linux双网卡绑定同一IP步骤,linux系统双网卡绑定单个IP地址
雙網(wǎng)卡綁定單個IP地址為了提供網(wǎng)絡(luò)的高可用性,我們可能需要將多塊網(wǎng)卡綁定成一塊虛擬網(wǎng)卡對外提供服務(wù),這樣即使其中的一塊物理網(wǎng)卡出現(xiàn)故障,也不會導致連接中斷。多網(wǎng)卡綁。
為了提供網(wǎng)絡(luò)的高可用性,我們可能需要將多塊網(wǎng)卡綁定成一塊虛擬網(wǎng)卡對外提供服務(wù),這樣即使其中的一塊物理網(wǎng)卡出現(xiàn)故障,也不會導致連接中斷。在Linux下叫bonding,IBM稱為etherchanel,broadcom叫team,但是名字怎么變,效果都是將兩塊或更多的網(wǎng)卡當做一塊網(wǎng)卡使用,在增加帶寬的同時也可以提高冗余性。比如我們在CentOS 6.3下可以將eth0和eth1綁定成虛擬網(wǎng)卡bond0。
如圖:
實驗配置:
mode=1:表示fault-tolerance (active-backup)提供冗余功能,工作方式是主備的工作方式,其中一塊網(wǎng)卡在工作(若eth0斷掉),則自動切換到另一個塊網(wǎng)卡(eth1做備份)。
系 統(tǒng)設(shè)備名稱IP地址子網(wǎng)掩碼
CentOS 6.3_64biteth0
eth1
bond010.1.3.210255.255.255.0
1、查看主機網(wǎng)卡
[root@web ~]# cd /etc/sysconfig/network-scripts/
[root@web1 network-scripts]# ll
total 200
-rw-r--r--. 1 root root?? 212 Mar 20 22:15 ifcfg-eth0
-rw-r--r--? 1 root root?? 212 Mar 23 19:10 ifcfg-eth1
2、復制ifcfg-bond0
[root@web network-scripts]# cp ifcfg-eth0 ifcfg-bond0
[root@web network-scripts]# ll
total 204
-rw-r--r--? 1 root root?? 212 Mar 23 19:12 ifcfg-bond0
-rw-r--r--. 1 root root?? 212 Mar 20 22:15 ifcfg-eth0
-rw-r--r--? 1 root root?? 212 Mar 23 19:10 ifcfg-eth1
3、編輯ifcfg-bond0、ifcfg-eth0、ifcfg-eth1
[root@web network-scripts]# vim ifcfg-bond0
DEVICE=bond0
BOOTPROTO=static
IPADDR=10.1.3.210
NETMASK=255.255.255.0
GATEWAY=10.1.3.254
ONBOOT=yes
USERCTL=no
[root@web1 network-scripts]# vim ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
USERCTL=no
[root@web1 network-scripts]# vim ifcfg-eth1
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
USERCTL=no
4、模塊加載
[root@web1 ~]# vim /etc/modprobe.d/dist.conf
在最后添加以下內(nèi)容:
#加載bonding模塊,對外虛擬網(wǎng)絡(luò)接口設(shè)備為bond0
alias bond0 bonding
options bond0 miimon=100 mode=1
[root@web1 ~]# grep bond0 /etc/modprobe.d/dist.conf
alias bond0 bonding
options bond0 miimon=100 mode=1
說明:
miimon是用來進行鏈路監(jiān)測的。比如:miimon=100,單位是ms(毫秒)這邊的100,是100ms,即是0.1秒那么系統(tǒng)每100ms監(jiān)測一次鏈路連接狀態(tài),如果有一條線路不通就轉(zhuǎn)入另一條線路;mode的值表示工作模式,他共有0,1,2,3四種模式,常用的為0、1兩種。
mode共有七種(0~6),這里解釋兩個常用的選項。
mode=0:表示load balancing (round-robin)為負載均衡方式,兩塊網(wǎng)卡都在工作。
mode=1:表示fault-tolerance (active-backup)提供冗余功能,工作方式是主備的工作方式,其中一塊網(wǎng)卡在工作(若eth0斷掉),則自動切換到另一個塊網(wǎng)卡(eth1做備份)。
bonding只能提供鏈路監(jiān)測,即從主機到交換機的鏈路是否接通。如果只是交換機對外的鏈路down掉了,而交換機本身并沒有故障,那么bonding會認為鏈路沒有問題而繼續(xù)使用。
5、重啟網(wǎng)絡(luò)服務(wù),使配置生效
[root@web1 ~]# service network restart
Shutting down interface eth0:????????????????????????????? [?OK?]
Shutting down interface eth1:????????????????????????????? [??OK? ]
Shutting down loopback interface:??????????????????????? ???[??OK? ]
Bringing up loopback interface:???????????????????? ????????[?OK?]
Bringing up interface bond0:? RTNETLINK answers: File exists
Error adding address 10.1.3.210 for bond0.
RTNETLINK answers: File exists????????????? ????????????????[?OK? ]
6、查看bond0接口狀態(tài)
[root@web1 ~]# 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?????? // eth0主模式
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:c9:6d:18
Slave queue ID: 0
Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:c9:6d:22
Slave queue ID: 0
7、查看中路由表狀態(tài):
[root@web1 ~]#? route? -n
Kernel IP routing table
Destination???? Gateway???????? Genmask???????? Flags Metric Ref??? Use Iface
10.1.3.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
0.0.0.0???????? 10.1.3.254????? 0.0.0.0???????? UG??? 0????? 0??????? 0 bond0
[root@web1 ~]# lsmod | grep bond
bonding?????????????? 127060? 0
8、測試
選擇一臺windows 7機器ping測試機,然后停掉當前使用的網(wǎng)卡eth0,查看是否能夠繼續(xù)ping通;
測試結(jié)果:
丟失一個包。
查看bond0接口狀態(tài)
[root@web1 ~]#?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:?eth1????? //eth1為主模式
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
MII Status: down
Speed: Unknown
Duplex: Unknown
Link Failure Count: 1
Permanent HW addr: 00:0c:29:c9:6d:18
Slave queue ID: 0
Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 1
Permanent HW addr: 00:0c:29:c9:6d:22
Slave queue ID: 0
總結(jié)
以上是生活随笔為你收集整理的linux双网卡绑定同一IP步骤,linux系统双网卡绑定单个IP地址的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一份从 0 到 1 的 Java 项目实
- 下一篇: linux怎样服务,如何在linux添加