歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> CentOS下雙網卡綁定

CentOS下雙網卡綁定

日期:2017/2/27 15:59:46   编辑:Linux教程
為了提供網絡的高可用性,我們可能需要將多塊網卡綁定成一塊虛擬網卡對外提供服務,這樣即使其中的一塊物理網卡出現故障,也不會導致連接中斷。多網卡綁定這個詞在不同的平台有不同叫法,在Linux下叫bonding,IBM稱為etherchanel,broadcom叫team,但是名字怎麼變,效果都是將兩塊或更多的網卡當做一塊網卡使用,在增加帶寬的同時也可以提高冗余性。比如我們在RHEL6下可以將eth0和eth1綁定成虛擬網卡bond0。

1、 添加虛擬網卡
# vim /etc/sysconfig/network-scripts/ifcfg-bond0
# cat /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.12.128
NETMASK=255.255.255.0
USERCTL=no

2、 配置本地網卡信息
# vim /etc/sysconfig/network-scripts/ifcfg-eth0
# vim /etc/sysconfig/network-scripts/ifcfg-eth1
# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
TYPE=Ethernet
BOOTPROTO=static
ONBOOT="yes"
MASTER=bond0
SLAVE=yes
USERCTL=no

# cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE="eth1"
TYPE=Ethernet
BOOTPROTO=static
ONBOOT="yes"
MASTER=bond0
SLAVE=yes
USERCTL=no

3、 模塊加載
# vim /etc/modprobe.d/dist.conf
# grep bond0 /etc/modprobe.d/dist.conf
alias bond0 bonding
options bond0 miimon=100 mode=1
//miimon是指多久時間要檢查網絡一次,單位是ms(毫秒)這邊的100,是100ms,即是0.1秒
//mode共有七種(0~6),這裡解釋兩個常用的選項。
Ø  mode=0:平衡負載模式,兩塊網卡都在工作。
Ø  mode=1:自動主備模式,其中一塊網卡在工作(若eth0斷掉),則自動切換到另一個塊網卡(eth1做備份)。

4、 重啟網絡服務,使配置生效
# service network restart
# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)
 
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
Speed: 100 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:45:bf:a0
Slave queue ID: 0
 
Slave Interface: eth1
MII Status: up
Speed: 100 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:45:bf:aa
Slave queue ID: 0

# route  -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.128.0   0.0.0.0         255.255.255.0   U     0      0        0 bond0
169.254.0.0     0.0.0.0         255.255.0.0     U     1004   0        0 bond0

# lsmod | grep bond
bonding               109558  0

5、 測試
選擇一台Linux機器ping測試機,然後停掉當前使用的網卡eth0,查看是否能夠繼續ping通
# ifdown eth0
# cat /proc/net/bonding/bond0
//發現此時激活的網卡為eth1了,如果測試可以ping通,則實驗完成
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth1
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth1
MII Status: up
Speed: 100 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:45:bf:aa
Slave queue ID: 0
Copyright © Linux教程網 All Rights Reserved