dotlinux guide

Leveraging Linux Network Bonding to Increase Throughput

In today’s data-driven world, network throughput is a critical bottleneck for high-performance systems—whether it’s a file server handling large data transfers, a database cluster processing thousands of queries, or a web server serving global traffic. Linux network bonding (also called NIC teaming) is a powerful technique that aggregates multiple physical network interfaces (NICs) into a single logical interface, enabling increased bandwidth, load balancing, and fault tolerance. By combining two or more NICs, bonding allows you to harness their combined throughput (e.g., two 1 Gbps NICs can theoretically deliver 2 Gbps) while maintaining redundancy if one interface fails. This blog explores the fundamentals of Linux network bonding, step-by-step implementation, common practices, and best practices to help you maximize throughput effectively.

Table of Contents

  1. Understanding Linux Network Bonding
    • 1.1 What is Network Bonding?
    • 1.2 Key Benefits
    • 1.3 Bonding Modes for Throughput
  2. Prerequisites
  3. Step-by-Step Implementation
    • 3.1 Using nmcli (NetworkManager)
    • 3.2 Using ifenslave (Legacy)
    • 3.3 Verifying Bond Configuration
    • 3.4 Testing Throughput with iperf3
  4. Common Practices
  5. Best Practices
  6. Troubleshooting
  7. Conclusion
  8. References

1. Understanding Linux Network Bonding

1.1 What is Network Bonding?

Linux network bonding is a kernel-level feature that combines multiple physical network interfaces (e.g., eth0, eth1) into a single logical interface (e.g., bond0). The bonded interface acts as a single entity, with its own IP address, and distributes traffic across the underlying physical interfaces to optimize performance or provide redundancy.

1.2 Key Benefits

  • Increased Throughput: Aggregate bandwidth from multiple NICs (e.g., 2x 1 Gbps NICs → ~2 Gbps).
  • Redundancy: If one physical interface fails, traffic automatically shifts to others (depending on the mode).
  • Load Balancing: Distribute traffic across NICs to prevent bottlenecks.

1.3 Bonding Modes for Throughput

The Linux bonding driver supports 7 modes, but only a subset is designed to increase throughput. Below are the most relevant modes for throughput optimization:

ModeNameTraffic DistributionSwitch Configuration Required?Throughput PotentialUse Case
0balance-rrRound-robin (packets)No (but recommended for order)HighSimple load balancing (risk of out-of-order packets).
2balance-xorXOR of MAC/IP addressesNoModerateStatic load balancing (avoids round-robin chaos).
4802.3ad (LACP)Dynamic aggregation (LACP protocol)Yes (LACP-enabled port group)Highest/ReliableEnterprise-grade, standardized (IEEE 802.3ad).
6balance-albAdaptive load balancingNoModerateNo switch config needed (uses ARP monitoring).

Most Recommended: Mode 4 (802.3ad/LACP) for production, as it dynamically adjusts to link conditions and is standardized.

2. Prerequisites

Before implementing bonding:

  • Linux System: Any modern distribution (Ubuntu 20.04+, CentOS 8+, Debian 11+).
  • Multiple NICs: At least 2 physical interfaces (e.g., eth0, eth1).
  • Kernel Support: The bonding kernel module (loaded by default on most distros).
  • Switch Support (for Mode 4): Switch ports must support LACP (802.3ad) and be configured as a port channel.

3. Step-by-Step Implementation

3.1 Using nmcli (NetworkManager)

Most modern Linux systems use NetworkManager. Use nmcli (NetworkManager CLI) to configure bonding:

Step 1: Create the bonded interface

# Create a bond interface (mode 4 = 802.3ad/LACP)
nmcli con add type bond ifname bond0 mode 802.3ad ip4 192.168.1.100/24 gw4 192.168.1.1
  • ifname bond0: Name of the logical bond interface.
  • mode 802.3ad: Use LACP for dynamic aggregation.
  • ip4/gw4: Static IP and gateway (omit for DHCP).

Step 2: Add slave interfaces to the bond

# Add eth0 and eth1 as slaves to bond0
nmcli con add type bond-slave ifname eth0 master bond0
nmcli con add type bond-slave ifname eth1 master bond0

Step 3: Activate the bond

nmcli con up bond-bond0  # Activate the bond connection
nmcli con up bond-slave-eth0  # Activate slave eth0
nmcli con up bond-slave-eth1  # Activate slave eth1

3.2 Using ifenslave (Legacy)

For systems without NetworkManager (e.g., minimal servers), use ifenslave and manual configuration:

Step 1: Install ifenslave

