單一實體網卡故障會導致服務中斷,Linux 核心內建的 bonding 驅動可將多張實體網卡聚合為一張虛擬網卡,提供連結備援與頻寬疊加。本文以 eth0 + eth1 綁定為 bond0 為例,完整說明設定流程、模式選擇與注意事項。

vi /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
BOOTPROTO=static
IPADDR=10.0.11.10
NETMASK=255.255.252.0
GATEWAY=10.0.11.1
ONBOOT=yes
USERCTL=no
TYPE=Ethernet
vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
MASTER=bond0
SLAVE=yes
TYPE=Ethernet
ifcfg-eth1 內容相同,僅 DEVICE 改為 eth1。
編輯 /etc/modprobe.d/bonding.conf(或舊版 /etc/modules.conf):
alias bond0 bonding
options bond0 miimon=100 mode=0
參數說明:
miimon=100:每 100ms 檢測一次連結狀態mode=0:負載均衡 - 兩張網卡皆 Active,流量輪詢分發mode=1:主動備援 - 僅一張 Active,另一張 Standby,故障切換若使用 mode=1,建議加入 primary=eth0 指定偏好主網卡。
編輯 /etc/rc.local(或建立 systemd service):
modprobe bonding miimon=100 mode=0
# 重啟網路服務或重開機
systemctl restart network
# 查看 bonding 狀態
cat /proc/net/bonding/bond0
# 關鍵輸出:Bonding Mode: load balancing (round-robin) / fault-tolerance (active-backup)
# MII Status: up
# Slave Interface: eth0 / eth1
Bonding 僅能偵測「主機到交換機」的第一層連結。若交換機上游連結中斷但交換機本身正常,bonding 仍判定連結正常,無法切換。生產環境建議搭配交換機端的 LACP (802.3ad, mode=4) 或上層應用層健康檢查。