Adding virtual bridges

Tue, 09/04/2012 - 16:58 -- jamie

If you have ever used a switch (or a hub) you are familiar with the idea of "bridging" - a process that allows you to connect multiple computers (or more specifically network interfaces) to each other. All data that comes from one interface is shared with the other interfaces.

The same principle applies to virtual bridges, except all the network interfaces are on one computer.

For example, if you are running many virtual servers on one computer, each virtual server will have it's own virtual network interface. If you would like all the virtual servers to be networked together (as if they were different computers attached to the same switch) you will need to create a virtual bridge.

Here's one way to create a network bridge. You will need to install some bridging utilities:

apt-get install openvswitch-brcompat

Begin by adding the following stanza to /etc/network/interfaces:

auto virbr0
iface virbr0 inet static
        pre-up brctl addbr virbr0
        post-down brctl delbr virbr

This stanza creates a network interface called virbr0, designed to come up automatically, with an IP address and a netmask. Most importantly, when the network interface is activated and de-activated, the brctl command is issued to add this device to a virtual bridge (with the same name).

Now, you can manually activate this bridge by typing:

ifup virbr0

You can test that it is working by typing:

brctl show

If you want to add a new network interface (e.g. called tap1) to your bridge, you'll need to create the interface using these instructions, then type:

brctl addif virbr0 tap1

You can remove the device with:

brctl delif virbr0 tap1