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

Linux 多網卡綁定模式:建立 Bonding 虛擬網卡實現高可用與負載均衡

編輯:關於 Linux

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

Linux 網卡綁定架構示意圖

前置條件

  • 兩張網卡晶片組型號相同,建議具備獨立 BIOS 晶片
  • 核心已編譯 bonding 模組(現代發行版預設皆已包含)

設定步驟

1. 建立虛擬介面設定檔

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

2. 修改實體網卡設定檔(移除 IP 相關設定)

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。

3. 載入 bonding 核心模組並指定模式

編輯 /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 指定偏好主網卡。

4. 開機自動載入模組

編輯 /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) 或上層應用層健康檢查。

Copyright © Windows教程網 All Rights Reserved