ubuntu - Virtualbox: How to access web server on guest OS from the host OS?

25
2013-09
  • Petkaux

    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:127.0.0.1  Mask:255.0.0.0
              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:192.168.1.15  Bcast:192.168.1.255  Mask:255.255.255.0
              inet6 addr: fe80::6627:37ff:fe69:c5d2/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              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 192.168.1.20 IP address with 255.255.255.0 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 192.168.1.20. (I am not using any proxy here.)

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

    :~$ telnet 192.168.1.20 80
    Trying 192.168.1.20...
    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
    192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
    link-local      *               255.255.0.0     U     1002   0        0 eth0
    default         192.168.1.1     0.0.0.0         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? Cheers

  • Answers
  • Petkaux

    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.

  • Jakob Weisblat

    Disabling the guest OS internal firewall as below should allow you access. Type

    service iptables stop
    chkconfig iptables off
    

    at the command line when in the guest OS.


  • Related Question

    networking - Static IP on FEDORA12 from Virtualbox
  • Krazy_Kaos

    I'm trying to get my FEDORA12 to have an STATIC IP - inside VirtualBox - inside Ubuntu

    Let me rephrase that. I have an Ubuntu 9.04 system with VirtualBox and a FEDORA12 VM. I would like to use a static IP on the Fedora VM (amahi needs it), but I'm getting stuck... I'm using NAT (if that's any help)

    I tried a few tutorials, but no go.

    I'm kind of new to the *nix world but I'm old school on M$


    Screenshots:

    UBUNTU 9.04 (host that has the VM)

    alt text

    FEDORA

    alt text

    alt text


    INFO:

    GUEST WITH STATIC:

    IFCONFIG:

    eth0      Link encap:Ethernet  HWaddr 08:00:27:35:CC:DE  
              inet addr:192.168.1.55  Bcast:192.168.1.255  Mask:255.255.255.0
              inet6 addr: fe80::a00:27ff:fe35:ccde/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:7 errors:0 dropped:0 overruns:0 frame:0
              TX packets:2764 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:574 (574.0 b)  TX bytes:127121 (124.1 KiB)
              Interrupt:11 Base address:0xc020 
    
    lo        Link encap:Local Loopback  
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:16436  Metric:1
              RX packets:1856 errors:0 dropped:0 overruns:0 frame:0
              TX packets:1856 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:181587 (177.3 KiB)  TX bytes:181587 (177.3 KiB)
    

    NETSTAT -NR:

    Kernel IP routing table
    Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
    192.168.2.1     0.0.0.0         255.255.255.255 UH        0 0          0 eth0
    192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
    0.0.0.0         192.168.2.1     0.0.0.0         UG        0 0        
    

    GUEST WITH DHCP:

    IFCONFIG:

    eth0      Link encap:Ethernet  HWaddr 08:00:27:35:CC:DE  
              inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
              inet6 addr: fe80::a00:27ff:fe35:ccde/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:105 errors:0 dropped:0 overruns:0 frame:0
              TX packets:2966 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:49787 (48.6 KiB)  TX bytes:149969 (146.4 KiB)
              Interrupt:11 Base address:0xc020 
    
    lo        Link encap:Local Loopback  
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:16436  Metric:1
              RX packets:1903 errors:0 dropped:0 overruns:0 frame:0
              TX packets:1903 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:185931 (181.5 KiB)  TX bytes:185931 (181.5 KiB)
    

    NETSTAT -NR:

    Kernel IP routing table
    Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
    10.0.2.0        0.0.0.0         255.255.255.0   U         0 0          0 eth0
    0.0.0.0         10.0.2.2        0.0.0.0         UG        0 0          0
    

    PS.: I'm still trying to workout the sudoer file to be able to exec the iptables command


  • Related Answers
  • heavyd

    You need your IP address to be on the same subnet as the virtual NAT router. As you can see from when you use DHCP on the guest the subnet is 10.0.2.0/255.255.255.0, so, when you are setting a static IP address it needs to be in the 10.0.2.x range. Try setting it to something like 10.0.2.150. If possible, look in the VirtualBox settings to find the range of IPs the DHCP server will assign so you don't use one of those. Once your on the same subnet, it should work just fine. Just to summarize, here are your settings:

    IP: 10.0.2.150
    Netmask: 255.255.255.0
    Default Gateway: 10.0.2.2