The Way I See It

June 25, 2009

VirtualBox networking Vista host and Ubuntu guests

Filed under: Ubuntu, VirtualBox — Frank Henry @ 15:11

This post describes how to set up a VirtualBox environment consisting of a Windows Vista host and two guests running Ubuntu 9.04.

I wanted to set up a web development environment consisting of a Windows Vista host and two guests, one running Ubuntu Server and the other running Ubuntu Desktop. I wanted a typical web server environment (Apache, MySQL and PHP) on the Ubuntu server, and I would have Vista and Ubuntu Desktop clients for testing. I wanted a setup that would work on wired or wireless, on my home and office networks, and on the occasional hotel or public hotspot. Ideally, the host and guest machines should all be able to communicate with each other, and they should all be able to access the Internet.

With the help of Google and the VirtualBox manual I was able to get it up and running without too much difficulty. All the web articles I found were written before the most recent (version 2.2.x) releases of VirtualBox, in which there were significant changes, so I wanted to share my experience in the hope that it will help someone else.

It’s quite a simple solution. You basically set up your Ubuntu guest systems to have two network interfaces, one to communicate with the host and the other guest, and one to provide Internet access.

Communication between host and guests

Communication between host and guets, and between the two guests, is achieved with Host-only networking. Host-only networking is a new feature introduced in VirtualBox 2.2.0. It creates on the Vista PC a virtual network adapter, and Windows uses this adapter to communicate with the guests.

The virtual adapter shows up in your guest system as a regular network adapter. Likewise, in Vista it appears in your network settings like any other adapter. To enable communication between host and guests, you simply need to
configure the virtual adapter on the Vista host to communicate with the corresponding adapter in your Ubuntu guests. To enable your host and guests to access the internet, you set up a second adapter, this time using NAT.

Network settings

I used the following IP addresses:

  • Virtual adapter on Vista PC: 10.10.1.100
  • Virtual adapter (eth0) on Ubuntu Server: 10.10.1.101
  • Virtual adapater (eth0) on Ubuntu Desktop: 10.10.1.102

Creating the virtual adapter

On Vista…

  1. Select Preferences… from the File menu in VirtualBox. In the Settings dialog box, click the Network tab. Then click the “+” icon to add a new adapter.
    Add a Host-only adapterWhen the adapter is created, click the screwdriver icon to change the settings. This displays the Host-only Network Details dialog box.Network details for host-only adapter
  2. In the Adapter tab, enter the IPv4 address (10.10.1.100) and the network mask (255.255.255.0).
  3. In the DHCP Server tab, make sure the Enable Server checkbox is unticked.
  4. Click OK in the Host-only Network Details dialog box and again in the VirtualBox Settings dialog box.
  5. In the main VirtualBox window, select the Ubuntu Server instance and click the Settings icon.
  6. In the Settings dialog box, click the Network tab. You will see four tabs named Adapter 1 to Adapter 4. These correspond to devices eth0 to eth3 in your Ubuntu guest.
    VirtualBox settings for Ubuntu guestIn the tab for Adapter 1, tick the “Enable Network Adapter” box. Unless you have some reason to change the Adapter Type, leave it at at the default (PCnet-FAST III). From the Attached To: dropdown, select “Host-only Adapter” and from the Name drop-down, select the virtual adapter you created earlier.Click on OK. Repeat the process for the Ubuntu Desktop instance.On Vista, open the Network and Sharing Center from the control panel. In the list of network connections, you will see “VirtualBox Host-Only Network”.
    VirtualBox adapter appears in list of network connections

    Double-click this connection and configure it to have a static IP address of 10.10.1.100 and a subnet mask of 255.255.255.0.
    Vista IP settings for VirtualBox adapter

