NIC Bonding on CentOS 7 with nmcli

当系统管理员希望增加可用带宽,并提供冗余和负载平衡的数据传输,内核支持bonding允许以聚合的方式实现。简单地说,绑定意味着将两个或多个物理网络接口(称为奴隶)聚合成一个单独的逻辑节点(称为主网络)。如果一个特定的NIC(网络接口卡)的经验问题,通信不受影响只要其他保持活跃。

1.先决条件

默认情况下,bonding内核模块没有启用。因此,我们将需要加载它并确保它持久。使用modprobe--first-time加载bonding模块,如果加载模块失败,会发出警告。

# modprobe --first-time bonding

以上的命令仅加载bondiing模块为当前会话,服务器重启后模块不会自动加载。为了确保持续加载,创建/etc/modules-load.d/bonding.conf文件放置于文件夹/etc/modules-load.d目录中,确保每次服务器重启时加载bonding模块。

# echo "# Load thebonding kernel module at boot" > /etc/modules-load.d/bonding.conf

# echo "bonding">> /etc/modules-load.d/bonding.conf

服务器重启之后确保bonding模块自动加载

# lsmod|grep bonding

bonding              136705  0

#

2、nucli创建bond

查看现有连接及可用的网络设备

# nmcli connection show

NAME  UUID  TYPE  DEVICE 

# nmcli device status

DEVICE       TYPE      STATE         CONNECTION 

eno16777736  ethernet  disconnected  --         

eno33554992  ethernet  disconnected  --         

bond0        bond      unmanaged     --         

lo           loopback  unmanaged     --         

#   

创建bond   

# nmcli con add type bond con-name bond0 ifname bond0 ip4 192.168.31.108/24 mode balance-rr

Connection 'bond0' (599582b0-346b-48d3-8f1d-f3bcee5deca7) successfully added.

# nmcli connection add type bond-slave con-name slave1 ifname eno16777736 master bond0

Connection 'slave1' (6a1dd331-bb90-4e92-9af6-654ed8b2d2ca) successfully added.

# nmcli connection add type bond-slave con-name slave2 ifname eno33554992 master bond0

Connection 'slave2' (e31f40c9-4a1c-45d5-9832-8a1705f0b1f7) successfully added.

#nmcli con mod bond0 ipv4.method manual

#nmcli con mod bond0 ipv4.gateway 192.168.31.1

#nmcli connection modify bond0 ipv4.dns 192.168.31.1

#nmcli connection modify bond0 bond.options mode=balance-rr,miimon=100,downdelay=0,updelay=0

创建后重启网络服务

#systemctl restart network

# nmcli device status

DEVICE       TYPE      STATE      CONNECTION 

bond0        bond      connected  bond0      

eno16777736  ethernet  connected  slave1     

eno33554992  ethernet  connected  slave2     

lo           loopback  unmanaged  --     

再次查看网络链接与网络设备    

# nmcli connection show

NAME    UUID                                  TYPE            DEVICE      

bond0   599582b0-346b-48d3-8f1d-f3bcee5deca7  bond            bond0       

slave1  6a1dd331-bb90-4e92-9af6-654ed8b2d2ca  802-3-ethernet  eno16777736 

slave2  e31f40c9-4a1c-45d5-9832-8a1705f0b1f7  802-3-ethernet  eno33554992 

# ip addr list

1: lo: 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: mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000

    link/ether 00:0c:29:51:e8:75 brd ff:ff:ff:ff:ff:ff

3: eno33554992: mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000

    link/ether 00:0c:29:51:e8:75 brd ff:ff:ff:ff:ff:ff

4: bond0: mtu 1500 qdisc noqueue state UP 

    link/ether 00:0c:29:51:e8:75 brd ff:ff:ff:ff:ff:ff

    inet 192.168.31.108/24 brd 192.168.31.255 scope global bond0

       valid_lft forever preferred_lft forever

    inet6 fe80::233b:2da9:bddd:c8dc/64 scope link tentative dadfailed 

       valid_lft forever preferred_lft forever

    inet6 fe80::875c:5f79:646d:8446/64 scope link tentative dadfailed 

       valid_lft forever preferred_lft forever

    inet6 fe80::bf1c:1978:9c5:6ed7/64 scope link tentative dadfailed 

       valid_lft forever preferred_lft forever

#