Configuring Network Interface Bonding in Linux
Network interface bonding in Linux aggregates multiple physical network interfaces into a single logical interface too enhance bandwidth, load balancing, and redundancy. This technique is essential in complex network environments for improving performance and availability.
Linux supports several bonding modes, each with distinct characteristics and use cases.
| Alias | Configuration Name | English Name | Chinese Name | Description |
|---|---|---|---|---|
| bond0 | balance-rr | Round-robin policy | 平衡轮询策略 | Transmits packets sequentially across interfaces, providing load balancing and fault tolerance. |
| bond1 | active-backup | Active-backup policy | 活动备份策略 | Only one interface is active; if it fails, a backup takes over, offering fault tolerance. MAC address is externally visible. |
| bond2 | balance-xor | XOR policy | 平衡策略 | Selects transmission interface based on (source MAC XOR destination MAC) mod device count, providing load balancing and fault tolerance. |
| bond3 | broadcast | Broadcast policy | 广播策略 | Sends all packets to every interface, ensuring fault tolerance. |
| bond4 | 802.3ad | IEEE 802.3ad Dynamic link aggregation | IEEE 802.3ad 动态链接聚合 | Creates an aggregation group with shared speed and duplex settings, requiring switch support for 802.3ad mode and driver-based speed/duplex retrieval. |
| bond5 | balance-tlb | Adaptive transmit load balancing | 适配器传输负载均衡 | Distributes outgoing traffic based on current load without special switch support; incoming traffic is handled by the current active interface. |
| bond6 | balance-alb | Adaptive load balancing | 适配器负载均衡 | Includes mode5 features with ARP negotiation for receive load balancing, intercepting ARP requests to use hardware addresses from slave devices. |
- Modes 0, 2, and 3 typically require static aggregation methods.
- Modes 1, 5, and 6 do not need switch configuration; network cards can aggregate automatically.
- Mode 4 requires 802.3ad support and switch configuration.
Active-Backup Mode
In this mode, only one network interface is active, with others as backups. If the active interface fails, a backup takes over, making it suitable for high-availability network connections.
Balance-RR (Round Robin) Mode
Packets are distributed in a round-robin fashion across all available interfaces. This mode provides load balancing but may not fully utilize bandwidth.
802.3ad (LACP) Mode
Utilizes the Link Aggregation Control Protocol (LACP) to bind multiple interfaces together, offering load balancing and redundancy. Switch support is required.
Balance-TLB (Transmit Load Balancing) Mode
Distributes packets based on current network traffic conditions, providing adaptive load balancing.
Balance-ALB (Adaptive Load Balancing) Mode
Learns optimal paths for packet transmission, suitable for dynamic network environments.
Configuration Steps on Linux Systems
Step 1: Install the ifenslave Tool
sudo apt-get install ifenslave
Step 2: Edit Network Configuration File
Modify the /etc/network/interfaces file to add bonding configurations:
# Network interfaces configuration
source /etc/network/interfaces.d/*
# Loopback interface
auto lo
iface lo inet loopback
# First slave interface
auto eth0
iface eth0 inet manual
bond-master bond0
# Second slave interface
auto eth1
iface eth1 inet manual
bond-master bond0
# Bonding interface
auto bond0
iface bond0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4
slaves eth0 eth1
bond-mode 1
bond-miimon 100
bond-lacp-rate 1
Step 3: Restart Network Services
sudo service networking restart
Configuration Steps on OpenWrt Systems
Check if necessary kernel components are installed:
opkg list | grep kmod-bonding
If not present, install kmod-bonding. In the latest official kernel version 5.15.162, this component is included by default. Older versions may require upgrading.
View current kernel version:
uname -r
Install link aggregation kernel module and LuCI graphical plugin:
opkg update
opkg install kmod-bonding
opkg install luci-proto-bonding
Offline installation using IPK packages:
- kmod-bonding: https://downloads.openwrt.org/releases/23.05.4/targets/x86/64/packages/kmod-bonding_5.15.162-1_x86_64.ipk
- luci-proto-bonding: https://downloads.openwrt.org/releases/23.05.4/packages/x86_64/luci/luci-proto-bonding_git-24.364.71483-75d2b84_all.ipk
After installation, reboot the system. The link aggregation feature will appear in the network interface configuration.