linux基础之网络篇第四章nmcli绑定

  • nmcli 上篇已经介绍了创建网卡配置,网卡切换等
  • 在CentOS7里面如何实现多网卡绑定
  • 也可以修改文件,这里是用命令
  • 我们先定义一个IP:我定义的是172.17.250.89
  • ping下IP,他是不通的
[root@localhost ~]# ping 172.17.250.89
PING 172.17.250.89 (172.17.250.89) 56(84) bytes of data.
From 172.17.254.78 icmp_seq=2 Destination Host Unreachable
From 172.17.254.78 icmp_seq=3 Destination Host Unreachable
From 172.17.254.78 icmp_seq=4 Destination Host Unreachable
From 172.17.254.78 icmp_seq=6 Destination Host Unreachable
From 172.17.254.78 icmp_seq=7 Destination Host Unreachable
From 172.17.254.78 icmp_seq=8 Destination Host Unreachable

nmcli绑定

  • 首先我们先用命令来生成配置文件 ,用命令nmcli connection add type bond con-name bond0 ifname bond0 mode active-backup
[root@localhost ~]# nmcli connection add  type bond con-name bond0 ifname bond0 mode active-backup 
Connection 'bond0' (282d8832-e1ea-43de-b769-fae4b26d7244) successfully added.
  • 来查看下配置生成了没有,使用命令nmcli connection show,下面的bond0就是我们生成的文件
[root@localhost ~]# nmcli connection show 
NAME                UUID                                  TYPE            DEVICE 
Wired connection 1  d2444c8a-2a16-3338-9558-5920b573bc91  802-3-ethernet  eth0   
Wired connection 2  679bea27-b8ed-3e8e-94a5-62329f148f3e  802-3-ethernet  eth1   
Wired connection 3  d094d2c1-6fac-3b62-81c8-4bbae33bbc12  802-3-ethernet  eth2   
bond0               282d8832-e1ea-43de-b769-fae4b26d7244  bond                
ens33               d5b2a714-b9f6-44dc-9724-45d60edbde62  802-3-ethernet  --     
ens34               a688a753-ba50-416b-bd37-02d240901857  802-3-ethernet  --    
  • 我们在来查看下他的格式
[root@localhost network-scripts]# cat ifcfg-bond0
DEVICE=bond0
BONDING_OPTS=mode=active-backup
TYPE=Bond
BONDING_MASTER=yes
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=bond0
UUID=282d8832-e1ea-43de-b769-fae4b26d7244
ONBOOT=yes
  • 接下来我们给他配地址m,使用命令 nmcli connection modify bond0 ipv4.method manual ipv4.addresses 172.17.250.89/24
[root@localhost network-scripts]# nmcli connection modify  bond0 ipv4.method manual ipv4.addresses  172.17.250.89/24
  • 在来查看下网卡配置状态
[root@localhost network-scripts]# cat ifcfg-bond0
DEVICE=bond0
TYPE=Bond
BONDING_MASTER=yes
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=bond0
UUID=282d8832-e1ea-43de-b769-fae4b26d7244
ONBOOT=yes
BONDING_OPTS=mode=active-backup
IPADDR=172.17.250.89
PREFIX=24
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
  • 查看下地址,没有获取到IP不能ping通,只是配置文件里面有IP
[root@localhost network-scripts]# ifconfig
bond0: flags=5123  mtu 1500
        ether be:bf:fb:4a:60:e2  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • 接下来我们使用nmcli connection up bond0命令让配置文件生效
[root@localhost network-scripts]# nmcli connection up bond0
  • 查看下配置文件,bond0已经生效里面已经有了IP,我们看看他是否通了
[root@localhost ~]# ifconfig
bond0: flags=5123  mtu 1500
        inet 172.17.250.89  netmask 255.255.255.0  broadcast 172.17.250.255
        ether be:bf:fb:4a:60:e2  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • 查看下,另外一台电脑是否ping通
  • 已经ping通
[root@localhost ~]# ping 172.17.250.89
PING 172.17.250.89 (172.17.250.89) 56(84) bytes of data.
64 bytes from 172.17.250.89: icmp_seq=1 ttl=64 time=0.758 ms
64 bytes from 172.17.250.89: icmp_seq=2 ttl=64 time=0.753 ms
64 bytes from 172.17.250.89: icmp_seq=3 ttl=64 time=0.471 ms
64 bytes from 172.17.250.89: icmp_seq=4 ttl=64 time=1.06 ms
64 bytes from 172.17.250.89: icmp_seq=5 ttl=64 time=0.487 ms
64 bytes from 172.17.250.89: icmp_seq=6 ttl=64 time=0.429 ms
  • 现在只是给他IP 还没有给他绑定物理网卡,他没有容错功能
  • 接下来把eth0和eth1绑定到bond0里面
