Linux Network Bonding: LACP (802.3ad) and active-backup Modes - 夜莺博客

Linux Network Bonding: LACP (802.3ad) and active-backup Modes

Bonding two NICs into one logical interface is the standard way to remove the server NIC as a single point of failure - and optionally to multiply throughput. The Linux bonding driver offers seven modes, but production boils down to two: 802.3ad LACP (mode 4) when you control the switch, and active-backup (mode 1) when you do not. This guide explains the modes, shows the switch side and the Linux side, and covers the verification and failover tests that prove the bond actually works.

Bonding Modes at a Glance

Mode Name Use case Switch requirement
0 balance-rr throughput, no fault tolerance guarantee none (can reorder packets)
1 active-backup pure redundancy none - works everywhere
2 balance-xor throughput + redundancy static LAG
4 802.3ad (LACP) throughput + redundancy (recommended) LACP-enabled switch port
6 balance-alb adaptive load balancing none (ARP-dependent)

For new deployments pick mode 4 when you own the switch, mode 1 otherwise - a misconfigured LACP bond (one side negotiating, the other not) drops all traffic.

Switch-Side Configuration (LACP only)

Mode 4 needs IEEE 802.3ad on both ends. Cisco IOS/XE example:

interface GigabitEthernet0/1
 channel-group 1 mode active
interface GigabitEthernet0/2
 channel-group 1 mode active
interface Port-channel1
 description bond0-server
 switchport mode access
 switchport access vlan 100

Use mode active when the Linux side sends LACP PDUs (it does by default); mode passive on one end is also fine, but mode on (static) will not negotiate. Juniper EX equivalent:

set interfaces ae0 aggregated-ether-options lacp active
set interfaces ge-0/0/0 ether-options 802.3ad ae0
set interfaces ge-0/0/1 ether-options 802.3ad ae0

Linux-Side Configuration with NetworkManager

# LACP (mode 4)
sudo nmcli connection add type bond con-name bond0 ifname bond0   bond.options "mode=802.3ad,miimon=100,xmit_hash_policy=layer3+4"

# active-backup (mode 1)
sudo nmcli connection add type bond con-name bond0 ifname bond0   bond.options "mode=active-backup,miimon=100,fail_over_mac=active"

# slaves
sudo nmcli connection add type ethernet con-name bond0-slave1 ifname enp3s0 master bond0
sudo nmcli connection add type ethernet con-name bond0-slave2 ifname enp4s0 master bond0

# address
sudo nmcli connection modify bond0   ipv4.addresses 192.168.1.50/24 ipv4.gateway 192.168.1.1   ipv4.method manual

sudo nmcli connection up bond0
sudo nmcli connection up bond0-slave1
sudo nmcli connection up bond0-slave2

miimon=100 polls link state every 100 ms for failover detection; xmit_hash_policy layer3+4 spreads flows across slaves for LACP; fail_over_mac=active in active-backup mode prevents both slaves presenting the same MAC during failover on switches that track port MACs strictly. Set connection.autoconnect-slaves 1 on the bond so slaves rejoin after reboot.

Verification and Fault Testing

cat /proc/net/bonding/bond0      # mode, slaves, active slave, miimon
ip link show bond0
ethtool enp3s0                   # per-slave speed/duplex
sudo nmcli connection show bond0 | grep bond.options

# failover test
sudo ip link set enp3s0 down
cat /proc/net/bonding/bond0      # active slave should switch
sudo ip link set enp3s0 up

In LACP mode also verify the bundle on the switch (show lacp neighbor / show etherchannel summary on Cisco). Bonding pairs with the switch-side LAG concepts covered in our PAgP vs LACP guide and the Arista EOS port-channel guide; the per-vendor commands live in the multi-vendor CLI cheat sheet.

原文链接:https://linuxjunkies.org/guides/linux-network-bonding