architecture2025-03-05ยท12 minยท158/348

Linux Network Bonding: Link Aggregation and Failover

Setting up network bonding on Linux for increased bandwidth and redundancy, including configuration modes, testing, and monitoring.

Introduction

Network bonding combines multiple physical network interfaces into a single logical interface. This provides either increased bandwidth through aggregation or redundancy through failover. On Linux, bonding is configured through the bonding driver and is essential for high-availability servers. This post covers the different bonding modes and their configuration.

Environment

The examples use Ubuntu 22.04 LTS with two 1 Gbps Ethernet interfaces (eth0 and eth1) that will be bonded for failover and load balancing.

ip link show
# 1: lo: 
# 2: eth0: 
# 3: eth1: 

modinfo bonding | grep description
# description:    Ethernet Channel Bonding Driver

Problem

A single network interface is a single point of failure. If it goes down, the server loses connectivity. Additionally, a single 1 Gbps link may not provide sufficient bandwidth for high-traffic servers.

Analysis

Linux bonding supports several modes:

ModeNameDescription
0balance-rrRound-robin, load balancing
1active-backupFailover, one active slave
2balance-xorXOR hash balancing
3broadcastAll slaves receive all packets
4802.3adLACP, requires switch support
5balance-tlbAdaptive transmit load balancing
6balance-albAdaptive load balancing (rx+tx)

Check if the bonding module is loaded:

lsmod | grep bonding
# bonding               172032  0

# If not loaded
sudo modprobe bonding

Solution

1. Configure active-backup mode (failover)

# Create bond interface
sudo nano /etc/netplan/01-bonding.yaml
network:
  version: 2
  renderer: networkd
  bonds:
    bond0:
      interfaces:
        - eth0
        - eth1
      addresses:
        - 192.168.1.10/24
      routes:
        - to: default
          via: 192.168.1.1
      parameters:
        mode: active-backup
        primary: eth0
        mii-monitor-interval: 100
sudo netplan apply

2. Configure balance-rr mode (round-robin)

network:
  version: 2
  renderer: networkd
  bonds:
    bond0:
      interfaces:
        - eth0
        - eth1
      addresses:
        - 192.168.1.10/24
      routes:
        - to: default
          via: 192.168.1.1
      parameters:
        mode: balance-rr
        mii-monitor-interval: 100

3. Configure 802.3ad mode (LACP)

network:
  version: 2
  renderer: networkd
  bonds:
    bond0:
      interfaces:
        - eth0
        - eth1
      addresses:
        - 192.168.1.10/24
      routes:
        - to: default
          via: 192.168.1.1
      parameters:
        mode: 802.3ad
        lacp-rate: fast
        mii-monitor-interval: 100
        transmit-hash-policy: layer3+4

Requires switch configuration for LACP.

4. Verify bond status

cat /proc/net/bonding/bond0
# Bonding Mode: fault-tolerance (active-backup)
# Primary Slave: eth0
# Currently Active Slave: eth0
# MII Status: up
# MII Polling Interval (ms): 100
# Up Delay (ms): 0
# Down Delay (ms): 0
#
# Slave Interface: eth0
# MII Status: up
# Speed: 1000 Mbps
# Duplex: full
#
# Slave Interface: eth1
# MII Status: up
# Speed: 1000 Mbps
# Duplex: full

5. Test failover

# Check current status
ip link show bond0
# 4: bond0:  mtu 1500

# Simulate interface failure
sudo ip link set eth0 down

# Check failover occurred
cat /proc/net/bonding/bond0 | grep "Currently Active"
# Currently Active Slave: eth1

# Ping should still work
ping -c 4 192.168.1.1
# PING 192.168.1.1: 64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.5ms

6. Configure ARP monitoring

network:
  version: 2
  bonds:
    bond0:
      interfaces:
        - eth0
        - eth1
      parameters:
        mode: active-backup
        arp-monitor:
          interval: 100
          targets:
            - 192.168.1.1
            - 192.168.1.2

7. Monitor bond statistics

# Check bond statistics
ip -s link show bond0
# 4: bond0: 
#     RX:  bytes packets errors dropped  missed   mcast
#     123456789  123456      0      0       0       0
#     TX:  bytes packets errors dropped carrier collsns
#     987654321  987654      0      0       0       0

# Check per-slave statistics
ethtool eth0
# Speed: 1000Mb/s
# Link detected: yes

8. Configure bonding via sysfs

# Create bond interface
echo bonding > /sys/class/net/bond0/bonding/mode

# Add slaves
echo +eth0 > /sys/class/net/bond0/bonding/slaves
echo +eth1 > /sys/class/net/bond0/bonding/slaves

# Set options
echo active-backup > /sys/class/net/bond0/bonding/mode
echo 100 > /sys/class/net/bond0/bonding/miimon

9. Use nmcli for NetworkManager

# Create bond connection
sudo nmcli con add type bond ifname bond0 bond.options "mode=active-backup,miimon=100"

# Add slave interfaces
sudo nmcli con add type ethernet ifname eth0 master bond0
sudo nmcli con add type ethernet ifname eth1 master bond0

# Configure IP
sudo nmcli con modify bond-bond0 ipv4.addresses 192.168.1.10/24
sudo nmcli con modify bond-bond0 ipv4.gateway 192.168.1.1
sudo nmcli con modify bond-bond0 ipv4.method manual

# Activate
sudo nmcli con up bond-bond0

10. Set up monitoring alerts

#!/bin/bash
# monitor-bond.sh

STATUS=$(cat /proc/net/bonding/bond0 | grep "Currently Active" | awk '{print $NF}')
SLAVES=$(cat /proc/net/bonding/bond0 | grep "Slave Interface" | wc -l)
UP_SLAVES=$(cat /proc/net/bonding/bond0 | grep "MII Status: up" | wc -l)

if [ "$UP_SLAVES" -lt "$SLAVES" ]; then
  echo "WARNING: Bond has $UP_SLAVES of $SLAVES slaves up" | logger -t bond-monitor
fi

Lessons Learned

Network bonding provides essential redundancy for production servers. active-backup mode is the simplest and most reliable for failover. 802.3ad mode provides both aggregation and failover but requires switch support. Always test failover by simulating interface failures. And monitor bond status regularly to ensure all slaves are healthy.


This blog does not accept any external sponsorships, affiliate marketing, or ad revenue.