Linux双网卡绑定配置小结_linux双网卡绑定实现
Linux双网卡绑定配置小结由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“linux双网卡绑定实现”。
Linux双网卡绑定配置小结
By Lu Liujun 2011.07.20
一、双网卡绑定说明
双网卡虚拟为一块网卡,作为安全备份或者负荷分担,在linux中这种技术称为bonding,这时候网卡运行在混杂模式(promisc)下。
二、绑定实现的前提
1、芯片组相同、网卡具备自己独立的BIOS2、linux支持绑定,RHEL4已经默认支持
可以用如下命令检查是否已经支持: modinfo bonding
Lab-COM:root # modinfo bonding filename:
/lib/modules/2.6.18-238.1.1.el5/kernel/drivers/net/bonding/bonding.ko author:
Thomas Davis, tadavis@lbl.gov and many others description:
Ethernet Channel Bonding Driver, v3.4.0-1 version:
3.4.0-1 license:
GPL srcversion:
956FDE3FEBDD81E105B7727 depends:
ipv6 vermagic:
2.6.18-238.1.1.el5 SMP mod_unload gcc-4.1 如果有以上信息说明系统已经支持bonding了。
三、配置bonding参数
1、配置/etc/sysconfig/network-scripts/ifcfg-bond0 内容如下:
Lab-COM:root # more /etc/sysconfig/network-scripts/ifcfg-bond0 # Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet DEVICE=bond0 BOOTPROTO=none BROADCAST=10.0.1.127 USERCTL=no IPADDR=10.0.1.118 NETMASK=255.255.255.128 NETWORK=10.0.1.0 ONBOOT=yes
上海配置如下:
COM1:root # more ifcfg-bond0
# Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet
DEVICE=bond0
BOOTPROTO=none
BROADCAST=4.4.5.191
USERCTL=no
BONDING_OPTS=“max_bonds=4 miimon=100 mode=1”
IPADDR=4.4.5.132
NETMASK=255.255.255.192
NETWORK=4.4.5.128
ONBOOT=yes
GATEWAY=4.4.5.129
2、配置/etc/sysconfig/network-scripts/ifcfg-eth0 内容如下:
# Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet DEVICE=eth0 BOOTPROTO=none ONBOOT=yes USERCTL=no MASTER=bond0 SLAVE=yes
上海配置如下:
COM1:root # more ifcfg-eth0
# Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
MASTER=bond0
SLAVE=yes3、配置配置/etc/sysconfig/network-scripts/ifcfg-eth1 内容如下:
Lab-COM:root # more /etc/sysconfig/network-scripts/ifcfg-eth1 # Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet DEVICE=eth1 BOOTPROTO=none ONBOOT=yes USERCTL=no MASTER=bond0 SLAVE=yes
除DEVICE,eth0和eth1的内容应该是一样的。
4、配置/etc/modprobe.conf 内容如下:
Lab-COM:root # more /etc/modprobe.conf alias eth0 bnx2 alias eth1 bnx2 alias eth2 bnx2 alias eth3 bnx2 alias eth4 e1000e alias eth5 e1000e alias scsi_hostadapter cci alias scsi_hostadapter1 ata_piix alias bond0 bonding options bond0 miimon=100 mode=1 红色字体为新增部分,其中miimon是链路监测时间,100是100ms,mode有0、1、2、3四种常用的是0和1,0为load-balancing(round-robin)负载均衡模式,1为fault-tolerance(active-backup)冗余模式,为主备方式。
上海电信的配置如下:
COM1:root # more modprobe.conf
alias eth0 bnx2
alias eth1 bnx2
alias eth2 bnx2
alias eth3 bnx2
alias eth4 e1000e
alias eth5 e1000e
alias eth6 e1000e
alias eth7 e1000e
alias scsi_hostadapter cci
alias scsi_hostadapter1 ata_piix
alias bond0 bonding
alias bond1 bonding
alias bond2 bonding
alias bond3 bonding
5、配置/etc/rc.d/rc.local
内容如下:
Lab-COM:root # more /etc/rc.d/rc.local #!/bin/sh # # This script will be executed *after* all the other init scripts.# You can put your own initialization stuff in here if you don't # want to do the full Sys V style init stuff.touch /var/lock/subsys/local ifenslave bond0 eth0 eth1 红色字体为新增部分。
上海电信的配置如下:
COM1:root # more rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.touch /var/lock/subsys/local
6、重启网络
修改好以上配置,并做确认,然后重启网络,运行如下命令: service network restart 重启后可以看到bond0已经起来了
7、运行ifconfig查看网络状态
结果如下:
Lab-COM:root # ifconfig bond0
Link encap:Ethernet HWaddr 00:26:55:4F:B5:FE
inet addr:10.0.1.118 Bcast:10.0.1.127 Mask:255.255.255.128
inet6 addr: fe80::226:55ff:fe4f:b5fe/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:38122 errors:0 dropped:0 overruns:0 frame:0
TX packets:730 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2555936(2.4 MiB)TX bytes:104835(102.3 KiB)
eth0
Link encap:Ethernet HWaddr 00:26:55:4F:B5:FE
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:38122 errors:0 dropped:0 overruns:0 frame:0
TX packets:730 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2555936(2.4 MiB)TX bytes:104835(102.3 KiB)
Interrupt:169 Memory:f4000000-f4012800
eth1
Link encap:Ethernet HWaddr 00:26:55:4F:B5:FE
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:154 Memory:f2000000-f2012800 可以看到两个网卡的mac已经一样了。由于机房的机器只连了一根网线,可以看到bond0上的ip包的数目和eth0的ip包的数目一样。
8、确认网络连通
ping其他地址,并在其他设备上ping本设备,如果都连通,说明配置正确。
四、配置过程遇到的问题
1、配置好所有相关的文件,重启网络后,发现网络不通
重启网络后,ping其他设备不通,其他设备也ping不通本地,报如下错误: ping: sendmsg: Operation not permitted 主要原因是系统打开了iptables,限制了出去的数据,修改iptables的配置后,网络连通正常。
如果是先安装了oracle和COM application然后再做的bonding,那需要运行如下命令更新系统的iptables配置:
/install/scripts/firewall-install.sh
五、适用版本
适用Linux版本是: Lab-COM:root # uname-a Linux Lab-COM 2.6.18-238.1.1.el5 #1 SMP Tue Jan 4 13:32:19 EST 2011 x86_64 x86_64 x86_64 GNU/Linux