HOWTO: Set up wireless networking between VirtualBox VMs on Ubuntu Hardy Heron

I’m working on a project at the moment that requires a whole bunch of Win XP VMs.  I’m using VirtualBox on my M1330 which out of the box is set up with NAT addressing.  This is fine for accessing the interweb but I need the VMs to talk to each other.  Not as straightforward as it seems but I managed to get it working as follows:

OK - in this example I have one Ubuntu Hardy Heron (HOST) hosting 2 VirtualBox Win XP VMs (GUESTS).

Open a terminal on the HOST computer.

1. Enable IP forwarding
sudo sysctl net.ipv4.ip_forward=1

2. Create tap0 and tap1 interfaces and bring them up (one for each GUEST)

sudo VBoxTunctl -b -u $USER
sudo VBoxTunctl -b -u $USER
sudo ip link set tap0 up
sudo ip link set tap1 up

NOTE: change $USER above to the username in the vboxusers group who will be running the VMs

3. Assign tap0 and tap1 IP addresses.
sudo ip addr add 192.168.0.100/24 dev tap0
sudo ip addr add 192.168.0.101/24 dev tap0

The IP addresses in the example should be changed to spare IP addresses on your network.

4. Install parprouted (if not already installed)
sudo apt-get install parprouted

5. Bind your wireless interface to tap0 and tap1
sudo parprouted wlan0 tap0
sudo parprouted wlan0 tap1

NOTE: Change wlan0 in the example as required to match your wireless interface.

6. Add routes for the tap0 and tap1 interfaces
sudo route add -net 192.168.0.0 netmask 255.255.255.0 tap0
sudo route add -net 192.168.0.0 netmask 255.255.255.0 tap1

NOTE: Change 192.168.0.0 to correspond to your network addressing scheme.

Ok - that finishes setting up the host. If you want to start the interfaces at boot then create a script called, say, vm_network in the folder /etc/network/if-up.d/ with the above commands.

#! /bin/sh
sysctl net.ipv4.ip_forward=1
VBoxTunctl -b -u $USER
VBoxTunctl -b -u $USER
ip link set tap0 up
ip link set tap1 up
ip addr add 192.168.0.100/24 dev tap0
ip addr add 192.168.0.100/24 dev tap1
parprouted wlan0 tap0
parprouted wlan0 tap1
route add -net 192.168.0.0 netmask 255.255.255.0 tap0
route add -net 192.168.0.0 netmask 255.255.255.0 tap1

Remember to change $USER and the ip address to match your environment! You can add additional tap interfaces (tap2, tap3 etc) for each additional VM on your network.

Now repeat the following steps on each VM you want to use.

NOTE: These steps are for VMs running Windoze XP. Should be even simpler on Linux guests!

1. In the VirtualBox control panel select the VM you want to work with and select settings (only available when VM is NOT running).

2. Select Network on the left and the Adapter 0 tab on the right.

3. If not already selected change the ‘Adapter Type’ to be PCnet-FAST III.

4. Change the ‘Attached to’ from NAT to Host Interface.

5. Click the ‘Generate’ button next to MAC address.

6. In the ‘Interface Name’ field enter tap0

7. Click OK and start the VM.

8. Open ‘Control Panel’ and then ‘Network Connections’

9. You should see a ‘Local Area Connection’ entry with limited or no connectivity. Right click it and select ‘Properties’

10. Open the ‘Internet Protocol (TCP/IP)’ dialog by double clicking.

11. Select ‘Use the following IP address’ and enter a free IP address on your network, the netmask 255.255.255.0, your gateway address and the address(es) of your DNS servers. Click ok.

12. Run the ‘Network Setup Wizard’ by clicking the link in the left hand pane. You can accept the defaults for everything unless you want to change the computer name, workgroup or share folders from it.

13. Restart the VM. That should be it! The VM should now act as a normal computer on your LAN.

2 Responses to “HOWTO: Set up wireless networking between VirtualBox VMs on Ubuntu Hardy Heron”


  1. 1 ivo Sep 4th, 2008 at 6:44 am

    Awesome! Tried a lot to get this working but never added the route, finally it works!
    Thanks!

  2. 2 dan Sep 8th, 2008 at 1:09 pm

    thanks for the write up, sorted!




Add to Technorati Favorites
Zen Handbook

Latest Posts

RSS