[记录]Ubuntu 双网卡绑定(bond)设置方法

这是最近碰到这个问题,需要将两张网卡绑定,共用一个IP,实现冗余效果。实际上linux双网卡的绑定模式有7中,而在这里常用的是 active-backup

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

linux下网卡绑定的7种模式:

mode=0 表示 load balancing (round-robin)为负载均衡方式,两块网卡都工作。 mode=1 表示 fault-tolerance (active-backup)提供冗余功能,工作方式是主 从的工作方式,也就是说默认情况下只有一块网卡工作,另一块做备份。  mode=2 表示 XOR policy 为平衡策略。此模式提供负载平衡和容错能力  mode=3 表示 broadcast 为广播策略。此模式提供了容错能力  mode=4 表示 IEEE 802.3ad Dynamic link aggregation 为 IEEE 802.3ad 为 动态链接聚合。该策略可以通过 xmit_hash_policy 选项从缺省的 XOR 策略改变到其他策略。  mode=5 表示 Adaptive transmit load balancing 为适配器传输负载均衡。该 模式的必要条件:ethtool 支持获取每个 slave 的速率  mode=6 表示 Adaptive load balancing 为适配器适应性负载均衡。该模式包含 了 balance-tlb 模式,同时加上针对 IPV4 流量的接收负载均衡(receive load   balance, rlb),而且不需要任何 switch(交换机)的支持。 

操作步骤

1,安装基础bond组件

sudo apt-get install ifenslave

安装时若提示找不到包,需要执行 apt-get update2,编辑modules 文件:

vi /etc/modules

在该文件中加入以下内容:

bonding mode=1 miimon=100

其中mode为上面介绍的模式,这里为1,miimon是用来进行链路监测的。比如:miimon=100,那么系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路;3,网卡配置信息

vi /etc/network/interfaces

加入以下内容:

auto bond0iface bond0 inet staticaddress 192.168.2.3netmask 255.255.255.0gateway 192.168.2.1post-up ifenslave bond0 eth0 eth1pre-down ifenslave -d bond0 eth0 eth1

4,重启服务器

shutdown -r now

重启后测试有效,可拔掉某一网线测试。

如果是多个bond?

如果是多个bond,如:eth0 和 eth1 做一个bond0eth1 和 eth2 做一个bond1

那么需要将 /etc/modules 中的内容改为:

bonding mode=1 miimon=100 max_bonds=2

也就是在原有基础上加一个 max_bonds=2 。

网卡配置部分与bond0 的相同,只不过将配置中的eth0和eth1改为 eth2和eth3.

完。

[记录]Ubuntu 双网卡绑定(bond)设置方法

相关文章:

你感兴趣的文章:

标签云: