VirtualBox Networking

Introduction

Note: How you choose to get VirtualBox on your Debian/Ubuntu machine is beyond the scope of this article. Also, take a look at the bottom of my example /etc/network/interfaces file... at one point, /dev/net/tun is set to world-readable, and world-writeable. I am not quite sure what the security implications of this are, but you may want to look further into the issue.

To give the virtual machine it's own address on the network, you must give it it's own TUN/TAP interface, which is (to my understanding) a network interface emulated in software. This network interface must then be bridged to your physical interface, so the VM can talk to other computers on the network.

I'm not sure if this is a common problem, but most of the instructions floating around the net didn't seem to fit the way I wanted to do things. The VirtualBox user manual itself had a Debian-specific way to perform the install, but failed to get it working with their instructions. And most of the scripts I saw lying around were meant to run in /etc/rc.local. I'd really rather put the relevant config into /etc/network/interfaces so that it goes up and down with the /etc/init.d/networking script.

Instructions

These steps were performed on Ubuntu Gutsy but should work on a Debian system as well. I actually did this a while ago, but I don't believe I am missing any steps. If I'm incorrect, feel free to let me know and I would be happy to work through it with you.

First, we need to make sure we have both the uml-utilities and bridge-utils packages installed. At the command line, type:

sudo apt-get install bridge-utils uml-utilities

For this example we will assume that you are using a static address on the home interface, at least until I can post a working DHCP configuration.

In the following /etc/network/interfaces, 10.0.0.1 is the gateway, and 10.0.0.2 is the IP address of the physical NIC on the host machine. The local username that VirtualBox will be running under is 'localhorse'. I have included tap0 and tap1. I sometimes want to run multiple VM's concurrently, in this way they can each have their own interface. So, open up your favorite text editor, and open /etc/network/interfaces. Your primary NIC is probably eth0, but adjust this example based on what you find in the interfaces file.

auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
        address 10.0.0.2
        netmask 255.255.255.0
        gateway 10.0.0.1
        broadcast 10.0.0.255

auto tap0
iface tap0 inet manual
        tunctl_user localhorse
        uml_proxy_arp 10.0.0.1
        uml_proxy_ether eth0

auto tap1
iface tap1 inet manual
        tunctl_user localhorse
        uml_proxy_arp 10.0.0.1
        uml_proxy_ether eth0

auto br0
iface br0 inet static
        address 10.0.0.2
        netmask 255.255.255.0
        gateway 10.0.0.1
        broadcast 10.0.0.255
        post-up chmod ugo+rw /dev/net/tun
        bridge_ports eth0 tap0
        bridge_ageing 7200
        bridge_fd 0
        bridge_maxwait 0

Notice that the bridge (br0) has the same IP address as the eth0 interface.

After that, issue this simple command:

sudo /etc/init.d/networking restart

You should now load VirtualBox. This tutorial assumes you have already set up a virtual machine. Simply select this VM, and click on the 'Network' heading in the 'Details' tab.

Make sure that 'Enable Network Adapter' is checked. The drop down box to the right of 'Attached to' should be set to 'Host Interface'. Make sure 'Cable Connected' has been checked.

Under 'Host Interface Settings', the interface name should be 'tap0', if you are intending to use the first of the two TUN/TAP interfaces we created.

Now you should be able to start the VM as if it were a physical computer attached to the network. This is similar to the (more automated) setup that the VMware install performs, but also more versatile, as it should work with QEMU and other emulators as well. I also personally find VirtualBox to have much better performance than VMware.



Last edited by localhorse on Feb. 12, 2011, 2:35 a.m. MST

 
The content on this site is copyright © 2005-2011 Danny Campbell. Thanks to the irssi team for the GPL-licensed CSS code. The Noware site is built with django-cms, running on the Django platform. Django is a Python web framework, which is being served using mod_wsgi on apache2. The database backend for Django is stored on a MySQL server. All of this is running on the wonderful GNU/Linux distribution, Debian.