网卡绑定可以将多块网卡虚拟成一块网卡,聚合起来工作。网卡绑定需要网卡工作在混杂promisc模
式,并且需要将两块网卡的mac地址改成相同。
1,配置bond0
# vi ifcfg-bond0
DEVICE=bond0
TYPE=Ethernet
ONBOOT=yes
DELAY=0
BOOTPROTO=static
IPADDR=192.168.1.20
NETMASK=255.255.255.0
2,配置网卡加入bond0
# vi ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
MASTER=bond0
SLAVE=yes
# vi ifcfg-eth2
DEVICE=eth2
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
MASTER=bond0
SLAVE=yes
# vi ifcfg-eth3
DEVICE=eth3
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
MASTER=bond0
SLAVE=yes
3,在/etc/modules.conf文件中添加如下内容(如果没有该文件,则新建一个):
alias bond0 bonding
options bond0 miimon=100 mode=0 primary=eth1
其中miimon=100表示每100ms检查一次链路连接状态,如果不通则会切换物理网卡
mode=1表示主备模式,也就是只有一块网卡是active的,只提供失效保护。如果mode=0则是负载均
衡模式的,所有的网卡都是active,还有其他一些模式很少用到
primary=eth1表示主备模式下eth1为默认的active网卡
4,最后,在/etc/rc.local中加入
modprobe bonding miimon=100 mode=1
重起系统即可生效
5,也可直接执行
#modprobe bonding miimon=100 mode=1
之后
# ifconfig
bond0 Link encap:Ethernet HWaddr 84:2B:2B:15:4D:BA
inet addr:192.168.1.20 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST MASTER 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)
eth1 Link encap:Ethernet HWaddr 84:2B:2B:15:4D:BA
UP BROADCAST SLAVE 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:114 Memory:d8000000-d8012800
eth2 Link encap:Ethernet HWaddr 84:2B:2B:15:4D:BA
UP BROADCAST SLAVE 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:122 Memory:da000000-da012800
eth3 Link encap:Ethernet HWaddr 84:2B:2B:15:4D:BA
UP BROADCAST SLAVE 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:130 Memory:dc000000-dc012800
6,加bond0到桥
虚拟化环境中经常需要把网卡加到网桥上
# vi ifcfg-virbr1
DEVICE=virbr1
TYPE=Bridge
ONBOOT=yes
DELAY=0
BOOTPROTO=static
IPADDR=192.168.1.20
NETMASK=255.255.255.0
# vi /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
ONBOOT=yes
BRIDGE=virbr1