徐高翔的个人网站

linux双网卡绑定

2009-10-15

软硬件环境

  • centos

前言

bonding的作用是把多块网卡虚拟成一块网卡,使用一个IP地址,一个MAC地址。一般的发行版内核都支持bonding,如果碰到不支持的,重编下内核使其支持就可以了。

实践

1
2
cd /etc/sysconfig/network-scripts
cp ifcfg-eth0 ifcfg-bond0

编辑ifcfg-bond0

1
2
3
4
5
6
7
8
9
# Broadcom NetXtreme II BCM5708 Gigabit Ethernet       
DEVICE=bond0
BROADCAST=192.168.0.255
HWADDR=00:22:19:CD:CD:44
IPADDR=192.168.0.251
NETMASK=255.255.255.0
ONBOOT=yes
GATEWAY=192.168.0.1
TYPE=Ethernet

ifcfg-eth0配置文件

1
2
3
4
5
6
# Broadcom NetXtreme II BCM5708 Gigabit Ethernet       
DEVICE=eth0
HWADDR=00:1A:64:64:6C:C8
NETMASK=255.255.255.0
ONBOOT=yes
TYPE=Ethernet

ifcfg-eth1配置文件

1
2
3
4
5
6
# Broadcom NetXtreme II BCM5708 Gigabit Ethernet       
DEVICE=eth1
HWADDR=00:1A:64:64:6C:CA
NETMASK=255.255.255.0
ONBOOT=yes
TYPE=Ethernet

编辑/etc/modprobe.conf文件

1
2
3
4
5
alias bond0 bonding       
options bond0 miimon=100 mode=1
alias scsi_hostadapter mptbase
alias scsi_hostadapter1 mptscsih
options lnet networks=tcp0

开机启动编辑/etc/rc.local文件

1
2
modprobe bonding
ifenslave bond0 eth0 eth1

在主备模式下工作,会按照先后顺序提供网卡服务,这里是eth0然后是eth1,如果其中有一块网卡失效,网络也不会中断,这有点像RAID1的功能。一切设置完毕后,重启系统查看配置结果。

1
ifconfig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
bond0     Link encap:Ethernet  HWaddr 00:1A:64:64:6C:C8  
inet addr:192.168.0.251 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::21a:64ff:fe64:6cc8/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:17066 errors:0 dropped:0 overruns:0 frame:0
TX packets:105 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1118781 (1.0 MiB) TX bytes:21938 (21.4 KiB)

eth0 Link encap:Ethernet HWaddr 00:1A:64:64:6C:C8
inet6 addr: fe80::21a:64ff:fe64:6cc8/64 Scope:Link
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:8672 errors:0 dropped:0 overruns:0 frame:0
TX packets:89 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:568833 (555.5 KiB) TX bytes:17518 (17.1 KiB)
Interrupt:3 Memory:ce000000-ce012100

eth1 Link encap:Ethernet HWaddr 00:1A:64:64:6C:C8
inet6 addr: fe80::21a:64ff:fe64:6cc8/64 Scope:Link
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:8394 errors:0 dropped:0 overruns:0 frame:0
TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:549948 (537.0 KiB) TX bytes:4420 (4.3 KiB)
Interrupt:10 Memory:ca000000-ca012100

从上面的输出可以看到,bond0、eth0、eth1的HWaddr都是00:1A:64:64:6C:C8。

查看bonding的状态

1
cat /proc/net/bonding/bond0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Ethernet Channel Bonding Driver: v3.1.2 (January 20, 2007)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0
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: 0
Permanent HW addr: 00:1a:64:64:6c:c8

Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:1a:64:64:6c:ca

本文链接 https://xugaoxiang.com/2009/10/15/linux双网卡绑定/

推荐文章(由hexo文章推荐插件驱动)

使用支付宝打赏
使用微信打赏

请博主喝咖啡!