Bridging and bonding are two essential networking concepts in Linux that allow you to combine multiple network interfaces into a single logical interface. This provides increased bandwidth, redundancy, and flexibility in your network.

In this comprehensive guide, we will walk through how to configure, modify, and delete both bridges and bonds on Linux systems.

An Overview of Network Bridges

A network bridge essentially connects two or more network segments together. It works by forwarding traffic between different interfaces, networks, or hosts that are connected to it.

Some key advantages of using bridges include:

  • Sharing connections – You can connect multiple devices to a Linux system with a single internet connection and bridge them to share the connection.

  • Segmenting networks – Bridges allow you to break larger networks into smaller segments while still allowing them to communicate through the bridge.

  • Performance and redundancy – Adding multiple interfaces to a bridge provides more total bandwidth and redundancy in case one interface fails.

Common use cases for bridges include:

  • Turning a Linux system into a basic network switch to connect multiple devices.

  • Allowing virtual machines access to a physical network.

  • Separating different networks or VLANs while allowing communication between them.

An Overview of Network Bonding

Network bonding refers to combining multiple network interfaces into a single logical "bonded" interface.

The main advantages of bonding include:

  • Increased bandwidth – Combining multiple interfaces gives you overall higher potential bandwidth.

  • Redundancy – If one bonded interface goes down, traffic automatically switches to the remaining interfaces.

  • Load balancing – Traffic can be distributed across the bonded interfaces.

Some common reasons to use bonding are:

  • Upgrade bandwidth on servers without replacing NICs

  • Ensure high availability by providing failover and redundancy

  • Aggregate bandwidth from multiple low-cost interfaces

Bonding modes allow you to configure how traffic is distributed across the bonded interfaces. Common modes are round-robin, active-backup, and load balancing based on hash policies.

Now that we‘ve covered the basics, let‘s walk through configuring bridges and bonds on a Linux system.

Prerequisites

Before we get started, there are a few prerequisites:

  • A Linux system with at least two network interfaces. For this guide, we‘ll use the primary ens33 and a secondary ens37 interface.

  • Administrative access, either as root or via sudo.

  • The bridge-utils package installed for managing bridges.

With that covered, let‘s get into setting up Linux bridges!

Configuring Linux Bridge Interfaces

The basic steps to create a Linux bridge are:

  1. Install bridge-utils
  2. Create the bridge with brctl addbr
  3. Add interfaces to it with brctl addif
  4. Assign an IP address

First, make sure the bridge-utils package is installed:

sudo apt update
sudo apt install bridge-utils

Next, we‘ll create the bridge itself and call it br0:

sudo brctl addbr br0

Let‘s add our two interfaces ens33 and ens37 to the bridge:

sudo brctl addif br0 ens33
sudo brctl addif br0 ens37 

We‘ll give the bridge an IP address by editing /etc/network/interfaces:

auto br0
iface br0 inet static
    address 192.168.1.10
    netmask 255.255.255.0
    bridge_ports ens33 ens37

Finally restart networking or reboot:

sudo systemctl restart networking

Our basic Linux bridge with two interfaces is now configured!

Modifying Bridges: Adding/Removing Ports

To add or remove additional interfaces from an existing Linux bridge, you use the brctl addif and brctl delif commands.

For example, to remove ens37 from br0:

sudo brctl delif br0 ens37

To add a new interface ens38:

sudo brctl addif br0 ens38

The bridge configuration will be updated automatically. You can run brctl show to verify the interfaces in the bridge at any time.

Making interface changes at runtime like this allows maximum flexibility – you can dynamically reconfigure bridges on a running system.

Deleting Linux Bridge Interfaces

To delete or remove a configured Linux bridge entirely:

  1. First bring down the bridge interface:

     sudo ip link set dev br0 down
  2. Delete the actual bridge:

     sudo brctl delbr br0
  3. Update any network config files like /etc/network/interfaces to remove the old bridge definition

  4. Restart networking:

     sudo systemctl restart networking 

The bridge interface br0 will be removed along with all its port assignments.

An Overview of Bonding Modes

Before we get into configuring a network bond, let‘s briefly summarize the different bonding modes available:

  • balance-rr: Round-robin policy through both interfaces
  • active-backup: Only one interface active with automatic failover
  • balance-xor: Transmissions based on MAC address
  • broadcast: Transmits everything on all interfaces
  • 802.3ad: Dynamic link aggregation with LACP
  • balance-tlb: Adaptive transmit load balancing
  • balance-alb: Adaptive load balancing based on interface speed

The default mode is usually active-backup which provides basic failover redundancy between two interfaces.

However all modes have different advantages depending on your specific needs for throughput, redundancy, and load balancing.

Creating a Basic Bond with two Interfaces

Let‘s create a simple bonded interface using the active-backup mode between ens33 and ens37.

First, install the bonding driver utilities:

sudo apt install ifenslave

Next, edit the interfaces config file. We‘ll create a bonded interface called bond0:

auto bond0
iface bond0 inet dhcp
    bond-mode active-backup
    bond-miimon 100
    bond-slaves none

auto ens33
iface ens33 inet manual
    bond-master bond0

auto ens37 
iface ens37 inet manual
    bond-master bond0

There‘s a few important options to explain here:

  • bond-mode active-backup specifies our bonding mode

  • bond-miimon 100 checks link health every 100 milliseconds

  • bond-slaves none lists the bonded interfaces

We assign the physical interfaces ens33 and ens37 as slaves to bond0 using their bond-master option.

Now restart networking to create the bond:

sudo systemctl restart networking

Run ip link show to verify the bond0 interface is active with ens33 and ens37 as slave devices.

Modifying Bonds: Changing Active Slaves

When using the active-backup mode, you can control which bonded interface is active at a given time:

sudo ifenslave -c bond0 ens37

This will immediately make ens37 the active slave, disabling ens33. Traffic will now use the ens37 interface.

This allows you to manually control failover order if needed. Other bond modes load balance automatically across all available interfaces.

Adding and Removing Slave Interfaces

To dynamically add or remove slave interfaces from an existing Linux bonded interface:

Add interface:

sudo ifenslave bond0 ens38

Remove interface:

sudo ifenslave -d bond0 ens33

No other configuration changes are needed. The kernel bonding driver handles everything automatically.

Again you can check ip link show and the files in /proc/net/bonding to validate slave interface changes.

Deleting Bonded Interfaces

To delete an existing bond, first remove all its slave interfaces:

sudo ifenslave -d bond0 all

Then update your network config by removing all bond related configuration.

Finally restart networking:

sudo systemctl restart networking

This will shutdown the bond device and you network configuration will revert back to the individual physical interfaces.

Final Thoughts

That wraps up our guide on configuring bonded and bridged network interfaces within Linux!

We showed you how to create and manage both bridges and bonds, configure bonding modes, dynamically add and remove additional interfaces, and delete managed interfaces when needed.

Bridging and bonding both provide useful tools on Linux for improving performance, flexibility, redundancy and high availability across systems and networks. By mastering bridge and bond configuration you unlock additional networking capabilities for your Linux systems.

Let me know if you have any other questions!

Similar Posts