How to configure a Linux bridge interface

In computer networking, a bridge is a network device that connects 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. Linux has software bridge functionality built into kernel.

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

Linux bridge setup can be done 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

The brctl command howto

To create a bridge:

$ sudo brctl addbr br0

To remove a bridge:

$ sudo brctl delbr br0

To add an interface to a bridge:

$ sudo brctl addif br0 eth0

To remove an interface to a bridge:

$ sudo brctl delif br0 eth0

It is worthwhile to note that Linux bridge setup 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.

In the following, I will describe how to create a permanent Linux bridge interface. As an example, I will create a Linux bridge called br100, and add eth0 interface to the bridge. Note that when you enslave a physical interface eth0 into a bridge interface br0, the bridge interface takes over the IP address of the enslaved interface eth0.

Configure a permanent bridge interface on Ubuntu or Debian

You need to edit /etc/network/interfaces. First, remove eth0 configuration from /etc/network/interface, and add the following.

If eth0 has an IP address assigned by DHCP:

auto br100

iface br100 inet dhcp
    bridge_ports      eth0
    bridge_stp        off
    bridge_maxwait    0
    bridge_fd         0

If eth0 has a static IP address:

iface br100 inet static
    bridge_ports      eth0
    bridge_stp        off
    bridge_maxwait    0
    bridge_fd         0
    address <static_IP_address_of_eth0>
    netmask <netmask>
    gateway <gateway>

Configure a permanent bridge interface on CentOS, RHEL or Fedora

You need to update existing eth0 configuration in /etc/sysconfig/network-scripts/ifcfg-eth0, and add bridge configuration in /etc/sysconfig/network-scripts/ifcfg-br100.

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

If eth0 has an IP address assigned by DHCP:

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

If eth0 has a static IP address:

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

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.

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.
Your name can also be listed here. Write for us as a freelancer.

One thought 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.

Leave a comment

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

Current ye@r *