場景定義
- 兩張物理網卡
eth0、eth1
- 連接多台交換機 (跨機架冗餘)
- 虛擬 IP (VIP):
192.168.100.100/24,閘道 192.168.100.1
RHEL 6 配置
Mode 1 (Active-Backup,非 LACP)
# /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.100.100
NETMASK=255.255.255.0
GATEWAY=192.168.100.1
USERCTL=no
NM_CONTROLLED=no
BONDING_OPTS="mode=1 primary=eth0 miimon=100"
# /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
NM_CONTROLLED=no
# /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
NM_CONTROLLED=no
Mode 4 (802.3ad LACP,需交換機配置)
# ifcfg-bond0 差異處
BONDING_OPTS="mode=4 miimon=100 xmit_hash_policy=layer2+3"
# 其餘相同
RHEL 7 配置 (NetworkManager 兼容)
Mode 1
# ifcfg-bond0
DEVICE=bond0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.100.100
NETMASK=255.255.255.0
GATEWAY=192.168.100.1
USERCTL=no
NM_CONTROLLED=no
BONDING_OPTS="mode=1 primary=eth0 miimon=100"
# ifcfg-eth0 / ifcfg-eth1 同 RHEL 6
Mode 4
# ifcfg-bond0 差異處
BONDING_OPTS="mode=4 miimon=100 xmit_hash_policy=layer2+3"
關鍵參數解析
| 參數 | 含義 | 建議值 |
| mode=1 | 主備模式,單一 active,其餘 standby | 跨交換機高可用,無需交換機支援 |
| mode=4 | LACP 動態鏈路聚合,負載分擔 | 需交換機配置 LACP,吞吐加倍 |
| primary=eth0 | 指定優先 active 介面 | Mode 1 必設 |
| miimon=100 | MII 鏈路監測間隔 (ms) | 100ms 平衡靈敏度與誤判 |
| xmit_hash_policy=layer2+3 | LACP 雜湊策略:L2 MAC + L3 IP | 流量更均勻分佈 |
驗證指令
# 查看 bonding 狀態
cat /proc/net/bonding/bond0
# 關鍵輸出檢查
# Bonding Mode: fault-tolerance (active-backup) / IEEE 802.3ad Dynamic link aggregation
# Active Slave: eth0
# MII Status: up
# Slave Interface: eth0/eth1 狀態
注意事項
- RHEL 7 建議使用
nmcli 或 nmtui 管理,避免 NetworkManager 衝突
- Mode 4 必須交換機端配置 LACP 群組,否則链路不會 up
- VLAN 標籤需配置在 bond0 上 (如
bond0.100),而非 slave 介面
- MTU 需在 bond0、slave、交換機端保持一致 (如 9000 Jumbo Frame)