# Ubuntu/Debian
sudo apt install ifenslave

# RHEL/CentOS
sudo yum install ifenslave

Step 2: Load the bonding module

sudo modprobe bonding mode=4 miimon=100  # mode=4 (LACP), miimon=100ms link monitoring

Step 3: Configure the bond interface

Edit /etc/network/interfaces (Debian/Ubuntu) or /etc/sysconfig/network-scripts/ifcfg-bond0 (RHEL/CentOS):

Debian/Ubuntu (/etc/network/interfaces):

auto bond0
iface bond0 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1
    bond-slaves eth0 eth1
    bond-mode 4  # 802.3ad
    bond-miimon 100  # Check link status every 100ms
    bond-downdelay 200
    bond-updelay 200

Step 4: Restart networking

# Debian/Ubuntu
sudo systemctl restart networking

# RHEL/CentOS
sudo systemctl restart network

3.3 Verifying Bond Configuration

Check the bond status with:

cat /proc/net/bonding/bond0

Sample Output for Mode 4 (LACP):

Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: IEEE 802.3ad Dynamic link aggregation
Transmit Hash Policy: layer2 (0)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 200
Down Delay (ms): 200

802.3ad info
LACP rate: slow
Min links: 0
Aggregator selection policy (ad_select): stable

Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:1b:21:xx:xx:xx
Aggregator ID: 1

Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:1b:21:yy:yy:yy
Aggregator ID: 1

3.4 Testing Throughput with iperf3

To validate increased throughput, use iperf3 to measure bandwidth between two systems:

On the bonded server (act as iperf server):

iperf3 -s  # -s = server mode

On a client (connect to the server):

iperf3 -c 192.168.1.100 -t 60  # -c = client, -t = test duration (60s)

Expected Result: With 2x 1 Gbps NICs in Mode 4, throughput should approach ~2 Gbps (e.g., 1.8-1.9 Gbps, accounting for overhead).

4. Common Practices

  • Choose Mode 4 (802.3ad/LACP) for Production: It’s the most reliable for throughput, as it dynamically negotiates links with the switch and avoids packet reordering issues.
  • Mode 0 (balance-rr) for Simple Setups: Use only if your switch lacks LACP support. Be cautious of out-of-order packets (breaks apps like NFS unless the switch is configured for “port channeling”).
  • Mode 6 (balance-alb) for Adaptive Load Balancing: No switch config needed, but throughput is limited by the single MAC address of the bond (less efficient than LACP).
  • Avoid Mixing NIC Speeds: All slave interfaces should have the same speed (e.g., 1 Gbps or 10 Gbps) to prevent bottlenecks.

5. Best Practices

  1. Use Identical NICs: Match speed (1 Gbps/10 Gbps), duplex (full), and driver (e.g., igb for Intel NICs) to ensure balanced traffic distribution.
  2. Configure Switch for LACP (Mode 4): On the switch, create a port channel (LAG) and enable LACP (active mode recommended). Example Cisco switch config:
    interface Port-channel1
      switchport mode trunk
    interface GigabitEthernet1/0/1
      switchport mode trunk
      channel-group 1 mode active  # LACP active mode
    interface GigabitEthernet1/0/2
      switchport mode trunk
      channel-group 1 mode active
  3. Monitor Bond Health: Use cat /proc/net/bonding/bond0 or tools like nload/iftop to track traffic per slave interface.
  4. Set miimon for Link Monitoring: Use miimon=100 (100ms) to quickly detect failed links.
  5. Test Failover: Unplug one NIC and verify traffic shifts to others (check dmesg for failover logs).

6. Troubleshooting

  • Bond Not Coming Up:

    • Ensure the bonding module is loaded: lsmod | grep bonding.
    • Verify slave interfaces are not assigned IPs individually (they should be “enslaved” to the bond).
  • Low Throughput in Mode 4:

    • Confirm switch LACP configuration (port channel, active mode).
    • Check for mismatched NIC speeds: ethtool eth0 | grep Speed.
  • Out-of-Order Packets (Mode 0):

    • Enable port channeling on the switch to group NICs into a single logical link.
  • Slave Interfaces Not Enslaving:

    • Ensure slaves are down before adding to the bond: ip link set eth0 down.

7. Conclusion

Linux network bonding is a powerful tool to increase throughput by aggregating multiple NICs into a single logical interface. By choosing the right mode (e.g., 802.3ad/LACP for enterprise setups) and following best practices (matching NICs, switch configuration), you can achieve near-linear throughput gains. Always test failover and monitor bond health to ensure reliability.

8. References