A bridge in computer networking plays a vital role in connecting multiple network segments. The bridge forwards traffic between different LANs (Local Area Networks), allowing devices on separate LANs to communicate.

On Ubuntu and other Linux distributions, the bridge utils package provides essential tools for configuring Ethernet bridges. This comprehensive guide will explain what bridge utils are, why bridges are useful, and provide step-by-step instructions on installing, setting up, and managing bridges using bridge utils on Ubuntu.

What are Bridge Utils?

Bridge utils is a package that contains command line utilities for configuring Ethernet bridge interfaces on Linux. Some key components of bridge utils include:

  • brctl: Used to set up, maintain, and inspect Ethernet bridges. Allows you to create a bridge, add/remove interfaces to it, show bridges and bridge interfaces, and delete bridges.

  • bridget: Prints bridge information. Shows bridge interfaces, IP/MAC addresses of interfaces, and more.

  • bridge: Configures bridge parameters at boot time by reading info from /etc/networks/interfaces.

In essence, bridge utils provides a suite of tools that admins can use to connect multiple local networks through bridges. This allows traffic to be forwarded as needed while keeping the network segments logically separated.

Why Use Bridges on Ubuntu?

There are several reasons why you may want to configure bridge interfaces on an Ubuntu system:

Connect multiple subnets – Bridges allow different subnets and network segments to interconnect as if they were on the same LAN. This lets you expand your network easily.

Network virtualization – Virtual machines can connect to bridges as if they were physical interfaces, enabling VM traffic to integrate with the local network.

Network experiments – Bridges are useful for testing networking configurations and prototyping new architectures. You can divide networks into logical sections for experiments.

Forward selective traffic – By bridging only certain interfaces, you can choose which traffic gets forwarded between network segments.

Improve security – Bridging can help divide secure internal networks from DMZs and subnets with Internet-facing servers. This improves security.

For most applications, administrators need an easy way to configure bridging. Bridge utils provides simple command line utilities to do this on Ubuntu and Debian-based Linux OSes.

Installing Bridge Utils on Ubuntu

Installing bridge utils only takes a single apt package manager command:

sudo apt install bridge-utils

This installs brctl and the other bridge config tools system-wide.

Note that you‘ll generally want to install bridge utils even if you use a network manager like Netplan or NetworkManager to configure bridges. The bridge utils commands act as low-level tools for inspecting and manipulating Ethernet bridges.

Creating a Bridge with brctl

The brctl utility is used to set up and manage Ethernet bridge devices. To create a Linux software bridge and add interfaces to it, you can use brctl directly.

First, install bridge utils if you haven‘t already:

sudo apt install bridge-utils

Next, use brctl to create a new bridge. Let‘s make one called br0:

sudo brctl addbr br0

You can verify the new bridge exists using brctl show:

sudo brctl show

This will list all configured bridges on the system.

With the bridge created, you can now add real Ethernet interfaces to it. For example, to add the interface enp3s0 to br0:

sudo brctl addif br0 enp3s0

Repeat this for any other interfaces you want to bridge together. You can use brctl show at any time to examine the bridge setup.

Finally, give the bridge an IP address if you want it to forward traffic between the bridged interfaces:

sudo ip addr add 192.168.1.10/24 dev br0

The bridge itself now functions as a switch to forward traffic between the bridged NICs.

Persisting Bridge Configurations

By itself, brctl and bridge utils only modify the live system. Bridges will not persist reboots.

To make your bridge setup permanent, you need to configure it in your network manager config.

Persisting Bridges in Netplan

On modern Ubuntu versions that use Netplan, edit /etc/netplan/00-installer-config.yaml and add your bridge info like so:

network:
  version: 2
  ethernets:  
    eno1: {}  
    eno2: {}

  bridges:
    br0:
     interfaces: [eno1, eno2]
     addresses: [192.168.1.10/24]
     gateway4: 192.168.1.1
     nameservers:
          addresses: [8.8.8.8, 1.1.1.1]

Notice this configures eno1 and eno2 to join bridge br0, alongside network details for the bridge itself.

