Howto make a virtual bridged network

2246

Why? Well, I happen to use a lot of virtualization tools at work. In fact, I use Sun VirtualBox to run Solaris and Windows VMs for testing things, and I also make a lot of use of dynamips, a MIPS architecture hardware emulator made to emulate Cisco routers (I also occasionally make use of QEMU and derivitaives of it to emulate some odd ball hardware). Sometimes, it’s not enough to have these virtualized machines interact with the physical network through my host OS’s network stack. Sometimes, I want the disperate virtual devices to interact with one another, and with the physical network as individual machines. to do this, I need to create a virtual ethernet bridge and then create tap interfaces for the virtual devices. 

Firs you need the bridge utils package installed. This provide the binary /usr/sbin/brctl. In Ubuntu this package is just called bridge-utils.

Everything else you need should already be installed with most Linux distros. 

 

First, create a bridge interface:

brctl addbr br0

Second, remove the IP address from your usual Ethernet interface:

 ifconfig eth0 0.0.0.0

Third, add the ethernet interface to the bridge:

brctl addif br0 eth0

Next, let’s get back on the physical network (assuming you use DHCP):

dhclient br0

Then, create a tap / tunnel interface:
If you use VirtualBox:
VBoxTunctl -b -u $(whoami)
If not, use:
tunctl -u $(whoami)
Finally, bring up the interface and add it to the bridge:
ifconfig tap0 up
brctl addif br0 tap0
Then the last 2 steps can be repeated for as many tap interfaces as you will need. 
At this point, you can either start issuing the dhclient command to start giving those tap interfaces IP addresses from DHCP on the physical network, or you can start binding the tap interfaces in you various VMs and emulators for use with one another. 
Hope someone else finds this helpfull!