Ubuntu – Virtualbox: How to access web server on guest OS from the host OS


After a lot of RTFM'ing and reading forums, I am still having problems and need some advice.
I use Virtualbox on Ubuntu and installed a Centos server as a guest. My problem is that I cannot access the web server on the guest OS from the host OS.

Here are the details:
Host OS is Ubuntu 12.04 LTS (kernel 3.2.0-24-generic) 64bit.

I use Virtualbox 4.1.12.

I get my IP address from my wireless router:

eth0      Link encap:Ethernet  HWaddr 18:03:73:42:3d:ac  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:47 Base address:0xe000 

lo        Link encap:Local Loopback  
          inet addr:  Mask:
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:3784 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3784 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:378673 (378.6 KB)  TX bytes:378673 (378.6 KB)

wlan0     Link encap:Ethernet  HWaddr 64:27:37:69:c5:d2  
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::6627:37ff:fe69:c5d2/64 Scope:Link
          RX packets:124013 errors:0 dropped:0 overruns:0 frame:0
          TX packets:82469 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:164307087 (164.3 MB)  TX bytes:9744555 (9.7 MB)

So, I installed CentOS as a guest OS and I want to access its http server.
In the Network Settings in Virtualbox I have this:
Attached to Bridged Adapter

Name: wlan0

I allow Promiscuous mode for the VMs.

And 'Cable Connected' ticked.

On the CentOS machine, the eth0 interface picked up IP address with mask. Everything looks OK so far, the two systems can ping each other.
I started the web server and it is listening on port 80 – checked with netstat. (However haven't change the default configuration file of the webserver.)

When I wanna connect to the web server on the CentOS machine, I cannot. 'Unable to connect' Firefox says, Chrome is also unhappy: Chrome could not connect to (I am not using any proxy here.)

I tried to telnet to port 80 on the guest system – no joy:

:~$ telnet 80
telnet: Unable to connect to remote host: No route to host

Not sure if it's important, but the route table on the guest OS is here:

[root@centos ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface     *        U     0      0        0 eth0
link-local      *          U     1002   0        0 eth0
default         UG    0      0        0 eth0

(It's funny, just figured it out that I can ssh from Ubuntu to CentOS.)

I tried different settings in Virtualbox, but the above is the closest to what people suggest on different forums. Tried NAT with port forwarding, Host-only adapter but I failed to fix it.

Can someone shed some lights for me, please?

Best Answer

The solution was to open the port on the firewall of the guest OS, as described here: http://wiki.centos.org/HowTos/Network/IPTables

The Network settings in Virtualbox was OK - Bridged Network is the correct setting.