Kemp’s Blog

A technical blog about technical things

Linux Ethernet Bridging

Ethernet bridging allows automated routing between multiple interfaces on your computer. They don’t necessarily have to be of the same type, as long as they carry IP protocol traffic. For instance, two Bluetooth BNEP PAN connections and a normal 100BASE-T Ethernet interface can be bridged together. This allows a host on one of the PAN connections to communicate with a host somewhere on the Ethernet network without any extra effort from you, as long as they share a common subnet.

My own use of this type of bridging is entirely with BNEP PAN connections to allow Gumstix devices to talk to each other via the emulated Ethernet network without regard to which devices are master or slave or how the packets are being routed in the underlying PAN. In this scheme, I have one Gumstix device running Ethernet bridging as the master of the PAN, with a PC and several other Gumstix devices as slaves. It doesn’t matter that all traffic is routed via the network master as this is hidden several layers below my view.

To get started you first have to install the bridge-utils package on the device performing the bridging. This provides the brctl program.

On an Ubuntu PC:

sudo apt-get install bridge-utils

On a correctly configured OE Gumstix device:

ipkg install bridge-utils

(From here I will only give the commands for the PC case, the Gumstix device will be identical except that you don’t need to use sudo.) Next you create a bridge, which in turn creates a virtual interface.

sudo brctl addbr bridge0

In this case, the bridge is called (unimaginatively) bridge0. Note that if you followed my previous instructions for setting up BNEP PAN networks under BlueZ 4.x, Blueman actually forms a bridge behind the scenes called pan0. Next you configure the bridge. Remember that all bridged connections should be on the same subnet. The interfaces for each connection are not given IP addresses. Instead the bridge is given an address.

sudo ifconfig bridge0

Replace with the appropriate network address, for instance Next, select an interface to add to the bridge, make sure it is not configured with its own IP address, and add it to the bridge.

sudo ifconfig xxx
sudo brctl addif bridge0 xxx

Replace xxx with the name of the interface (eth0, eth1, bnep0, etc). That’s it, once you’ve added the interfaces you need the bridge will take care of the rest.

As an idea of how I achieve bridging over a PAN on a Gumstix device, I generally place a boot script on the device with the following:

brctl addbr pan0
ifconfig pan0 192.168.2.`cat /etc/id`
brctl stp pan0 off
brctl setfd pan0 0

Those final two lines turn off STP and set the forwarding delay to 0 in order to prevent additional delay in setting up the network when interfaces are added/removed from the bridge. This should only be done if there is no chance of routing loops in the network (which should be true if the only participants in the bridged network are members of the PAN, though be careful if using a Scatternet).

Next, I place the following script in /etc/bluetooth/pan/dev-up to be called whenever a new incoming Bluetooth connection is created:

ifconfig $1
brctl addif pan0 $1

That’s the lot. Hope this helps.