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
| Mode | Name | Purpose | Switch Required? |
|---|---|---|---|
| 0 | balance-rr | Round-robin load balancing | No |
| 1 | active-backup | Redundancy | No |
| 2 | balance-xor | Hash-based balancing | Sometimes |
| 3 | broadcast | Send through all interfaces | No |
| 4 | 802.3ad (LACP) | Standard link aggregation | Yes |
| 5 | balance-tlb | Adaptive transmit load balancing | No |
| 6 | balance-alb | Adaptive load balancing | No |
⚙ 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
Virtual Environment Notes
mode=802.3adusually does not work in VMware Workstation because switch support is missingbalance-rris 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