Linux双网卡绑定是通过bonding技术实现使用两块网卡成为一块网卡设备,两块网卡共用一个IP,可实现负载均衡,网卡冗余。前提是bonding使用相同型号的网卡芯片
通过以下命令查看是否支持bonding,默认redhat5.x已支持
#modinfo bonding
filename: /lib/modules/2.6.18-164.el5/kernel/drivers/net/bonding/bonding.ko
author: Thomas Davis, tadavis@lbl.gov and many others
description: Ethernet Channel Bonding Driver, v3.4.0
version: 3.4.0
#cd /etc/sysconfig/network-scripts/
#cp ifcfg-lo ifcfg-bond0
#vi ifcfg-bond0
DEVICE=bond0
IPADDR=192.168.0.15
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
ONBOOT=yes
USERCTL=no
BOOTPROTO=none
#vi ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
HWADDR=00:0C:29:23:38:03
ONBOOT=yes
MASTER=bond0
SLAVE=yes
#vi ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none
HWADDR=00:0C:29:23:38:0D
ONBOOT=yes
MASTER=bond0
SLAVE=yes
#vi /etc/modprobe.conf
末行添加
alias bond0 bonding
options bond0 miimon=100 mode=1
BONDING_OPTS选项中的mode=0指的是使用指负载均衡模式,如果这个参数为1,表示冗余功能。miimon=100表示系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路。
#/etc/init.d/network restart
#ifconfig
bond0 Link encap:Ethernet HWaddr 00:0C:29:41:E1:48
inet addr:192.168.0.254 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe41:e148/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:2913 errors:0 dropped:0 overruns:0 frame:0
TX packets:2338 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:274948 (268.5 KiB) TX bytes:357004 (348.6 KiB)
eth0 Link encap:Ethernet HWaddr 00:0C:29:41:E1:48
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:2289 errors:0 dropped:0 overruns:0 frame:0
TX packets:2176 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:209531 (204.6 KiB) TX bytes:326498 (318.8 KiB)
Interrupt:59 Base address:0x2024
eth1 Link encap:Ethernet HWaddr 00:0C:29:41:E1:48
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
#cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)
Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
MII Status: up
Link Failure Count: 1
Permanent HW addr: 00:0c:29:41:e1:48
Slave Interface: eth1
MII Status: up
Link Failure Count: 1
Permanent HW addr: 00:0c:29:41:e1:52
通过bonding技术实现网卡负载均衡模式就可以了