Ubuntu – Creating Host Interface Networking for VirtualBox

Now VirtualBox 2.1 is out host interface networking is a simple affair, however you can still set it up manually by following this howto if you wish

I have had a big struggle get host interface networking going on my main PC (Edgy), on a command line server (both wired) and for my laptop at work and home (wireless). Following the VirtualBox Help file example meant a borked Nautilus and other networking things dying, plus I had no two way connectivity and a lost connection for my host machine.

Success has required two different approaches which I will detail below. The first was found on another blog, the second worked up from an article by Jack Knight in Linux Format Magazine , No. 98. Jack was also kind enough to help me get it working, as LXF didn’t print it quite right!

Wired Host Interface Networking with six tap interfaces for all those VMs 🙂

You can do everything you need to do by simply editing your /etc/networking interfaces file, or by replacing it with this one and edit in place: interfaces-taps-and-bridge.txt


install uml-utilities and bridge-utils

sudo apt-get install bridge-utils uml-utilities

edit /etc/network/if-pre-up.d/uml-utilities

sudo nano /etc/network/if-pre-up/uml-utilities

to change:

chown root:uml-net /dev/net/tun


chown root:vboxusers /dev/net/tun

change the vm settings from NAT to Host Interface and enter
a tap interface from tap0, tap1, or tap2 up to tap5

eth0 is your primary interface – change as necessary
with static ip – change as necessary
the bridge will have a static IP
you will have all tap interfaces using a static IP

for dhcp bridge replace bridge entries with

auto br0
iface br0 inet dhcp
bridge_ports eth0 tap0 tap1 tap2 tap3 tap4 tap5
bridge_maxwait 0

for dhcp bridge change the line
in tap entries to
uml_proxy_arp bimma.mynetwork.loc


stop networking before changes

sudo /etc/init.d/networking stop

Open /etc/network/interfaces

sudo nano /etc/network/interfaces

Add all the following after your auto lo entry in interfaces

#virtual network interfaces
auto tap0
iface tap0 inet manual
tunctl_user bimma
uml_proxy_ether eth0

auto tap1
iface tap1 inet manual
tunctl_user bimma
uml_proxy_ether eth0

auto tap2
iface tap2 inet manual
tunctl_user bimma
uml_proxy_ether eth0

auto tap3
iface tap3 inet manual
tunctl_user bimma
uml_proxy_ether eth0

auto tap4
iface tap4 inet manual
tunctl_user bimma
uml_proxy_ether eth0

auto tap5
iface tap5 inet manual
tunctl_user bimma
uml_proxy_ether eth0

Enter the following to set your bridge interface, with a static IP. The gateway is your router or ISP’s gateway

#network bridge interface
auto br0
iface br0 inet static
bridge_ports eth0 tap0 tap1 tap2 tap3 tap4 tap5
bridge_maxwait 0

Change the eth0 entry to manual. This will move the bridge interface to your actual IP, and your eth0 will run through the bridge, so you need to accept that eth0 stops having a direct IP

# The primary network interface
auto eth0
iface eth0 inet manual

restart networking after changes

sudo /etc/init.d/networking start or restart


Works as above for Ubuntu Hardy Heron. If using Xubuntu, you will need to stop Network Manager from autostarting to get things going, or that was the case for me!

General Update

On my system, I had to write a script actioned by /etc/network/rc.local to copy this new interfaces file, restart networking and then copy back a bland static IP type interfaces file for the next restart.

Connecting VMs when on a Wireless NIC with encryption using Masquerading

You can probably, with a bit of fiddling, get this working on the same machine as above, with fixed interfaces, but I don’t recommend it. This setup is meant when standard host interface netwroking won’t work becuase you are using a wireless nic, as VirtualBox have not yet implemented full support for wireless nics.

You need to create a little script to do this work for you, which simply creates a tap interface (only one this time, but you can have more). or download this version, and edit accordingly: tapctrl.txt


install the following:

sudo apt-get install parprouted uml-utilities

change permissions for /dev/net/tun

sudo chgrp vboxusers /dev/net/tun


Create a new file called tapctrl in nano/gedit as follows:

# Name: tapctrl
# Usage: tapctrl start|stop
# Provides: tap for virtualbox over external network including wireless
# Set up variables here:
DESC=”Virtualbox IP tap”
TUNDEVICE=tap1 # Arbitrary, but must match device used in virtualbox network device setting
LANDEVICE=eth0 # Adjust to match your network device – may be eth0, eth1 ath0, wlan1 etc.
IPADDR= # arbitrary, but make sure you pick something from an unused subnet
USER=bimma #your user name on the machine you are running

case “$1” in start|restart|force-reload)
echo -n “Starting $DESC: ”
tunctl -t $TUNDEVICE -u $USER
ip link set $TUNDEVICE up
ip addr add $IPADDR dev $TUNDEVICE
iptables -t nat -P POSTROUTING ACCEPT # allow other if’s to work
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/conf/$TUNDEVICE/proxy_arp
echo -n “Stopping $DESC: ”
iptables –table nat -F

killall parprouted
ip link set $TUNDEVICE down ;;
echo “Usage: $N start|stop” >&2
exit 1
exit 0

Ensure the script can be executed

chmod a+x tapctrl

Now change the interface settings to host interface in you VM, and add the name of the tap interface you have created, in this case tap1. To run the script simply (assuming in your home directory):

sudo ~/tapctrl start

To stop:

sudo ~/tapctrl stop

Once in your VM you need to give it a static IP in the range indicated in the script, the separate sub-net to your main lan, like

You should have internet access and be able to see other computers on your network, but you won’t have an IP, because you are masquerading under your real nic.

6 thoughts on “Ubuntu – Creating Host Interface Networking for VirtualBox

  1. I want to have many tap interfaces, each one with a diferent ip and mac, and be able to use each of them to access other computers on my network. Do you know if this is possible? How?

  2. Hi Will

    Not quite sure how what you want to do will help? Why do you need to access other computers in this way? Are they virtual PCs or real ones? If real ones then why simply network using Linux (NFS/Samba/SSH) or MS tools? If virtual ones (on the same PC) then this is what this howto is all about. If you create all the virtual tap interfaces you can open many virtual machines, as long as you assign a different tap interface to each one.

  3. Hi Will

    Thanks a lot for this great howto, I did manage to have dhcp with my VirtualBox, and it works now without a problem.
    It helped me so much, thanks again.

    Cheers from France,


Leave a Reply to Slavko Cancel reply

Your email address will not be published. Required fields are marked *