linux 双网卡绑定~

模式bond1: active-backup

模式的特点:一个端口处于主状态 ,一个处于从状态,所有流量都在主链路上处理,从不会有任何流量。当主端口down掉时,从端口接手主状态。

先停止NetworkManager
service NetworkManager stop 
chkconfig NetworkManager off   //开机自启动 关闭


在/etc/sysconfig/network-scripts/目录下建立ifcfg-bond0文件,文件内容如下:

DEVICE=bond0
USERCTL=no
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.100.17    //你所设置的IP
NETMASK=255.255.255.0
GATEWAY=192.168.100.1
TYPE=UnKnown    //或者Ethernet (若Networkmanager未关闭 就用unknown )
BONDING_OPTS="miimon=80 mode=0"   //这一步也可以在下面 /etc/modprobe.d/bonidng.conf 里面填写


绑定mode为0,是rond-robin模式。
然后分别修改ifcfg-eth0文件,如下:

DEVICE="eth0"
ONBOOT="yes"
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
USERCTL=no


在把ifcfg-eth1文件修改如下:

DEVICE="eth1"
ONBOOT="yes"
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
USERCTL=no

在/etc/modprobe.d/目录下建立bonding.conf文件,文件内容如下:
alias bond0 bonding

---若上一面bond0 配置未填写 BONDING_OPTS,这里再另起一行:options bond0 miimon=100 mode=0

执行

modprobe  bonding

然后重启网络

service network restart

-------如果用远程连接的话 请使用:modprobe bonding&&service network restart
之后就可以用ifconfig-a看到绑定好的bond0网卡,bond0与eth0,eth1的mac地址均为一样。
可以同过cat/proc/net/bonding/bond0 此命令查看绑定情况

网卡绑定解除:

删除ifcfg-bond0,和删除/etc/modprobe.d/bonding.conf

修改ifcfg-eth0和ifcfg-eth0为绑定之前的样子

rmmod bonding(很重要)

service network restart

注意事项:

1.Warning: the permanent HWaddr of eth0 - 00:0c:29:2d:4a:87 - is still in use by bond0. Set the HWaddr of eth0 to a different address to avoid conflicts.

  an:在网上查了下,很多人都说是VMware workstation的问题,实体机做没问题。具体原因不太清楚,我上网查的资料:http://blog.csdn.net/robertkun/article/details/16873961,不过我还没试。
最直接的解决办法:建议测试的时候不要用ifdown eth0来测试,而是在workstation右下角找到eth0网络适配器,右键断开连接。

2.为什么eth0修复后,bond0不返回eth0

3.

[root@nginx1 network-scripts]# cat ifcfg-bond0 
DEVICE=bond0
ONBOOT=yes
#双网卡IP
IPADDR=192.168.1.100
GATEWAY=192.168.1.1
NETMASK=255.255.255.0
#mode0代表Active-backup policy(主-备份策略)
BONDING_OPTS="miimon=80 mode=1"
[root@nginx1 network-scripts]# cat ifcfg-eth
cat: ifcfg-eth: No such file or directory
[root@nginx1 network-scripts]# cat ifcfg-eth0
DEVICE="eth0"
#IPADDR=192.168.1.200
#NM_CONTROLLED="yes"
ONBOOT="yes"
#NETMASK=255.255.255.0
#GATEWAY=192.168.1.1
MASTER=bond0
SLAVE=yes
TYPE="Ethernet"
UUID="a90ad08d-f6e9-4f34-94e3-690d44454e9e"
[root@nginx1 network-scripts]# cat ifcfg-eth1
DEVICE="eth1"
#IPADDR=192.168.174.200
#NM_CONTROLLED="yes"
ONBOOT="yes"
MASTER=bond0
SLAVE=yes
#NETMASK=255.255.255.0
#GATEWAY=192.168.1.1
#TYPE="Ethernet"
#UUID="a90ad08d-f6e9-4f34-94e3-690d44454e9e"

感谢:http://blog.csdn.net/yh10169658/article/details/52220582

原文地址:https://www.cnblogs.com/simplezy/p/6791308.html