[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 - 主备模式
绑定网卡:eno33554992+eno50332216=bond0
双网卡绑定步骤 查看物理网卡信息
[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
删除网卡连接信息
[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开始)。
[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:设备类型: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.
[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
[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切换测试
[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
[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
[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
[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
[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