一:原理:
linux操作系統下雙網卡綁定有七種模式。現在一般的企業都會使用雙網卡接入,這樣既能添加網絡帶寬,同時又能做相應的冗余,可以說是好處多多。而一般企業都會使用linux操作系統下自帶的網卡綁定模式,當然現在網卡產商也會出一些針對windows操作系統網卡管理軟件來做網卡綁定(windows操作系統沒有網卡綁定功能 需要第三方支持)。
進入正題,linux有七種網卡綁定模式:
0. round robin;
1.active-backup;
2.load balancing (xor);
3.fault-tolerance (broadcast);
4.lacp;
5.transmit load balancing;
6.adaptive load balancing。
二、試驗一:redhat5(mode=1(active-backup):一個網卡處於活動狀態 ,一個處於備份狀態,所有流量都在主鏈路上處理。當活動網卡down掉時,啟用備份的網卡。)
1、編輯/etc/sysconfig/network-scripts/ifcfg-bond0文件,輸入如下指令:
[root@node1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
BOOTPROTO=none
OBBOOT=yes
IPADDR=192.168.100.126
NETMASK=255.255.255.0
TYPE=Ethernet
USERCTL=no
BONDING_OPTS="mode=1 miimon=100"
表示系統在啟動時加載bonding模塊,對外虛擬網絡接口設備為 bond0;miimon=100表示系統每100ms監測一次鏈路連接狀態,如果有一條線路不通就轉入另一條線路;mode=1表示fault-tolerance (active-backup)提供冗余功能,工作方式是主備的工作方式,也就是說默認情況下只有一塊網卡工作,另一塊做備份。 |
2、編輯/etc/sysconfig/network-scripts/ifcfg-eth0文件,輸入如下內容:
[root@node1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
MASTER=bond0
SLAVE=yes
3、編輯/etc/sysconfig/network-scripts/ifcfg-eth1文件,輸入如下內容:
[root@node1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
MASTER=bond0
SLAVE=yes
4、執行如下指令:
[root@node1 ~]# echo "alias bond0 bonding" >>/etc/modprobe.conf
5、生效bond0
[root@node1 ~]# modprobe bonding
三、試驗二:redhat6(mode=1(active-backup):一個網卡處於活動狀態 ,一個處於備份狀態,所有流量都在主鏈路上處理。當活動網卡down掉時,啟用備份的網卡。)
1、編輯/etc/sysconfig/network-scripts/ifcfg-bond0文件,輸入以下內容:
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.100.116
NETMASK=255.255.255.0
GATEWAY=192.168.100.1
TYPE=Ethernet
USERCTL=no
BONDING_OPTS="mode=1 miimon=100 primary=eth0"
2、編輯/etc/sysconfig/network-scripts/ifcfg-eth0文件,輸入以下內容:
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
MASTER=bond0
SLAVE=yes
3、編輯/etc/sysconfig/network-scripts/ifcfg-eth1文件,輸入以下內容
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
MASTER=bond0
SLAVE=yes
4、執行以下語句:
[root@localhost ~]# #echo "alias bond0 bonding" >>/etc/modprobe.d/dist.conf
[root@localhost ~]# #echo "options bond0 miimon=100 mode=0" >>/etc/modprobe.d/dist.conf
說明: |
5、關閉NetworkManager服務:
[root@localhost ~]# service NetworkManager status
NetworkManager is stopped
[root@localhost ~]# chkconfig NetworkManager off
[root@localhost ~]#
6、重啟電腦:
[root@localhost ~]# #init 6
7、ifconfig查看ip:
[root@localhost ~]# ifconfig bond0 Link encap:Ethernet HWaddr 00:50:56:80:2C:53 inet addr:192.168.100.116 Bcast:192.168.100.255 Mask:255.255.255.0 inet6 addr: fe80::250:56ff:fe80:2c53/64 Scope:Link UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1 RX packets:1741 errors:0 dropped:0 overruns:0 frame:0 TX packets:332 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:137206 (133.9 KiB) TX bytes:38181 (37.2 KiB) eth0 Link encap:Ethernet HWaddr 00:50:56:80:2C:53 UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1 RX packets:888 errors:0 dropped:0 overruns:0 frame:0 TX packets:332 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:69751 (68.1 KiB) TX bytes:38181 (37.2 KiB) eth1 Link encap:Ethernet HWaddr 00:50:56:80:2C:53 UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1 RX packets:853 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:67455 (65.8 KiB) TX bytes:0 (0.0 b) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:24827 errors:0 dropped:0 overruns:0 frame:0 TX packets:24827 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:7421150 (7.0 MiB) TX bytes:7421150 (7.0 MiB) virbr0 Link encap:Ethernet HWaddr 52:54:00:82:5F:52 inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) [root@localhost ~]# |
8、查看配置信息
[root@localhost ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: eth0 (primary_reselect always)
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: 10000 Mbps
Duplex: full
Link Failure Count: 1
Permanent HW addr: 00:50:56:80:2c:53
Slave queue ID: 0
Slave Interface: eth1
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 1
Permanent HW addr: 00:50:56:80:4c:54
Slave queue ID: 0