Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm setting up a VirtualBox with CentOS so I can test out all my code, etc. on a Linux box instead of the Windows I use for development.

I just got the SSH working (I SSH to localhost:2222 and it port forwards it to the virtualbox port 22).

It's using NAT because for some reason it refuses to start with a bridged adapter.

I'm trying to do the same thing with Apache, to get a web server up and running.

I've portforwarded port 8888 on localhost to port 80 in my CentOS Virtualbox, but I can't seem to access anything with localhost:8888 in my browser?

Apache is also definitely running:

ps -e | grep httpd
2108  ?      00:00:00 httpd
2110  ?      00:00:00 httpd
2111  ?      00:00:00 httpd
2112  ?      00:00:00 httpd
2113  ?      00:00:00 httpd
2114  ?      00:00:00 httpd
2115  ?      00:00:00 httpd
2116  ?      00:00:00 httpd
2117  ?      00:00:00 httpd

Iptables:

# Generated by iptables-save v1.4.7 on Fri Jan 27 18:26:36 2012
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [32:2278]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
-I INPUT -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
-I OUTPUT -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
-I INPUT -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT
-I OUTPUT -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT
COMMIT
# Completed on Fri Jan 27 18:26:36 2012

I've also stopped iptables, so that's not interfering. I tried to telnet into port 80 from my CentOS Virtualmachine to see if it'd work, and Neither 127.0.0.1 or [vm ip] works for telneting to port 80. It gets to connecting to [ip] and then says connection closed by foreign host. For the listen lines in my httpd.conf, it says listen 0.0.0.0:80

Output of netstat -tlnp | grep http

netstat -tlnp | grep http
tcp        0      0 0.0.0.0:80                       0.0.0.0:*                        LISTEN      2032/httpd
tcp        0      0 :::443                      :::*                        LISTEN      2032/httpd

When I nmap localhost, I get

[root@CentOS conf]# nmap localhost

Starting Nmap 5.21 ( http://nmap.org ) at 2012-01-28 00:58 WST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.0000090s latency).
Hostname localhost resolves to 3 IPs. Only scanned 127.0.0.1
Not shown: 993 closed ports
PORT    STATE SERVICE
22/tcp  open  ssh
23/tcp  open  telnet
25/tcp  open  smtp
80/tcp  open  http
111/tcp open  rpcbind
443/tcp open  https
631/tcp open  ipp

share|improve this question
    
Are you absolutely sure that 15.0.2.15 is the correct IP? That list of ports is extremely different. –  Shane Madden Jan 28 '12 at 8:23
    
Looks like you are binding to ipv6 only and not ipv4 - you may need to explicitly specify the use of ipv4 with Listen 0.0.0.0:80 (Apache docs). (Also check that localhost maps to 127.0.0.1 and not just to ::1 in /etc/hosts - but that is unlikely). –  cyberx86 Jan 28 '12 at 9:28
    
@ShaneMadden definitely sure it's the right IP –  user1045696 Jan 28 '12 at 9:56
    
Hosts: 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 10.0.2.15 localhost –  user1045696 Jan 28 '12 at 9:59
    
@ShaneMadden So I somehow fixed the IP issue, nmaping the IP address is now the same as nmaping localhost. However, it's still not working. I also can't ssh into the IP address directly (10.0.2.15:22) so I assume it's the same issue that's messing things up –  user1045696 Jan 28 '12 at 10:04

3 Answers 3

You have copy pasted the iptables rules? If yes then there is an error in it:

 _I OUTPUT -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT

the underscore insted of hyphen.

share|improve this answer
    
Should have said, I've fixed that, editing the post now :) –  user1045696 Jan 28 '12 at 10:35

First you have to make sure that apache is listening on the ethernet interface (the one from the VM) or on all addresses. For this run:

sudo netstat -tlnp|grep http

If it is not listening to external interface (as opposed to loopback one), then you have to change the Listen directive in apache configuration and restart apache (not reload).

share|improve this answer
    
I've edited the OP with the output, I'm not entirely sure what it means? –  user1045696 Jan 28 '12 at 4:52

In virtualbox, try changing the network settings to Bridge Adapter instead of NAT and select the appropriate interface you want to use (wired or wireless). Fire up CentOS and then re-check your ethernet address (run ifconfig).

From there check if you can now access apache using the new ethernet address.

With regard to ssh on centos, you have to make sure to edit sshd_config and uncomment the following:

Port 22
PermitRootLogin No

Also create another user aside from root and then add that user in sshd_config:

AllowUsers username
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.