I set up VirtualBox to do virtualize some odds and ends testing I was doing (specifically, with the intent of freeing up a laptop to be reissued) and encountered the wonderful problem of trying to bridge the connections to the network at large. With VMWare Server, this is delightfully trivial. The bridged connections are already set up and all you have to do is pick it off the list when setting up the virtual adapter. VirtualBox works the same way, but you have to set up the adapters yourself. So, here are my notes on doing it.

At the system level, what you are doing is creating a bridge (which enslaves a hardware interface) and creating virtual adapters off of it. What you get is something like this:

On Debian (and, by extension, Ubuntu) you can create the devices by editing the /etc/network/interfaces file and adding the following sections:

auto br0
iface br0 inet dhcp
bridge_ports all tap0 tap1

auto tap0
iface tap0 inet manual
up ifconfig eth0 up
down ifconfig eth0 down

The first section creates the bridge and enslates eth0 to it. The second section creates a TAP interface that is assigned to that bridged device.

Alternatively, you can manually run commands like the following to accomplish this task. If you go this route, you will want to take your commands, put them in a shell script, and rerun them at boot time so that your interfaces are recreated after booting up. The utilities are brctl (for the bridge) and tunctl (for the TUN interface). Given the sections above, it is actually pretty easy to know what sequence of commands to run, so I'll leave that as an excercise for the reader (with the help of the man pages/help section).

There you have it. All you need to know to go crazy and create seven million bridged network devices. While my reason and example here is setting up VirtualBox, it is not the only use for it. Other uses include operating system virtualization, running multiple services on different IPs (i.e. bridging Apache to another address than the main system one), and other general tomfoolery.