| Mode | 名稱 | 特點 | 交換機要求 |
| 0 | balance-rr | 輪詢負載均衡 | 需配置靜態聚合 |
| 1 | active-backup | 主備故障轉移(推薦生產) | 無特殊要求 |
| 4 | 802.3ad | 動態鏈路聚合 (LACP) | 需支持 LACP 配置 |
| 5 | balance-tlb | 適應性負載均衡 | 無特殊要求 |
| 6 | balance-alb | 適應性負載均衡 + ARP 協商 | 無特殊要求 |
配置示例:Mode 1 主備模式(最常用)
1. 配置 Bond 接口 /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.2
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
USERCTL=no
BONDING_OPTS="mode=1 miimon=100"
2. 配置從屬網卡 ifcfg-eth0、ifcfg-eth1
# ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
USERCTL=no
# ifcfg-eth1
DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
USERCTL=no
3. 加載 bonding 模塊 /etc/modprobe.d/bonding.conf
alias bond0 bonding
options bonding mode=1 miimon=100
4. 重啟網絡生效
systemctl restart network
# 或 service network restart
驗證綁定狀態
cat /proc/net/bonding/bond0
關鍵輸出:
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:29:xx:xx:xx
Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:29:xx:xx:yy
關鍵參數說明
miimon=100:每 100ms 檢查一次鏈路狀態(MII 監控)
mode=1:主備模式,僅一張卡活躍
primary=eth0(可選):指定優先主卡,恢復時切回
updelay/downdelay:鏈路狀態變化延遲,防抖動
NetworkManager 管理(CentOS 7/8 推薦)
# 創建 bond
nmcli con add type bond con-name bond0 ifname bond0 mode active-backup ipv4.addresses 192.168.1.2/24 ipv4.gateway 192.168.1.1 ipv4.method manual
# 添加從屬網卡
nmcli con add type bond-slave con-name eth0-master ifname eth0 master bond0
nmcli con add type bond-slave con-name eth1-master ifname eth1 master bond0
# 啟用
nmcli con up bond0
nmcli con up eth0-master
nmcli con up eth1-master
注意事項
- Mode 0/4 需交換機端口聚合配置,否則可能導致網絡環路或單向通信
- 物理網卡驅動需支持 MII/ETHTOOL 狀態查詢
- 綁定後 MAC 地址默認使用第一張從屬網卡 MAC
- 建議配置後 重啟系統 而非僅重啟網絡服務,確保內核模塊正確加載