Bridging Ethernet Connections (as of Ubuntu 16.04)

These instructions work for current Ubuntu versions as of this writing.

NOTE: Bridging is popular, and so it has reference material in several places that may not all be updated at once. These are the links I know of;

This covers how to bridge connections using the package bridge-utils. It is assumed that the bridging computer is not directly connected to the Internet. This article contains information from several sources, including;

Please visit these sites if you need a more in-depth discussion of network bridges and the commands used here.

Why bridge?

It is possible to "bridge" two Ethernet adapters together (for example, eth0 and eth1). When you bridge two Ethernet networks, the two networks become one single (larger) Ethernet network.

One reason you would bridge Ethernet connections is to monitor traffic flowing across an Ethernet cable. For example, an inline sniffer to monitor the traffic flowing between these two devices, such as a router and the switch. (Using tools like ntop, Wireshark, and tcpdump.)

How to bridge? (short version)

The Debian wiki provides a good overview of how to use brctl and the /etc/network/interfaces file to create and set up bridges. Typing man bridge-utils-interfaces at a command prompt provides additional detail.

You can set up a simple Ethernet bridge by installing bridge-utils placing this text into /etc/network/interfaces file:

auto lo
iface lo inet loopback

auto br0
iface br0 inet dhcp
  bridge_ports eth0 eth1

Using auto br0 ensures that the bridge starts when the computer reboots, and using iface br0 inet dhcp provides the computer with its own IP address on the single (larger) Ethernet network.

You will note that auto eth0 and iface eth0 inet manual are not in the file. This is because br0 will bring up the components assigned to it.

Once you have edited the /etc/network/interfaces file, it may be easiest to reboot your computer to turn on the bridging. (It is possible to start the bridge without rebooting or logging out, but you may have some problems with the Network Connection Manager interfering with your settings.)

Bridging Ethernet Connections from the GUI

As of Ubuntu 15.04 you can bridge from the desktop using network manager. This is covered in a website at ask.xmodulo.com/configure-linux-bridge-network-manager-ubuntu.html.

Bridging Ethernet Connections (Step by step)

You will need to know the following information;

  • Your interface name. This used to be eth0 or eth1, but now we have Predictable Network Interface Names which means they could be eth0, p3p1, p2p1, enp9s0, wlp9s0, or eno16777728. (Yes, those are all real examples. Do an ifconfig from the cli to find out what Ubuntu is actually calling your nics.

  • Your IP address, subnet mask, gateway and DNS. (If not using dhcp)
  • Information about your network. (Specifically if a loop could ever be formed.)

Installing bridge-utils

sudo apt-get update
sudo apt-get install bridge-utils

If you use sudo -i and enter your password, then you will not have to use sudo before each command. It may also save you some typing in the future.

Automatically Create the Bridge at Start-up

The above setup demonstrated how to create a bridge using the command line, however when you restart your computer you will lose it. To prevent this from happening, we need to edit the /etc/network/interfaces file. This file shows an example of a bridge configure via dhcp.

Sample /etc/network/interfaces file

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# Bridge between eth0 and eth1
auto br0
iface br0 inet dhcp
# For static configuration delete or comment out the above line and uncomment the following:
# iface br0 inet static
#  address 192.168.1.10
#  netmask 255.255.255.0
#  gateway 192.168.1.1
#  dns-nameservers 192.168.1.5
#  dns-search example.com
   bridge_ports eth0 eth1
   bridge_stp off
   bridge_fd 0
   bridge_maxwait 0

Restart networking

sudo /etc/init.d/networking restart 
  • bridge_stp off is a setting for spanning tree. If you have a possibility for network looks, you may want to turn this on.

  • bridge_fd 0 turns off all forwarding delay. If you do not know what this is, you probably do not need it.

  • bridge_maxwait 0 is how long the system will wait for the Ethernet ports to come up. Zero is no wait.

Manually Setting up the Bridge

If you do not want to use your bridge all the time (or if you do not want to break Network Manager for the times when you are not bridging) you can build a bridge by hand. Or you can script it to bring up your bridge on demand.

Ensure that both (or all) of your interfaces are installed and enabled. If they are then you may proceed at this point. For a few moments, if your computer is connected to the Internet then it will be disconnected temporarily.

Open a terminal and use the following commands. Note that when interfaces are referenced, they refer to device names assigned by Linux such as "eth0" and "eth1". A bridge can be anything, but a simple name like bridge0 or br0 is suggested.

ip addr flush dev <interface 1>
ip addr flush dev <interface 2>
brctl addbr <bridge name>
brctl addif <bridge name> <interface 1> <interface 2>
ip link set dev <bridge name> up

In lines 1-2 we simply prepared the devices to be bridged. In line 3, we added a new bridge named myBridge (whatever you named your bridge). In lines 4-5, we added interface1 and interface2 to myBridge. In line 6, we made the bridge operational. For more information on commands: use the Konsole command brctl

Manually creating the routing

If you manually created the bridge above, you will also need to manually give it IP address information. If you are using DHCP, running sudo dhclient br0 will get your interface up and running. If not, it is all manual.

At this point you may also want to see http://linux-net.osdl.org/index.php/Bridge at this point for a more in depth explanation of bridges and other commands within brctl.

Contributors

Websites

Editors can add any website they find that are related to this article or that they used to add to this article.

http://linux-net.osdl.org/index.php/Bridge http://wiki.debian.org/BridgeNetworkConnections

Users

Editors post their name/username and some form of contact.

Jonte Craighead, JonTec on #(K)ubuntu IRC Channel

[JonTec's reference]: sethk on #ubuntu IRC Channel

John Griffin

Additions

13.Aug.06: JonTec: There was an error inside my bridge setup commands that would prevent you from adding interfaces to the bridge. I have fixed this error.

2.Nov.06 JackWasey: Is this possible between ethernet and Firewire connections? If not, what is the appropriate method?

4.Sep.12 griffin2: Added section on Ubuntu 12.04.

14.Apr.16 Lee Sharp: A lot of cleanup and realignment with other pages.


NetworkConnectionBridge (last edited 2016-04-15 03:40:47 by c-73-136-18-217)