Accessing your Virtualbox Guest from your Host OS


Nitin Venkatesh's Gravatar

Nitin Venkatesh
published Nov. 8, 2014, noon


We all use VirtualBox to setup our playgrounds and experiment(wreck) everything without ever having to bear the repercussions. Sometimes, we want to access this guest machine from our host, but we fail. For example, I have an Ubuntu guest (nitin-VirtualBox) running inside my Ubuntu host(trusty) and I want to access the Apache Web Server running on my guest.

Running an ifconfig on my Ubuntu guest, I find the IP and try to ping it from my host. But, nothing is returned.

screenshot-vbox-initial

nitin@trusty:~$ ping -c 5 10.0.2.15
PING 10.0.2.15 (10.0.2.15) 56(84) bytes of data.

--- 10.0.2.15 ping statistics ---
5 packets transmitted, 0 received, 100% packet loss, time 4024ms

What we need to do is setup a VirtualBox Host Only Network and get our guest connected to it.

  1. If your guest machine is running, shut it down first.
  2. Click on File->Preferences in the VirtualBox menu-bar.

    screenshot-vbox-menubar

  3. Select the Network option from the side menu and click on the Host-only networks tab.

    screenshot-vbox-host-only-network-add-new

  4. The default options for the newly-created Host-only network should be fine. If not, you can add the following data manually, by clicking on the Edit button in the DHCP Server tab.

    • Server Address: 192.168.56.100
    • Server Mask: 255.255.255.0
    • Lower Address Bound: 192.168.56.101
    • Upper Address Bound: 192.168.56.254

    Don't forget to check the Enable Server option.

    screenshot-vbox-host-only-network-edit

    screenshot-vbox-host-only-network-dhcp-settings

  5. Now save all the settings in Preferences.

  6. Now open up the settings of your Guest machine and navigate to the Network option from the side menu and click on the Adapter 2 tab.

    screenshot-vbox-guest-settings

    screenshot-vbox-guest-settings-network-

  7. In the Attached to section, click on the dropdown and choose Host-only Adapter and in the Name section nested in it, choose the newly-created Host-only network.

    Don't forget to check the Enable Network Adapter option.

    screenshot-vbox-guest-network-adapter

  8. Save these settings and boot into your Guest machine.

  9. After logging in, type ifconfig. Note the new IP, it should be under a new interface like eth0 or vboxnet0. Now you can use this IP to SSH, view the webpages on your machine's Apache Server, etc..

    screenshot-vbox-host-only-network-success

    nitin@trusty:~/Projects/nitstorm.github.io$ ping -c5 192.168.56.101
    PING 192.168.56.101 (192.168.56.101) 56(84) bytes of data.
    64 bytes from 192.168.56.101: icmp_seq=1 ttl=64 time=0.735 ms
    64 bytes from 192.168.56.101: icmp_seq=2 ttl=64 time=0.282 ms
    64 bytes from 192.168.56.101: icmp_seq=3 ttl=64 time=0.269 ms
    64 bytes from 192.168.56.101: icmp_seq=4 ttl=64 time=0.342 ms
    64 bytes from 192.168.56.101: icmp_seq=5 ttl=64 time=0.369 ms
    
    --- 192.168.56.101 ping statistics ---
    5 packets transmitted, 5 received, 0% packet loss, time 4000ms
    rtt min/avg/max/mdev = 0.269/0.399/0.735/0.172 ms