RHEL5 双网卡绑定设置详解


由于市场上大多数服务器都标配2-4个网口,通常情况下只会采用其中一个,为了资源的充分利用及防止网卡故障,

推荐大家采用bonding技术,注意真实环境中交换机对应的两个网口也要做配置哦!


一、编辑虚拟网络接口配置文件,指定网卡信息

[root@crushlinux ~]# vi /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
BOOTPROTO=none      
BONBOOT=yes
IPADDR=192.168.1.254
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
NETWORK=192.168.1.0
USERCTL=no


二、配置真实网卡eth0,eth1

[root@crushlinux ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=yes
[root@crushlinux ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=yes

三、加载模块,让系统支持bonding

[root@crushlinux ~]# mv /etc/modprobe.conf /etc/modprobe.conf.bak
[root@crushlinux ~]# vi /etc/modprobe.conf
alias eth0 bnx2
alias eth1 bnx2
alias scsi_hostadapter aacraid
alias scsi_hostadapter1 ata_piix
alias bond0 bonding
options bond0 miimon=100 mode=1 primary=eth0

说明:

mode指定了bond0的工作模式,常用的是0和1,0表示负载均衡方式,1表示主备方式。

mode=0表示 load balancing (round-robin)为负载均衡方式,两块网卡都工作。

mode=1表示 fault-tolerance (active-backup)提供冗余功能,工作方式是主备方式,默认情况一块网卡工作,另一块做备份。


bonding只提供链路监测,从主机到交换机的链路是否接通。如果交换机对外的链路down掉了,

而交换机本身没有故障,那么bonding会认为链路没有问题而继续使用。


miimon是用来进行链路监测的。

比如:miimon=100,那么系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路。


四、增加开机启动脚本

[root@crushlinux ~]# vi /etc/rc.d/rc.local 末行加入
ifenslave bond0 eth0 eth1


五、重启网络服务

[root@crushlinux ~]# service network restart


六、测试

用另一台机器通过ping命令测试

[root@berg ~]# ifconfig eth0 192.168.1.253

[root@berg ~]# ping 192.168.1.254

如果不同对ifcfg-bond0进行排查,如果ping通就可测试双网卡绑定了,拔掉一根网线,还是通的为正确。

可将两块网卡网线全部拔掉进行测试,接上网线后稍等10~30秒,可继续ping通。