This completes the setup on Vista. Now for Ubuntu…

  1. Start your Ubuntu Server guest and log in.
  2. Configure the network interface. If you used Adapter 1 in the VirtualBox settings, the corresponding device on Ubuntu is eth0, eth1 corresponds to Adapter 2, and so on. This example assumes eth0.
  3. frank@ubuntu-server:> sudo nano etc/network/interfaces
    # The loopback network interface
    auto lo
    iface lo inet loopback
    
    # VirtualBox host-only adapter
    auto eth0
    iface eth0 inet static
    address 10.10.1.101
    netmask 255.255.255.0
    gateway 10.10.0.1
    broadcast 10.10.0.255

    Then, restart networking:

    sudo /etc/init.d/networking restart

    You should now be able to ping the Vista PC from Ubuntu Server:

    ping 10.10.1.100

    And from the Vista PC, you should now be able to ping Ubuntu Server:

    ping 10.10.1.101

    And of course, if Apache is installed, the home page of Ubuntu Server should be accessible on http://10.10.1.101.

    Setup for the Ubuntu desktop is the same. Use the address 10.10.1.102. When finished, you should be able to ping the Vista PC on 10.10.1.100 and ping the Ubuntu server on 10.10.1.101.

    Communication with the Internet

    To enable the Ubuntu guests to access the Internet, you need to configure a second network adapter. This second adapter uses Network Address Translation (NAT) to transparently route Internet traffic to and from the virtual machine.

    1. In the main VirtualBox window, select the Ubuntu Server instance and click the Settings icon.
    2. In the Settings dialog box, click the Network tab.VirtualBox settings for Ubuntu guestIn the tab for Adapter 2, tick the “Enable Network Adapter” box. Unless you have some reason to change the Adapter Type, leave it at at the default (PCnet-FAST III). From the Attached To: dropdown, select “NAT” and from the Name drop-down, select the virtual adapter you created earlier.

    Click on OK. Repeat the process for the Ubuntu Desktop instance.

    This completes the setup on Vista. Now for Ubuntu…

    1. Start your Ubuntu Server guest and log in.
    2. Configure the network interface. If you used Adapter 2 in the VirtualBox settings, the corresponding device on Ubuntu is eth1, and so on. This example assumes eth1.
    3. frank@ubuntu-server:> sudo nano etc/network/interfaces
      # The loopback network interface
      auto lo
      iface lo inet loopback
      
      # VirtualBox host-only adapter
      auto eth0
      iface eth0 inet static
      address 10.10.1.101
      netmask 255.255.255.0
      gateway 10.10.0.1
      broadcast 10.10.0.255
      
      # VirtualBox NAT adapter
      auto eth1
      iface eth1 inet dhcp

      Then, restart networking:

      sudo /etc/init.d/networking restart

You should now be able to access the Internet from Ubuntu Server:

ping www.google.com

And you should still be able to ping Ubuntu Server from the Vista PC and vice versa.

Now, repeat the process from Ubuntu Desktop, test your connections and you are done.

Other ways to skin the cat

There may be other ways to skin this cat, for example by using bridging and internal networking. It depends on your requirements. For me, this method works best because in addition to being the most “real” scenario it doesn’t need any reconfiguring for different Internet connections.

4 Comments »

  1. Wow!! Finally something that really works!!! Thanks a lot for this post!
    I was trying to make this work for days.

    Comment by Falcon — October 15, 2009 @ 06:40 | Reply

  2. quote ” On Vista…Select Preferences… from the File menu. In the Settings dialog box, click the Network tab. Then click the “+” icon to add a new adapter.”

    Where is this File menu? I just have Network and sharing centre, There are no menus!!

    Comment by emma — October 16, 2009 @ 09:37 | Reply

  3. Yes I can see why you might be confused :-) . I should have said “… from the File menu in Virtual Box.” (post now edited to clarify).

    Comment by Frank Henry — October 16, 2009 @ 10:39 | Reply

  4. Excellent post !

    The most comprehensive guide to such a setup I’ve read so far – and I researched like crazy !!! This should go into the virtualbox forums or wiki

    Observations:
    When I followed the steps, my internet connection broke. Had to restart my dial-up, no problems since then.

    Virtual box wouldn’t let me select/type a name into the dialog where one should select the ‘previously set up adapter’ – I just stayed grey + disabled why so ever.

    Worked anyway, I disabled the default host-only adapter before…

    Again: THANKS !

    Comment by papasosa — November 1, 2009 @ 22:05 | Reply


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.