DOC_TYPE: RESEARCH_LOG

NIC Bonding on Linux: High Performance and Redundancy

#Linux#Network#NIC Bonding#Netplan#High Availability

NIC Bonding on Linux: High Performance and Redundancy

This guide explains what NIC bonding is, why it is used, and how it can be configured step by step on Ubuntu 22.04.


✨ What Is NIC Bonding?

NIC bonding combines multiple physical network interfaces into a single logical interface. This can improve both performance through combined bandwidth and redundancy through high availability.

Also known as:

  • Link Aggregation (LAG)
  • LACP (802.3ad / 802.1AX)
  • Interface Bonding

🧠 Why Use NIC Bonding?

Redundancy

If one NIC or switch port fails, another NIC can take over and keep the connection alive.

A critical database server may have ens33 and ens37 joined under bond0 with mode=active-backup. If the switch port connected to ens33 fails, traffic moves to ens37 automatically and services continue without interruption.

Performance / Load Balancing

Multiple NICs can carry traffic at the same time. This can increase total available bandwidth depending on mode, workload, and switch support.

Common Use Cases

  • Web servers
  • Proxy, DLP, SIEM, and security appliances
  • Switch uplinks
  • High-volume server-to-server transfers

📊 NIC Bonding Modes

ModeNamePurposeSwitch Required?
0balance-rrRound-robin load balancingNo
1active-backupRedundancyNo
2balance-xorHash-based balancingSometimes
3broadcastSend through all interfacesNo
4802.3ad (LACP)Standard link aggregationYes
5balance-tlbAdaptive transmit load balancingNo
6balance-albAdaptive load balancingNo

⚙ Ubuntu 22.04 Netplan Configuration

sudo apt update
sudo apt install ifenslave -y
sudo modprobe bonding

active-backup

network:
  version: 2
  renderer: networkd
  ethernets:
    ens33: {}
    ens37: {}
  bonds:
    bond0:
      interfaces:
        - ens33
        - ens37
      addresses:
        - 192.168.1.200/24
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 1.1.1.1]
      parameters:
        mode: active-backup
        primary: ens33
        mii-monitor-interval: 100
sudo netplan apply

balance-rr

network:
  version: 2
  renderer: networkd
  ethernets:
    ens33: {}
    ens37: {}
    ens38: {}
  bonds:
    bond0:
      interfaces:
        - ens33
        - ens37
        - ens38
      addresses:
        - 192.168.1.200/24
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 1.1.1.1]
      parameters:
        mode: balance-rr
        mii-monitor-interval: 100

balance-rr distributes traffic across interfaces but may cause packet ordering issues for some TCP workloads.


📈 Testing with iperf3

Server side:

iperf3 -s

Bonding side:

iperf3 -c 192.168.1.165 -t 10 -P 4

📊 Verifying Traffic Distribution

watch -n 1 cat /sys/class/net/ens33/statistics/tx_bytes
watch -n 1 cat /sys/class/net/ens37/statistics/tx_bytes
watch -n 1 cat /sys/class/net/ens38/statistics/tx_bytes
ip -s link show ens33

Simple monitoring script:

#!/bin/bash
interfaces=("ens33" "ens37" "ens38")
declare -A last
for iface in "${interfaces[@]}"; do
  last[$iface]=$(cat /sys/class/net/$iface/statistics/tx_bytes)
done

while true; do
  clear
  echo "NIC Bonding Traffic Monitor (tx_bytes/sec)"
  echo "-------------------------------------------"
  for iface in "${interfaces[@]}"; do
    current=$(cat /sys/class/net/$iface/statistics/tx_bytes)
    diff=$((current - last[$iface]))
    kbps=$((diff / 1024))
    printf "%-8s: %8d KB/s\n" "$iface" "$kbps"
    last[$iface]=$current
  done
  sleep 1
done

image


Virtual Environment Notes

  • mode=802.3ad usually does not work in VMware Workstation because switch support is missing
  • balance-rr is often the most compatible lab mode
  • Each virtual NIC must be connected

Conclusion

NIC bonding is useful for network availability and, depending on the selected mode, throughput improvement. Use active-backup for redundancy, and balance-rr or 802.3ad for performance-focused scenarios after proper testing.

Prepared by: Aziz Ortanç

GitHub: github.com/Aziz4706