[root@localhost ~]# ifconfig
bond0: flags=5123  mtu 1500
        inet 172.17.250.89  netmask 255.255.255.0  broadcast 172.17.250.255
        ether be:bf:fb:4a:60:e2  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163  mtu 1500
        inet 192.168.31.128  netmask 255.255.255.0  broadcast 192.168.31.255
        inet6 fe80::a29b:8116:eaca:f436  prefixlen 64  scopeid 0x20
        ether 00:0c:29:52:72:d2  txqueuelen 1000  (Ethernet)
        RX packets 885  bytes 89264 (87.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 465  bytes 63242 (61.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163  mtu 1500
        inet 172.17.254.77  netmask 255.255.0.0  broadcast 172.17.255.255
        inet6 fe80::edc6:9ab6:837e:b8f7  prefixlen 64  scopeid 0x20
        ether 00:0c:29:52:72:dc  txqueuelen 1000  (Ethernet)
        RX packets 39525  bytes 3170826 (3.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5186  bytes 535096 (522.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • 我们用nmcli connection add type bond-slave ifname eth0 master命令来执行,添加eth0和eth1
[root@localhost ~]# nmcli  connection add  type  bond-slave  ifname eth0 master bomd0
Warning: master='bomd0' doesn't refer to any existing profile.
Connection 'bond-slave-eth0-1' (5d1bf5be-89da-4983-bff8-c06d12ace0bb) successfully added.
  • 现在我们查看下/etc/sysconfig/network-scripts/路径下的文件
  • 已经多了些配置文件
[root@localhost network-scripts]# ls
ifcfg-bond0              ifcfg-ens34  ifdown-ib    ifdown-ppp       ifdown-tunnel  ifup-ib    ifup-plusb   ifup-Team         network-functions
    ifcfg-lo     ifdown-ippp  ifdown-routes    ifup           ifup-ippp  ifup-post    ifup-TeamPort     network-functions-ipv6
ifcfg-bond-slave-eth0ifdown       ifdown-ipv6  ifdown-sit       ifup-aliases   ifup-ipv6  ifup-ppp     ifup-tunnel  ifdown-bnep  ifdown-isdn  ifdown-Team      ifup-bnep      ifup-isdn  ifup-routes  ifup-wireless
ifcfg-ens33              ifdown-eth   ifdown-post  ifdown-TeamPort  ifup-eth       ifup-plip  ifup-sit     init.ipv6-global
  • 接下来我们关联到物理网卡上
[root@localhost network-scripts]# nmcli connection up  bond-slave-eth0
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/12)
[root@localhost network-scripts]# nmcli connection up  bond-slave-eth1
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/12)
  • 我们在来查询绑定的情况
  • 他们MAC地址完全相同
  • 绑定成功
[root@localhost ~]# ifconfig
bond0: flags=5187  mtu 1500
        inet 172.17.250.89  netmask 255.255.255.0  broadcast 172.17.250.255
        inet6 fe80::28c9:f0c9:1483:a02d  prefixlen 64  scopeid 0x20
        ether 00:0c:29:52:72:d2  txqueuelen 1000  (Ethernet)
        RX packets 52  bytes 3486 (3.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 19  bytes 1310 (1.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=6211  mtu 1500
        ether 00:0c:29:52:72:d2  txqueuelen 1000  (Ethernet)
        RX packets 1627  bytes 156249 (152.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1050  bytes 139562 (136.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
eth1: flags=6211  mtu 1500
        ether 00:0c:29:52:72:d2  txqueuelen 1000  (Ethernet)
        RX packets 600  bytes 61748 (60.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 134  bytes 18898 (18.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • 接下来我们去 /proc/net/bonding/bond0路径下面查看下他们的绑定关系
  • None表示运行中,up表示待命状态
  • 绑定配置成功
[root@localhost ~]# cat /proc/net/bonding/bond0 
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

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
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:52:72:d2
Slave queue ID: 0

Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:52:72:e6
Slave queue ID: 0
[root@localhost ~]# 
  • 接下来删除bond0 用命令connection down bond0,先下线
[root@localhost ~]# nmcli   connection down bond0
Connection 'bond0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/11)
  • 下线以后我们来看下配置
  • bond0 模块也自动下线了
[root@localhost ~]# ifconfig 
eth0: flags=4163  mtu 1500
        ether 00:0c:29:52:72:d2  txqueuelen 1000  (Ethernet)
        RX packets 1636  bytes 157932 (154.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1066  bytes 140574 (137.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163  mtu 1500
        ether 00:0c:29:52:72:dc  txqueuelen 1000  (Ethernet)
        RX packets 52659  bytes 4215036 (4.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5397  bytes 554782 (541.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • 接下来我们删除链接 用nmcli connection delete命令删除,也可以直接删除文件,我就直接删除文件了
[root@localhost network-scripts]# rm -rf  /etc/sysconfig/network-scripts/ifcfg-bond*
  • 在用nmcli connection reload 读取一下就完成了
    [root@localhost network-scripts]# nmcli connection reload

你可能感兴趣的:(linux基础之网络篇第四章nmcli绑定)