当前位置: > Linux发行版 > Debian >

Debian7 bonding配置详解

时间:2021-12-18 16:48来源:linux.it.net.cn 作者:IT

Linux双网卡绑定一个IP地址,实质工作就是使用两块网卡虚拟为一块,使用同一个IP地址,是我们能够得到更好的更快的服务。其实这项技术在Sun和Cisco中早已存在,被称为Trunking和Etherchannel技术,在Linux的2.4.x的内核中也采用这这种技术,被称为bonding。

bonding的原理

在正常情况下,网卡只接收目的硬件地址(MAC Address)是自身Mac的以太网帧,对于别的数据帧都过滤掉,以减轻驱动程序的负担。

但是网卡也支持另外一种被称为混杂的模式,可以接收网络上所有的帧,比如说很多用抓包工具就需要让网卡运行在这个模式下。

bonding也运行在这个混杂模式下,而且修改了驱动程序中的MAC地址,将两块网卡的MAC地址改成相同,可以接收特定MAC的数据帧。然后把相应的数据帧传送给bond驱动程序处理。

bonding模块工作方式

bonding有0-6七种模式,常用的工作方式为0、1、6三种:

mode=0:表示load balancing(round-robin)为负载均衡模式(两块网卡都要工作),但需要交换机支持并需要在交换机上进行相应配置。
mode=1:表示fault-tolerance(active-backup)提供冗余功能,工作方式是主辅的方式,也就是说默认情况下只有一块网卡工作,另一块做备份。
mode=6:表示load balancing(round-robin)为负载均衡模式(两块网卡都要工作),不需要交换机支持。

bonding配置

使用如下命令安装bonding。

apt-get install ifenslave

使用如下命令让系统开机自动加载模块bonding。

sh -c "echo bonding mode=6 miimon=100 >> /etc/modules"

其中miimon参数是用于进行链路监测的。比如:miimon=100,那么系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路;mode的值表示bonding工作模式。

修改/etc/network/interfaces文件为如下内容。

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.1.20
netmask 255.255.255.0

auto eth1
iface eth1 inet static
address 192.168.1.30
netmask 255.255.255.0

auto bond0
iface bond0 inet static  # 虚拟网卡的TCP/IP配置
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 192.168.1.1
post-up ifenslave bond0 eth0 eth1
pre-down ifenslave -d bond0 eth0 eth1

如果在安装ifenslave后没有重新启动计算机,必须手动加载bonding模块。

modprobe bonding mode=6 miimon=100

使用如下命令重新启动网卡。

/etc/init.d/networking restart

虚拟网卡绑定虚拟网桥配置

auto br0
iface br0 inet static
bridge_ports bond0
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1

auto bond0
iface bond0 inet manual
up ip address add 0/0 dev $IFACE
up ip link set $IFACE up
down ip link set $IFACE down
post-up ifenslave bond0 eth0 eth1
pre-down ifenslave -d bond0 eth0 eth1


(责任编辑:IT)
------分隔线----------------------------