linux双网卡绑定

/

软硬件环境

  • centos

前言

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

实践

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

编辑ifcfg-bond0

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

ifcfg-eth0配置文件

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

ifcfg-eth1配置文件

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

编辑/etc/modprobe.conf文件

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

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

  1. modprobe bonding
  2. ifenslave bond0 eth0 eth1

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

  1. ifconfig
  1. bond0 Link encap:Ethernet HWaddr 00:1A:64:64:6C:C8
  2. inet addr:192.168.0.251 Bcast:192.168.0.255 Mask:255.255.255.0
  3. inet6 addr: fe80::21a:64ff:fe64:6cc8/64 Scope:Link
  4. UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
  5. RX packets:17066 errors:0 dropped:0 overruns:0 frame:0
  6. TX packets:105 errors:0 dropped:0 overruns:0 carrier:0
  7. collisions:0 txqueuelen:0
  8. RX bytes:1118781 (1.0 MiB) TX bytes:21938 (21.4 KiB)
  9. eth0 Link encap:Ethernet HWaddr 00:1A:64:64:6C:C8
  10. inet6 addr: fe80::21a:64ff:fe64:6cc8/64 Scope:Link
  11. UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
  12. RX packets:8672 errors:0 dropped:0 overruns:0 frame:0
  13. TX packets:89 errors:0 dropped:0 overruns:0 carrier:0
  14. collisions:0 txqueuelen:1000
  15. RX bytes:568833 (555.5 KiB) TX bytes:17518 (17.1 KiB)
  16. Interrupt:3 Memory:ce000000-ce012100
  17. eth1 Link encap:Ethernet HWaddr 00:1A:64:64:6C:C8
  18. inet6 addr: fe80::21a:64ff:fe64:6cc8/64 Scope:Link
  19. UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
  20. RX packets:8394 errors:0 dropped:0 overruns:0 frame:0
  21. TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
  22. collisions:0 txqueuelen:1000
  23. RX bytes:549948 (537.0 KiB) TX bytes:4420 (4.3 KiB)
  24. Interrupt:10 Memory:ca000000-ca012100

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

查看bonding的状态

  1. cat /proc/net/bonding/bond0
  1. Ethernet Channel Bonding Driver: v3.1.2 (January 20, 2007)
  2. Bonding Mode: fault-tolerance (active-backup)
  3. Primary Slave: None
  4. Currently Active Slave: eth0
  5. MII Status: up
  6. MII Polling Interval (ms): 100
  7. Up Delay (ms): 0
  8. Down Delay (ms): 0
  9. Slave Interface: eth0
  10. MII Status: up
  11. Link Failure Count: 0
  12. Permanent HW addr: 00:1a:64:64:6c:c8
  13. Slave Interface: eth1
  14. MII Status: up
  15. Link Failure Count: 0
  16. Permanent HW addr: 00:1a:64:64:6c:ca

转载请注明作者和出处,并添加本页链接。
原文链接: blog.xugaoxiang.com/108

给我留言