Configuring VirtualBox Host Interfaces

Among all the advice on how to configure host interfaces on Ubuntu Linux, the most useful information is missing – how to make the configuration persistent across reboots, and how to make only the required changes to make it work. It turns out that the proper configuration is trivial – all you need to do is to make some changes to /etc/network/interfaces file. Unfortunately, this method is not compatible with Network Manager – I will leave this research for another day.

My setup is simple: I want to keep the default network configuration on my Ubuntu host and simply add a packet interface for the guest system, which the guest system can configure itself. Here are the steps:

Launch Terminal and run

sudo gedit /etc/network/interfaces

Change configuration for eth0 from dhcp to manual:

iface eth0 inet manual

For each tapX interface, add the following three lines (replace tap0 with tap1, tap2 etc. as necessary, and replace denis with the user name you run virtualbox as):

auto tap0
iface tap0 inet manual
pre-up tunctl -t tap0 -u denis

List all tapX interfaces along with eth0 in the configuration for the bridge interface:

auto br0
iface br0 inet dhcp
bridge_ports eth0 tap0 tap1 tap2

Here’s what my /etc/network/interfaces file looks like – I have only one host interface configured:

# loopback interface
auto lo
iface lo inet loopback

# primary interface
auto eth0
iface eth0 inet manual

# host interface for virtualbox
auto tap0
iface tap0 inet manual
pre-up tunctl -t tap0 -u denis

# bridge that links all interfaces together
auto br0
iface br0 inet dhcp
bridge_ports eth0 tap0

Save the file and run

sudo /etc/init.d/networking restart

Finally, under Network page of the virtual machine configuration in VirtualBox, set Attached To to Host Interface and type tap0 (or tap1, tap2 etc.) into Interface Name:
VirtualBox Network Settings For Host Interface

Leave a Reply