Apply the config by running:

sudo netplan apply

The same bridge will now be configured automatically on each boot.

Persisting Bridges in /etc/network/interfaces

If your system uses /etc/network/interfaces instead of Netplan, edit this file to define your bridge:

auto br0
iface br0 inet static
        address 192.168.1.10
        netmask 255.255.255.0
        gateway 192.168.1.1
        bridge_ports eno1 eno2
        bridge_stp off
        bridge_fd 0

Some important options here include:

  • bridge_ports – The real NICs that make up the bridge br0.
  • bridge_stp – Spanning tree protocol. Can help avoid bridging loops.
  • bridge_fd – Forward delay for port transitions to the bridge.

Reboot or restart networking to apply this /etc/network/interfaces bridge configuration.

Managing Existing Bridges

You can continue to use brctl and other bridge utils commands to manage configured bridges. Useful operations include:

Display bridge info

See an overview of all configured bridges using brctl show:

$ brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.02423c063e8b       no              eno1
                                                        eno2

List bridge interfaces

To show just the interfaces (bridged NICs) belonging to a specific bridge:

$ brctl showifs br0
interface name port id                STP enabled      priority  path cost
eno1          8000.51527376d093       no               128       100 
eno2          8000.ee4dfb9aac28       no               128       100

Add/remove interfaces

Add another interface eno3 to bridge br0:

sudo brctl addif br0 eno3

Conversely, remove eno2 from the bridge with:

sudo brctl delif br0 eno2

Delete a bridge

When you no longer need a bridge, delete it with:

sudo brctl delbr br0

This will remove the bridge entirely and disconnect the bridged NICs.

Get statistics

See packet counters and bridge/port stats using:

sudo brctl showstp br0

There are even more available options – check man brctl for full usage details.

Tips for Configuring Bridges

Here are some useful tips for setting up and managing bridged networks with bridge utils:

  • Give each bridge a unique name like br0, br1, etc to help identify its purpose
  • Add only necessary interfaces to bridges to avoid creating potential bottlenecks or loops
  • Use spanning tree protocol where possible, especially for large numbers of bridged interfaces
  • Monitor bridge traffic with stats and packet counters (brctl showstp) to catch problems
  • Set forwarding delay appropriately on busy bridges to avoid interface state changes causing temporary outages
  • Create strict firewall policies around bridges to limit access and improve control/security

Troubleshooting Bridge Issues

Problems can arise if bridge utils bridges are misconfigured. Here are some common issues and fixes.

No connectivity between bridged interfaces – Check BRIDGED INTERFACES see each other in the bridge with brctl showifs. Ensure IPs are correctly assigned, MAC learning is enabled, and rules/firewalls are not blocking bridged traffic.

Intermittent connectivity loss – This can occur if bridge STP parameters are off or port state changes briefly drop forwarded traffic. Tune bridge STP settings and forwarding delay. Monitor stats with brctl showstp.

Bridge takes AGES to forward first packet – Large forwarding delays configured? STP can also delay initial traffic significantly. Tune bridge timers accordingly.

Bridge interfaces flapping up/down – Flapping links will take bridges offline. Check interface health (driver issues?). STP problems could also cause port changes. View bridge logs.

Many quirks come down to spanning tree protocol issues. Understand your environment before tuning STP too heavily.

Final Thoughts

Bridging in Linux is incredibly useful for interconnecting subnets, carrying VM traffic, prototyping networks, and improving security by segmentation. Bridge utils supply simple but powerful tools for configuring bridge devices directly from the CLI.

With brctl and bridge companion utilities, admins can swiftly create, manage, and analyze Ethernet bridges on demand. Just be sure to persist any custom bridges using a network manager config to reuse them after reboots.

For more advanced bridge configurations, also look at Linux bonding driver options. Bonding enables aggregating multiple NICs into a single bridged interface for increases throughput and redundancy.

I hope this detailed bridge utils tutorial helps demystify Linux bridging for your environment! Let me know in the comments if you have any other bridge configuration questions.

Similar Posts