您的当前位置:首页 --> CentOS入门
CentOS7双网卡绑定-Network bonding 2
浏览次数:1973 关键词 ( 绑定  双网卡  Network  bonding  )
Configure Network Bonding 系统环境 [root@test03 ~]# uname -a Linux test03 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux   [root@test03 ~]# ip addr show  1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN      link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00     inet 127.0.0.1/8 scope host lo        valid_lft forever preferred_lft forever     inet6 ::1/128 scope host         valid_lft forever preferred_lft forever 2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000     link/ether 00:0c:29:56:69:4d brd ff:ff:ff:ff:ff:ff     inet 192.168.231.13/24 brd 192.168.231.255 scope global eno16777736        valid_lft forever preferred_lft forever     inet6 fe80::20c:29ff:fe56:694d/64 scope link         valid_lft forever preferred_lft forever 3: eno33554992: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000     link/ether 00:0c:29:56:69:57 brd ff:ff:ff:ff:ff:ff 4: eno50332216: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000     link/ether 00:0c:29:56:69:61 brd ff:ff:ff:ff:ff:ff 双网卡绑定目标
  • 网卡绑定模式:active-backup - 主备模式

一个网卡处于活跃状态,另一个处于备份状态,所有流量都在主链路上处理,当活跃网卡down掉时,启用备份网卡。

  • 绑定网卡:eno33554992+eno50332216=bond0

设置网卡eno33554992为主网卡(优先处于活跃状态),eno50332216为辅网卡(备份状态,主网卡链路正常时,辅网卡处于备份状态)。

双网卡绑定步骤 查看物理网卡信息 [root@test03 network-scripts]# nmcli device  DEVICE       TYPE      STATE      CONNECTION   eno16777736  ethernet  connected  eno16777736  eno33554992  ethernet  connected  eno33554992  eno50332216  ethernet  connected  eno50332216  lo           loopback  unmanaged  --    # 共四张网卡,lo为本地回环网卡,另外三张为物理网卡。 查看网卡连接信息 [root@test03 network-scripts]# nmcli connection show  NAME         UUID                                  TYPE            DEVICE       eno50332216  36b38556-4bf8-4ce0-8045-4f5465530f67  802-3-ethernet  eno50332216  eno33554992  46831ccf-905b-4361-b5ba-c5448133e288  802-3-ethernet  eno33554992  eno16777736  613db14a-2375-4a89-b55a-d2abd8fc65d5  802-3-ethernet  eno16777736 删除网卡连接信息

本次Network bonding配置中,需要将eno33554992和eno50332216绑定为bond0,并且设置eno33554992为主网卡,首先需要这两块网卡现有的配置信息,否则team0创建完成后,未删除的网卡配置信息会影响bond0的正常工作。

如果nmcli connectionshow命令输出中无将要进行配置的网卡连接信息,则无需进行删除操作。

[root@test03 network-scripts]# nmcli connection delete eno33554992  [root@test03 network-scripts]# nmcli connection delete eno50332216  [root@test03 network-scripts] [root@test03 network-scripts]# nmcli connection show  NAME         UUID                                  TYPE            DEVICE       eno16777736  613db14a-2375-4a89-b55a-d2abd8fc65d5  802-3-ethernet  eno16777736  # 网卡连接信息删除成功。 # 这里删除的其实就是/etc/sysconfig/network-scripts目录下两块网卡的配置文件。 [root@test03 network-scripts]# pwd /etc/sysconfig/network-scripts [root@test03 network-scripts]# ls ifcfg-* ifcfg-eno16777736  ifcfg-lo 创建bond0 [root@test03 network-scripts]# nmcli connection add type bond ifname bond0 con-name bond0 miimon 100 mode active-backup primary eno33554992 ip4 192.168.231.200/24 Connection 'bond0' (dc55d681-0d5a-4de2-8e94-0e5cb2e249c9) successfully added.
  • primary eno33554992:指定主网卡为eno33554992

  • mode active-backup:指定bonding模式为active-backup

  • miimon 100:以毫秒为单位指定 MII 链接监控的频率(默认为0,即关闭此功能;配置miimon参数时,最好从100开始)。

bonding内核模块必须在ifcfg-bondN中的BONDING_OPTS="bonding parameters"中指定,各参数间使用空格分隔,不要在/etc/modprobe.d/bonding.conf和已经弃用的/etc/modprobe.conf文件中指定bonding配置选项。

配置完成后,此时会在/etc/sysconfig/network-scripts目录下生成ifcfg-bond0的配置文件:

[root@test03 network-scripts]# cat ifcfg-bond0 DEVICE=bond0 BONDING_OPTS="miimon=100 mode=active-backup primary=eno33554992" TYPE=Bond BONDING_MASTER=yes BOOTPROTO=none IPADDR=192.168.231.200 PREFIX=24 DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_FAILURE_FATAL=no NAME=bond0 UUID=dc55d681-0d5a-4de2-8e94-0e5cb2e249c9 ONBOOT=yes 创建bond0子接口

将网卡eno33554992和eno50332216创建为bond0的子接口:

