Files
oam/knowledge base/linux/bond network interfaces.md
2025-11-15 21:07:57 +01:00

5.4 KiB

Bond network interfaces

Combines multiple network interfaces into a single logical interface.
Provides benefits such as increased bandwidth, redundancy, and load balancing.

  1. TL;DR
  2. Bonding modes
  3. Configuration
  4. Further readings
    1. Sources

TL;DR

Linux bonding is implemented through the bonding kernel module.
It implements several bonding modes, each with its own characteristics and use cases.

If one's switches support LACP, prefer using mode 4 (802.3ad) for compatibility and optimal performance.
LACP allows the Linux system and the switch to negotiate the link aggregation settings automatically.

Usage
# Check the status of the bonding interface.
cat '/proc/net/bonding/bond0'

# Test the redundancy of the bonding interface.
# Simulates a failure of one of the slave interfaces.
ifconfig 'eth0' down; sleep 30s; ifconfig 'eth0' up

Bonding modes

ID Mode name Summary Use cases
0 Round Robin Sends packets out sequentially on each available slave interface.
Provides load balancing across all used interfaces and increases the overall bandwidth.
Environments where bandwidth aggregation is the primary goal and all connected switches support load balancing
1 Active-Backup Only one slave interface is active at a time. If the active interface fails, the driver automatically switches to one of the backup interfaces. Scenarios where redundancy is crucial, such as in mission-critical applications
2 XOR The driver uses a hash function to determine which slave interface to send a packet on. The hash is based on the source and destination MAC addresses. Networks where the traffic patterns are relatively stable, and the same source-destination pairs are likely to be used frequently
3 Broadcast All packets are sent out on all slave interfaces. Provides high redundancy, but consumes a lot of network resources.
4 802.3ad, Link Aggregation Control Protocol Requires support from the connected switches. Creates a link aggregation group (LAG) between the Linux system and the switch. Provides both load balancing and redundancy. Environments where high bandwidth and reliability are required
5 Balance-TLB Dynamically distributes outgoing traffic to the interface with the least load. Environments where the traffic distribution is uneven and load balancing is required
6 Balance-ALB Distributes both outgoing and incoming traffic across all slave interfaces Networks where both high bandwidth and load balancing are required

Configuration

  1. Load the bonding module:

    modprobe 'bonding'
    
  2. Create a bonding interface.

    Add a configuration file in the /etc/sysctl.d/ directory:

    # /etc/sysctl.d/bond0.conf
    # miimon: interval (in milliseconds) at which the bonding driver checks the link status of the slave interfaces
    bonding.modes=mode=6 miimon=100
    
  3. Add the slave interfaces:

    # /etc/network/interfaces
    
    auto bond0
    iface bond0 inet static
        address <ip_address>
        netmask <netmask>
        gateway <gateway>
        bond-mode <mode_number>
        bond-miimon 100
        bond-slaves eth0 eth1
    
  4. Restart the network service:

    sudo systemctl restart networking
    

Further readings

Sources