Linux 双网卡绑定

1.检查kernel 看是否支持绑定

 

[root@Nms ~]# cat /boot/config-2.6.18-164.el5 | grep -i bonding

CO-NFIG_BONDING=m  表示支持,否则需要编译内核使它支持bonding

 

2.将eth0 和eth2 两块网卡绑定在一起。

 

1>.建立网卡绑定的配置文件内容如下:

   [root@Nms ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0 

   DEVICE=bond0 《绑定设备名称》

   BONDING_OPTS="mode=1 miimon=100"

    《mode为0是绑定的两块网卡负载均衡模式实现,两块网卡同时工作一块网卡宕掉,另一个继续工作。查阅相关文献有少量丢包现象。

Mode 为1是绑定的两块网卡以主备模式实现,只有一块网卡工作,当主网卡宕掉之后,备用网卡立刻接管

Mode为0、2、3、4需要交换机做相应配置,mode为1、5、6不需交换机特别配置》

   BOOTPROTO=none

   ONBOOT=yes

   NETWORK=10.10.13.0

   NETMASK=255.255.255.192

   IPADDR=10.10.13.27

   USERCTL=yes《允许非root用户控制设备》

           GATEWAY=10.10.13.48

   TYPE=Ethernet

      IPV6INIT=no

 

2>.分别在两块网卡的配置文件添加字段见红色部分

   Eth0:[root@Nms ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 

   # NetXen Incorporated NX3031 Multifunction 1/10-Gigabit Server Adapter

   DEVICE=eth0

   BOOTPROTO=none

   ONBOOT=yes

   MASTER=bond0

   SLAVE=yes

   USERCTL=no

   TYPE=Ethernet

      IPV6INIT=no

  

   Eth2:[root@Nms ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth2

   # NetXen Incorporated NX3031 Multifunction 1/10-Gigabit Server Adapter

   DEVICE=eth2

   BOOTPROTO=none

   ONBOOT=yes

   TYPE=Ethernet

   MASTER=bond0

   SLAVE=yes

   USERCTL=no

      IPV6INIT=no

  

3添加alias bond0 bonding 

 

[root@Nms ~]# vi /etc/modules.conf 
添加: alias bond0 bonding  
[root@Nms ~]# vi /etc/rc.local
添加:   ifenslave bond0 eth2 eth0

 

 备注:ifenslave一定要加,解决可能在虚拟机中安装正确正常使用,但是在实体机器中无法工作的问题

 

4.重启网络服务:

 

/etc/init.d/network restart 或者service network restart

 

5.检查网卡绑定情况

 

    . [root@Nms ~]# ifconfig 

    bond0     Link encap:Ethernet  HWaddr 3C:4A:92:E4:AC:14  

              inet addr:10.10.13.27  Bcast:10.10.13.63  Mask:255.255.255.192

              inet6 addr: fe80::3e4a:92ff:fee4:ac14/64 Scope:Link

              UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1

              RX packets:1013027 errors:0 dropped:0 overruns:0 frame:0

              TX packets:577741 errors:0 dropped:0 overruns:0 carrier:0

              collisions:0 txqueuelen:0 

              RX bytes:165151585 (157.5 MiB)  TX bytes:96743546 (92.2 MiB)

    

    eth0      Link encap:Ethernet  HWaddr 3C:4A:92:E4:AC:14  

              UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1

              RX packets:1007793 errors:0 dropped:0 overruns:0 frame:0

              TX packets:577743 errors:0 dropped:0 overruns:0 carrier:0

              collisions:0 txqueuelen:1000 

              RX bytes:164837761 (157.2 MiB)  TX bytes:96744064 (92.2 MiB)

              Interrupt:178 

    

    eth1      Link encap:Ethernet  HWaddr 3C:4A:92:E4:AC:15  

              UP BROADCAST 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:1000 

              RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

              Interrupt:186 

    

    eth2      Link encap:Ethernet  HWaddr 3C:4A:92:E4:AC:14  

              UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1

              RX packets:5234 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:313824 (306.4 KiB)  TX bytes:0 (0.0 b)

              Interrupt:194 

    

    eth3      Link encap:Ethernet  HWaddr 3C:4A:92:E4:AC:17  

              inet addr:192.168.100.13  Bcast:192.168.100.255  Mask:255.255.255.0

              inet6 addr: fe80::3e4a:92ff:fee4:ac17/64 Scope:Link

              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

              RX packets:5852 errors:0 dropped:0 overruns:0 frame:0

              TX packets:76 errors:0 dropped:0 overruns:0 carrier:0

              collisions:0 txqueuelen:1000 

              RX bytes:402095 (392.6 KiB)  TX bytes:9661 (9.4 KiB)

              Interrupt:202 

    

    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:7300 errors:0 dropped:0 overruns:0 frame:0

              TX packets:7300 errors:0 dropped:0 overruns:0 carrier:0

              collisions:0 txqueuelen:0 

              RX bytes:4411678 (4.2 MiB)  TX bytes:4411678 (4.2 MiB)

 

6.查看双网卡现在工作在那块网卡上

 

此次绑定模式为主备绑定(mode=1),通过cat /proc/net/bonding/bond0可以看到绑定现在工作在eth0上,当停止eth0网卡,绑定不受影响,eth2代替eth0说明绑定成功。详见下面:

    [root@localhost ~]# cat /proc/net/bonding/bond0 

    Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)

    

    Bonding Mode: fault-tolerance (active-backup)

    Primary Slave: None

    Currently Active Slave: eth0《bond工作在eth0 网卡上》

    MII Status: up

    MII Polling Interval (ms): 100

    Up Delay (ms): 0

    Down Delay (ms): 0

    

    Slave Interface: eth0《eth0启动正常》

    MII Status: up

    Link Failure Count: 3

    Permanent HW addr: 00:08:02:ed:6e:4f

    

    Slave Interface: eth2《eth2启动正常》

    MII Status: up

    Link Failure Count: 1

    Permanent HW addr: 00:02:a5:44:e0:41

 

    [root@localhost ~]# ifconfig eth0 down             《停掉eth0网卡》

    [root@localhost ~]# cat /proc/net/bonding/bond0 

    Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)

    

    Bonding Mode: fault-tolerance (active-backup)

    Primary Slave: None

    Currently Active Slave: eth2《eth2代替eth0工作》

    MII Status: up

    MII Polling Interval (ms): 100

    Up Delay (ms): 0

    Down Delay (ms): 0

    

    Slave Interface: eth0《etho网卡停止工作》

    MII Status: down

    Link Failure Count: 4

    Permanent HW addr: 00:08:02:ed:6e:4f

    

    Slave Interface: eth2

    MII Status: up

    Link Failure Count: 1

    Permanent HW addr: 00:02:a5:44:e0:41

    [root@localhost ~]# ifconfig eth0 up

你可能感兴趣的:(linux)