伺服器安裝多張網卡(如內建 2 埠 + 擴充卡 2 埠)時,核心偵測順序可能導致 eth0/eth1 指派與預期不符。本文說明透過修改模組別名、互換 ifcfg 設定檔、重載模組的完整流程,將擴充卡固定為 eth0/eth1。

e1000e(期望命名為 eth2/eth3)e1000e(同驅動,期望命名為 eth0/eth1)eth2/eth3/etc/modprobe.conf# 原設定(核心依載入順序指派 eth0/eth1)
alias eth0 e1000e
alias eth1 e1000e
# 修改為:將內建網卡固定為 eth2/eth3
alias eth2 e1000e
alias eth3 e1000e
⚠️ 若系統使用 /etc/modprobe.d/ 目錄,請改編輯 /etc/modprobe.d/eth.conf 或類似檔案。
cd /etc/sysconfig/network-scripts/
# 使用暫存檔名避免覆蓋
mv ifcfg-eth0 ifcfg-temp0
mv ifcfg-eth2 ifcfg-temp2
mv ifcfg-temp2 ifcfg-eth0
mv ifcfg-temp0 ifcfg-eth2
# 同樣處理 eth1/eth3
mv ifcfg-eth1 ifcfg-temp1
mv ifcfg-eth3 ifcfg-temp3
mv ifcfg-temp3 ifcfg-eth1
mv ifcfg-temp1 ifcfg-eth3
編輯各 ifcfg-ethX,確保 DEVICE=ethX 與檔名一致:
# ifcfg-eth0
DEVICE=eth0
HWADDR=00:11:22:33:44:55 # 對應擴充卡 MAC
# ifcfg-eth2
DEVICE=eth2
HWADDR=AA:BB:CC:DD:EE:FF # 對應內建卡 MAC
modprobe -r e1000e # 先卸載
modprobe e1000e # 重新載入,依新別名指派 eth2/eth3
# 嘗試重啟網路
/etc/init.d/network restart
# 若不生效,需重開機
reboot
ifconfig -a
# 確認 eth0/eth1 對應擴充卡 MAC,且狀態 RUNNING
# 確認 eth2/eth3 對應內建卡 MAC
RedHat 7 / CentOS 7 以降建議使用 udev 規則綁定 MAC 至介面名稱:
# /etc/udev/rules.d/70-persistent-net.rules
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:11:22:33:44:55", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="AA:BB:CC:DD:EE:FF", NAME="eth2"
優點:不依賴模組載入順序,直接綁定硬體 MAC,更穩健。
/etc/sysconfig/network-scripts/ 整個目錄HWADDR (MAC) 是唯一可靠識別依據透過模組別名與設定檔互換,可在舊版 Linux 固定多網卡命名;新版系統請優先採用 udev 規則。