How to configure a Linux bridge interface

In computer networking, a bridge is a network device that interconnects more than one LAN segment at Layer-2. Bridges can filter traffic between different segments, thereby reducing the amount of traffic on LAN, even with many LAN segments. This bridge functionality is built into the Linux kernel, so one can set up a software bridge interconnecting multiple network interfaces.

In this post, I will describe how to configure a Linux bridge interface.

A Linux bridge can be created with a user-space command-line tool called brctl which allows you to create, remove and administer Linux Ethernet bridges.

To use brctl command, you need to install the following package.

On Ubuntu or Debian:

$ sudo apt-get install bridge-utils

On CentOS, RHEL and Fedora:

$ sudo yum install bridge-utils

Create a Linux Bridge from the Command Line

To create a bridge named br0:

$ sudo brctl addbr br0

To remove a bridge named br0:

$ sudo brctl delbr br0

To add interfaces eth0 and eth1 to a bridge br0:

$ sudo brctl addif br0 eth0
$ sudo brctl addif br0 eth1

To remove an interface eth0 to a bridge br0:

$ sudo brctl delif br0 eth0

It is worthwhile to note that a Linux bridge created by brctl is NOT persistent, meaning that any bridge created by brctl will automatically be destroyed upon boot. If you would like to have a permanent bridge configuration, you need to use a separate configuration file in /etc.

Create a Linux Bridge Permanently

In the rest of the tutorial, I will describe how to create a permanent Linux bridge interface from the command line using /etc configuration. If you want to use the GUI-based Network Manager to configure a Linux bridge, refer to this tutorial instead.

As an example, I will create a Linux bridge called br0 and add eth0 and eth1 interfaces to the bridge.

Configure a permanent bridge interface on Ubuntu or Debian

You need to edit /etc/network/interfaces as follows.

If the bridge br0 is to be assigned an IP address by DHCP:

auto eth0
iface eth0 inet manual

auto eth1
iface eth1 inet manual

auto br0
iface br0 inet dhcp
    bridge_ports      eth0 eth1

If the bridge br0 is to be assigned a static IP address:

auto eth0
iface eth0 inet manual

auto eth1
iface eth1 inet manual

auto br0
iface br0 inet static
    bridge_ports      eth0 eth1
    address <static_IP_address>
    netmask <netmask>
    gateway <gateway>

If you want to set up a transparent bridge between eth0 and eth1, you don't need to assign any IP address to the bridge. In that case, the following will do.

auto eth0
iface eth0 inet manual

auto eth1
iface eth1 inet manual

auto br0
iface br0 inet manual
    bridge_ports      eth0 eth1

Configure a permanent bridge interface on CentOS, RHEL or Fedora

You need to update existing eth0/eth1 configuration in /etc/sysconfig/network-scripts/ifcfg-eth[0-1], and add bridge configuration in /etc/sysconfig/network-scripts/ifcfg-br0.

$ sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
BRIDGE=br0
$ sudo vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
TYPE=Ethernet
BRIDGE=br0

If the bridge br0 is to be assigned an IP address by DHCP:

$ sudo vi /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
ONBOOT=yes
DELAY=0
BOOTPROTO=dhcp
ONBOOT=yes

If the bridge br0 is to be assigned a static IP address:

$ sudo vi /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
BOOTPROTO=static
IPADDR=<static_IP_address>
NETMASK=<netmask>
GATEWAY=<gateway>
ONBOOT=yes

To set up a transparent bridge between two interfaces:

$ sudo vi /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
BOOTPROTO=none
ONBOOT=yes
Download this article as ad-free PDF (made possible by your kind donation): 
Download PDF

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.


Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of Xmodulo.com. He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

2 thoughts on “How to configure a Linux bridge interface

  1. Great job putting together a concise and informative article. I followed it to setup a bridge on a Linux Mint laptop between eth0 and a plugin USB ethernet device (eth1). It worked perfectly the first time.

  2. Hi Dan,

    I am setting up Xen on Ubuntu. I have setup a static Linux bridge on Xen/Dom0 and now need to create a DomU and have that VM's independent ethernet i/f be able to reach the network via Dom0's bridge. how do I do that configuration? Your example (and others I've found) all talk about adding another interface belonging to the bridge owner, and the blogs I've seen discussing this network bridging all assume dhcp. Unfortunately I have a pool of static addresses I must work with, and I haven't found examples of how to statically connect to a bridge from another machine sharing the same lan.

    Thanks!
    Wayne

Leave a comment

Your email address will not be published. Required fields are marked *