# 添加网卡eno33554992:设备类型:bond-slave;连接名称:bond0-p1;master:bond0 [root@test03 network-scripts]# nmcli connection add type bond-slave ifname eno33554992 con-name bond0-p1 master bond0  Connection 'bond0-p1' (aaa54dc4-8122-4246-99e8-afd711e3102d) successfully added.   # 添加网卡eno50332216:设备类型:bond-slave;连接名称:bond0-p2;master:bond0 [root@test03 network-scripts]# nmcli connection add type bond-slave ifname eno50332216 con-name bond0-p2 master bond0  Connection 'bond0-p2' (11e38097-2273-4565-bf1c-3ce2e2e2a0ea) successfully added.

配置完成后,此时会在/etc/sysconfig/network-scripts目录下生成ifcfg-bond0-p1,ifcfg-bond0-p2的配置文件:

[root@test03 network-scripts]# cat ifcfg-bond0-p1  TYPE=Ethernet NAME=bond0-p1 UUID=aaa54dc4-8122-4246-99e8-afd711e3102d DEVICE=eno33554992 ONBOOT=yes MASTER=bond0 SLAVE=yes [root@test03 network-scripts] [root@test03 network-scripts]# cat ifcfg-bond0-p2 TYPE=Ethernet NAME=bond0-p2 UUID=11e38097-2273-4565-bf1c-3ce2e2e2a0ea DEVICE=eno50332216 ONBOOT=yes MASTER=bond0 SLAVE=yes 激活bond0及其子接口

查看当前已激活的网络接口:

[root@test03 network-scripts]# nmcli connection show --active  NAME         UUID                                  TYPE            DEVICE       eno16777736  613db14a-2375-4a89-b55a-d2abd8fc65d5  802-3-ethernet  eno16777736  bond0-p2     11e38097-2273-4565-bf1c-3ce2e2e2a0ea  802-3-ethernet  eno50332216  bond0-p1     aaa54dc4-8122-4246-99e8-afd711e3102d  802-3-ethernet  eno33554992  bond0        dc55d681-0d5a-4de2-8e94-0e5cb2e249c9  bond            bond0

如果bond0-p1、bond0-p2、bond0没有激活,可使用下面命令进行激活:

[root@test03 network-scripts]# nmcli connection up bond0-p1 [root@test03 network-scripts]# nmcli connection up bond0-p2 [root@test03 network-scripts]# nmcli connection up bond0 bonding状态查看 [root@test03 network-scripts]# cd /proc/net/bonding/ [root@test03 bonding]# ls bond0 [root@test03 bonding]# cat bond0  Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)   Bonding Mode: fault-tolerance (active-backup) Primary Slave: eno33554992 (primary_reselect always) Currently Active Slave: eno33554992 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0   Slave Interface: eno33554992 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:56:69:57 Slave queue ID: 0   Slave Interface: eno50332216 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:56:69:61 Slave queue ID: 0 bonding切换测试

首先查看bond0当前状态:

[root@test03 network-scripts]# cd /proc/net/bonding/ [root@test03 bonding]# ls bond0 [root@test03 bonding]# cat bond0  Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)   Bonding Mode: fault-tolerance (active-backup) Primary Slave: eno33554992 (primary_reselect always) Currently Active Slave: eno33554992 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0   Slave Interface: eno33554992 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:56:69:57 Slave queue ID: 0   Slave Interface: eno50332216 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:56:69:61 Slave queue ID: 0

当前活跃网卡为主网卡:eno33554992,长ping bond0 IP地址:ping 192.168.231.200 -t,网络畅通,现在断开eno33554992的网络连接:

[root@test03 bonding]# nmcli connection down bond0-p1  Connection 'bond0-p1' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)   # ping 192.168.231.200 -t 来自 192.168.231.200 的回复: 字节=32 时间=2ms TTL=64 来自 192.168.231.200 的回复: 字节=32 时间<1ms TTL=64 请求超时。 请求超时。 来自 192.168.231.200 的回复: 字节=32 时间<1ms TTL=64 来自 192.168.231.200 的回复: 字节=32 时间<1ms TTL=64

发现网络短暂断开后恢复(本次测试环境为虚拟机,真实物理机应该看不到网络断开连接的情况),此时查看bond0状态为:

[root@test03 bonding]# cat bond0  Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)   Bonding Mode: fault-tolerance (active-backup) Primary Slave: None Currently Active Slave: eno50332216 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0   Slave Interface: eno50332216 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:56:69:61 Slave queue ID: 0

现在恢复eno33554992的网络连接:

[root@test03 bonding]# nmcli connection up bond0-p1  Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)   # ping 192.168.231.200 -t 来自 192.168.231.200 的回复: 字节=32 时间=2ms TTL=64 来自 192.168.231.200 的回复: 字节=32 时间<1ms TTL=64 请求超时。 请求超时。 来自 192.168.231.200 的回复: 字节=32 时间<1ms TTL=64 来自 192.168.231.200 的回复: 字节=32 时间<1ms TTL=64

查看bond0工作状态为:

[root@test03 bonding]# cat bond0  Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)   Bonding Mode: fault-tolerance (active-backup) Primary Slave: eno33554992 (primary_reselect always) Currently Active Slave: eno33554992 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0   Slave Interface: eno50332216 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:56:69:61 Slave queue ID: 0   Slave Interface: eno33554992 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:56:69:57 Slave queue ID: 0
下一条 centos系统中网络配置相关
上一条 CentOS 配置防火墙

数千企业与站长的选择,7*24小时稳定运行

 了解更多套餐详细