Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

RedHat/CentOS 網卡綁定配置指南:實現鏈路冗余與負載均衡

編輯:Linux 教學

Bonding 技術簡介

網卡綁定將多塊物理網卡聚合為一個邏輯接口(bond0),提供:

  • 故障轉移:主卡故障自動切換備卡(Mode 1)
  • 負載均衡:多卡分發流量提高吞吐(Mode 0、4 等)
  • 鏈路冗余:單點故障不中斷服務

常用模式對比

配置示例: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
  • 建議配置後 重啟系統 而非僅重啟網絡服務,確保內核模塊正確加載
Copyright © Windows教程網 All Rights Reserved
Mode名稱特點交換機要求
0balance-rr輪詢負載均衡需配置靜態聚合
1active-backup主備故障轉移(推薦生產)無特殊要求
4802.3ad動態鏈路聚合 (LACP)需支持 LACP 配置
5balance-tlb適應性負載均衡無特殊要求
6balance-alb適應性負載均衡 + ARP 協商無特殊要求