日期:2014-05-16  浏览次数:20764 次

Linux 下 网卡绑定ip

一、多网卡绑定1个ip

1. 新建ifcfg-bond0

[root@dex network-scripts]# cd /etc/sysconfig/network-scripts/
[root@dex network-scripts]# cp ifcfg-eth0 ifcfg-bond0
[root@dex network-scripts]# vi ifcfg-bond0 
加入如下内容
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=bond0
BOOTPROTO=none
BROADCAST=192.168.100.255
IPADDR=192.168.100.12
NETMASK=255.255.255.0
NETWORK=192.168.100.0
ONBOOT=yes
2. 修改ifcfg-eth0 ifcfg-eth1
[root@dex network-scripts]# vi ifcfg-eth0
修改为如下内容
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
[root@dex network-scripts]# cp ifcfg-eth0 ifcfg-eth1
[root@dex network-scripts]# vi ifcfg-eth1
修改为如下内容
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
3. 修改/etc/modprobe.conf文件
[root@dex network-scripts]# vi /etc/modprobe.conf
加入如下两行
alias bond0 bonding
options bond0 miimon=100 mode=1




mode=0 表示两块网卡同时工作,提供负载均衡
mode=1 表示提供冗余功能(主备模式)


4. 重启服务
[root@dex network-scripts]# service network restart
查看一下
[root@dex network-scripts]# ifconfig -a
bond0     Link encap:Ethernet  HWaddr 00:0C:29:AE:CF:7F  
          inet addr:192.168.100.12  Bcast:192.168.100.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
          RX packets:3396 errors:0 dropped:0 overruns:0 frame:0
          TX packets:753 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:237786 (232.2 KiB)  TX bytes:86115 (84.0 KiB)


eth0      Link encap:Ethernet  HWaddr 00:0C:29:AE:CF:7F  
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:1201 errors:0 dropped:0 overruns:0 frame:0
          TX packets:694 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:76776 (74.9 KiB)  TX bytes:79243 (77.3 KiB)


eth1      Link encap:Ethernet  HWaddr 00:0C:29:AE:CF:7F  
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:2195 errors:0 dropped:0 overruns:0 frame:0
          TX packets:59 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:161010 (157.2 KiB)  TX bytes:6872 (6.7 KiB)


lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:2045 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2045 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:3201608 (3.0 MiB)  TX bytes:3201608 (3.0 MiB)
绑定结束




尝试着拔掉一个网线,看看结果怎样。