layout: post
title: Centos7网卡配置命令nmcli
date: 2017-12-17
tags: [“Linux”,”网络相关”]


在配置Centos6时,大家第一想到的就是把networkManager这个服务关掉,让它消失,这个服务台太鸡肋了,不该起作用的时候经常起作用,给管理带来了不便,但是在Centos7当中networkManager的bug已经修复了,并且可以使用一个很强大的命令nmcli来管理(nmcli命令依赖networkManager服务)。我不知道为什么红帽官方为什么要推荐使用这么强大复杂的,不是应该越简洁越好么,但是既然推荐了,那么还是好好练习一下吧,没准儿就像git一样,虽然复杂,但是用熟练了可以提升n倍的工作效率。因为nmcli命令非常复杂,所以就单独写一篇博客了。

nmcli一些基础用法,nmcli后面的命令是支持缩写的,但是本篇博客就用完整的名字来写了:

nmcli connection show 显示网卡配置信息

  1. [root@newhostname etc]# nmcli connection show
  2. 名称 UUID 类型 设备
  3. Bond bond0 ad33d8b0-1f7b-cab9-9447-ba07f855b143 bond bond0
  4. System ens33 c96bc909-188e-ec64-3a96-6a90982b08ad 802-3-ethernet ens33
  5. System ens38 be9e2b6b-674b-771d-7251-f3b49b3d23e0 802-3-ethernet ens38
  6. eth0 4a5516a4-dfa4-24af-b1c4-e843e312e2fd 802-3-ethernet ens37

有设备标注的表示已经启用的网卡配置文件

nmcli connection delete 删除一个网卡配置文件

  1. [root@newhostname network-scripts]# cp ifcfg-ens37 ifcfg-ens37.bak
  2. [root@newhostname network-scripts]# nmcli connection delete eth0
  3. 成功删除连接 'eth0'4a5516a4-dfa4-24af-b1c4-e843e312e2fd)。

查看一下是否删除了

  1. [root@newhostname network-scripts]# ls ' grep ifcfg-ens
  2. ifcfg-ens33
  3. ifcfg-ens37.bak
  4. ifcfg-ens38

恢复配置

  1. [root@newhostname network-scripts]# mv ifcfg-ens37.bak ifcfg-ens37
  2. [root@newhostname network-scripts]# nmcli connection show
  3. 名称 UUID 类型 设备
  4. Bond bond0 ad33d8b0-1f7b-cab9-9447-ba07f855b143 bond bond0
  5. System ens33 c96bc909-188e-ec64-3a96-6a90982b08ad 802-3-ethernet ens33
  6. System ens38 be9e2b6b-674b-771d-7251-f3b49b3d23e0 802-3-ethernet ens38
  7. Wired connection 1 f0c177b9-f8a8-3686-bbb1-f79af06df083 802-3-ethernet ens37

配置恢复了

现在我们来用nmcli命令来添加配置文件

首先,我们需要先知道,在服务器上启用的网卡
使用 nmcli device命令可以查看到网卡的连接状态

  1. [root@newhostname network-scripts]# nmcli device
  2. 设备 类型 状态 连接
  3. bond0 bond 连接的 Bond bond0
  4. ens33 ethernet 连接的 System ens33
  5. ens37 ethernet 连接的 Wired connection 1
  6. ens38 ethernet 连接的 System ens38
  7. lo loopback 未托管 --

可以这样理解nmcli device 类似 ip link

现在我们来为bond0添加网卡配置文件

  1. [root@newhostname ~]# nmcli connection add con-name bond0-office ifname bond0 type bond mode 0 ipv4.method auto
  2. 连接"bond0-office"(86f5c5d1-7b22-425f-96ad-cce91da27f98) 已成功添加。
  3.  
  4. #con-name: 表示设备别名,文件的标识
  5. #type: 类型 bond、ethernet、brigde
  6. #ifname :设备名
  7. #ipv4.method : manual 为手动配置 ;auto为自动(可以获取dhcp)
  8. #ipv4.addresses : ipv4的IP地址
  9. #ipv4.gateway : ipv4的网关
  10. #ipv4.dns : ipv4的dns服务器

通过nmcli connection add 方法,我们成功的添加了一个新的网卡配置文件
我们再来看一下文件的状态

  1. [root@newhostname ~]# nmcli connection show
  2. 名称 UUID 类型 设备
  3. Bond bond0 ad33d8b0-1f7b-cab9-9447-ba07f855b143 bond bond0
  4. System ens33 c96bc909-188e-ec64-3a96-6a90982b08ad 802-3-ethernet ens33
  5. System ens38 be9e2b6b-674b-771d-7251-f3b49b3d23e0 802-3-ethernet ens38
  6. Wired connection 1 f0c177b9-f8a8-3686-bbb1-f79af06df083 802-3-ethernet ens37
  7. bond0-office 86f5c5d1-7b22-425f-96ad-cce91da27f98 bond --

可以看出,新加的网卡配置文件并没有启用,我们现在启用这个配置文件

  1. [root@newhostname ~]# nmcli connection up bond0-office #刚才实验其实做错了,我这里就不写了,在创建文件的时候,如果是bond类型,那么type必须是bond,如果不写type,这里是激活不了的
  2. 成功激活(主服务器等待从服务器)连接(D-Bus 激活路径:/org/freedesktop/NetworkManager/ActiveConnection/15

我们查看一下新的配置文件状态和属性

  1. [root@newhostname ~]# nmcli connection show bond0-office
  2. connection.id: bond0-office
  3. connection.uuid: 86f5c5d1-7b22-425f-96ad-cce91da27f98
  4. connection.stable-id: --
  5. connection.interface-name: bond0
  6. connection.type: bond
  7. connection.autoconnect: yes
  8. connection.autoconnect-priority: 0
  9. connection.autoconnect-retries: -1 (默认)
  10. connection.timestamp: 1513493496
  11. connection.read-only: no
  12. connection.permissions: --
  13. connection.zone: --
  14. connection.master: --
  15. connection.slave-type: --
  16. connection.autoconnect-slaves: -1 (默认)
  17. connection.secondaries: --
  18. connection.gateway-ping-timeout: 0
  19. connection.metered: 未知
  20. connection.lldp: -1 (default)
  21. ipv4.method: auto
  22. ipv4.dns: --
  23. ipv4.dns-search: --
  24. ipv4.dns-options: (默认)
  25. ipv4.dns-priority: 0
  26. ipv4.addresses: --
  27. ipv4.gateway: --
  28. ipv4.routes: --
  29. ipv4.route-metric: -1
  30. ipv4.ignore-auto-routes: no
  31. ipv4.ignore-auto-dns: no
  32. ipv4.dhcp-client-id: --
  33. ipv4.dhcp-timeout: 0
  34. ipv4.dhcp-send-hostname: yes
  35. ipv4.dhcp-hostname: --
  36. ipv4.dhcp-fqdn: --
  37. ipv4.never-default: no
  38. ipv4.may-fail: yes
  39. ipv4.dad-timeout: -1 (默认)
  40. ipv6.method: auto
  41. ipv6.dns: --
  42. ipv6.dns-search: --
  43. ipv6.dns-options: (默认)
  44. ipv6.dns-priority: 0
  45. ipv6.addresses: --
  46. ipv6.gateway: --
  47. ipv6.routes: --
  48. ipv6.route-metric: -1
  49. ipv6.ignore-auto-routes: no
  50. ipv6.ignore-auto-dns: no
  51. ipv6.never-default: no
  52. ipv6.may-fail: yes
  53. ipv6.ip6-privacy: -1 (未知)
  54. ipv6.addr-gen-mode: stable-privacy
  55. ipv6.dhcp-send-hostname: yes
  56. ipv6.dhcp-hostname: --
  57. ipv6.token: --
  58. bond.options: mode=balance-rr
  59. proxy.method: none
  60. proxy.browser-only: no
  61. proxy.pac-url: --
  62. proxy.pac-script: --
  63. GENERAL.名称: bond0-office
  64. GENERAL.UUID: 86f5c5d1-7b22-425f-96ad-cce91da27f98
  65. GENERAL.设备: bond0
  66. GENERAL.状态: 已激活 #激活状态
  67. GENERAL.默认:
  68. GENERAL.默认6:
  69. GENERAL.VPN 参数:
  70. GENERAL.区: --
  71. GENERAL.DBUS路径: /org/freedesktop/NetworkManager/ActiveConnection/15
  72. GENERAL.连接路径: /org/freedesktop/NetworkManager/Settings/7
  73. GENERAL.指定对象: --
  74. GENERAL.主路径: --
  75. IP4.地址[1]: 172.18.16.206/16 #自动获取的地址
  76. IP4.网关: 172.18.0.1
  77. IP4.DNS[1]: 223.5.5.5
  78. IP4.DNS[2]: 223.6.6.6
  79. IP4.域[1]: --
  80. DHCP4.选项[1]: requested_routers = 1
  81. DHCP4.选项[2]: requested_domain_search = 1
  82. DHCP4.选项[3]: requested_time_offset = 1
  83. DHCP4.选项[4]: requested_domain_name = 1
  84. DHCP4.选项[5]: requested_rfc3442_classless_static_routes = 1
  85. DHCP4.选项[6]: requested_classless_static_routes = 1
  86. DHCP4.选项[7]: dhcp_server_identifier = 172.18.0.1
  87. DHCP4.选项[8]: requested_wpad = 1
  88. DHCP4.选项[9]: requested_broadcast_address = 1
  89. DHCP4.选项[10]: next_server = 0.0.0.0
  90. DHCP4.选项[11]: broadcast_address = 172.18.255.255
  91. DHCP4.选项[12]: requested_interface_mtu = 1
  92. DHCP4.选项[13]: requested_subnet_mask = 1
  93. DHCP4.选项[14]: expiry = 1513494096
  94. DHCP4.选项[15]: dhcp_message_type = 5
  95. DHCP4.选项[16]: ip_address = 172.18.16.206
  96. DHCP4.选项[17]: routers = 172.18.0.1
  97. DHCP4.选项[18]: domain_name = magedu.com
  98. DHCP4.选项[19]: requested_static_routes = 1
  99. DHCP4.选项[20]: requested_nis_servers = 1
  100. DHCP4.选项[21]: requested_ntp_servers = 1
  101. DHCP4.选项[22]: requested_domain_name_servers = 1
  102. DHCP4.选项[23]: dhcp_lease_time = 600
  103. DHCP4.选项[24]: domain_name_servers = 223.5.5.5 223.6.6.6
  104. DHCP4.选项[25]: requested_ms_classless_static_routes = 1
  105. DHCP4.选项[26]: subnet_mask = 255.255.0.0
  106. DHCP4.选项[27]: network_number = 172.18.0.0
  107. DHCP4.选项[28]: requested_host_name = 1
  108. DHCP4.选项[29]: requested_nis_domain = 1
  109. IP6.地址[1]: fe80::8714:3d23:b1a9:73b7/64
  110. IP6.地址[2]: fe80::cd18:b4a3:9d06:2ff3/64
  111. IP6.地址[3]: fe80::da49:1504:e231:df1a/64
  112. IP6.网关: --

看一下配置文件

  1. [root@newhostname ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0-office
  2. DEVICE=bond0
  3. BONDING_OPTS=mode=balance-rr
  4. TYPE=Bond
  5. BONDING_MASTER=yes
  6. PROXY_METHOD=none
  7. BROWSER_ONLY=no
  8. BOOTPROTO=dhcp
  9. DEFROUTE=yes
  10. IPV4_FAILURE_FATAL=no
  11. IPV6INIT=yes
  12. IPV6_AUTOCONF=yes
  13. IPV6_DEFROUTE=yes
  14. IPV6_FAILURE_FATAL=no
  15. IPV6_ADDR_GEN_MODE=stable-privacy
  16. NAME=bond0-office
  17. UUID=86f5c5d1-7b22-425f-96ad-cce91da27f98
  18. ONBOOT=yes

我们创建的是一个bond设备配置文件,那么就需要slave网卡来支撑,下面我们在添加连个slave网卡

  1. [root@newhostname ~]# nmcli connection add type bond-slave ifname ens33 master bond0
  2. 连接"bond-slave-ens33"(0c0f0e30-6f4a-4fb2-9237-c8380225f61a) 已成功添加。
  3. [root@newhostname ~]# nmcli connection add type bond-slave ifname ens38 master bond0
  4. 连接"bond-slave-ens38"(1a21b214-4e3e-435c-8c2b-ab4ca2934980) 已成功添加。

OK!我们来看下这俩网卡的配置文件

  1. [root@newhostname network-scripts]# cat ifcfg-bond-slave-ens3[38] # 刚才我没有指定管理文件名,系统默认给起了一个ifcfg-bond-slave-ens33 和 ifcfg-bond-slave-ens38 如果要指定名字可以使用 con-name
  2. TYPE=Ethernet
  3. NAME=bond-slave-ens33
  4. UUID=0c0f0e30-6f4a-4fb2-9237-c8380225f61a
  5. DEVICE=ens33
  6. ONBOOT=yes
  7. MASTER=bond0
  8. SLAVE=yes
  9. TYPE=Ethernet
  10. NAME=bond-slave-ens38
  11. UUID=1a21b214-4e3e-435c-8c2b-ab4ca2934980
  12. DEVICE=ens38
  13. ONBOOT=yes
  14. MASTER=bond0
  15. SLAVE=yes

查看一下现在生效的配置文件

  1. [root@newhostname network-scripts]# nmcli connection show
  2. 名称 UUID 类型 设备
  3. System ens33 c96bc909-188e-ec64-3a96-6a90982b08ad 802-3-ethernet ens33
  4. System ens38 be9e2b6b-674b-771d-7251-f3b49b3d23e0 802-3-ethernet ens38
  5. Wired connection 1 f0c177b9-f8a8-3686-bbb1-f79af06df083 802-3-ethernet ens37
  6. bond0-office 86f5c5d1-7b22-425f-96ad-cce91da27f98 bond bond0
  7. Bond bond0 ad33d8b0-1f7b-cab9-9447-ba07f855b143 bond --
  8. bond-slave-ens33 0c0f0e30-6f4a-4fb2-9237-c8380225f61a 802-3-ethernet --
  9. bond-slave-ens38 1a21b214-4e3e-435c-8c2b-ab4ca2934980 802-3-ethernet --

因为我们之前已经将bond0-office启用了,所以再把ifcfg-bond-slave-ens33 和 ifcfg-bond-slave-ens38启用就好了

  1. [root@newhostname network-scripts]# nmcli connection up bond-slave-ens33
  2. 连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/18
  3. [root@newhostname network-scripts]# nmcli connection up bond-slave-ens38
  4. 连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/19

现在看来也不是太麻烦,名字长用tab键补全完全没问题!

如果我们不用bond,需要给普通网卡添加设置type可以不写,也可以写type ethernet,后面的参数正常配置就OK了。

修改配置文件

我们可以通过nmcli connection modity 来实现修改配置文件。
我们先来添加一个ip地址看看

  1. [root@newhostname network-scripts]# nmcli connection modify bond0-office +ipv4.addresses 172.18.30.1/16
  2. [root@newhostname network-scripts]# cat ifcfg-bond0-office
  3. DEVICE=bond0
  4. BONDING_OPTS=mode=balance-rr
  5. TYPE=Bond
  6. BONDING_MASTER=yes
  7. PROXY_METHOD=none
  8. BROWSER_ONLY=no
  9. BOOTPROTO=dhcp
  10. DEFROUTE=yes
  11. IPV4_FAILURE_FATAL=no
  12. IPV6INIT=yes
  13. IPV6_AUTOCONF=yes
  14. IPV6_DEFROUTE=yes
  15. IPV6_FAILURE_FATAL=no
  16. IPV6_ADDR_GEN_MODE=stable-privacy
  17. NAME=bond0-office
  18. UUID=86f5c5d1-7b22-425f-96ad-cce91da27f98
  19. ONBOOT=yes
  20. IPADDR=172.18.30.1
  21. PREFIX=16

我们再来删掉这个地址

  1. [root@newhostname network-scripts]# nmcli connection modify bond0-office -ipv4.addresses 172.18.30.1
  2. [root@newhostname network-scripts]# cat ifcfg-bond0-office
  3. DEVICE=bond0
  4. BONDING_OPTS=mode=balance-rr
  5. TYPE=Bond
  6. BONDING_MASTER=yes
  7. PROXY_METHOD=none
  8. BROWSER_ONLY=no
  9. BOOTPROTO=dhcp
  10. DEFROUTE=yes
  11. IPV4_FAILURE_FATAL=no
  12. IPV6INIT=yes
  13. IPV6_AUTOCONF=yes
  14. IPV6_DEFROUTE=yes
  15. IPV6_FAILURE_FATAL=no
  16. IPV6_ADDR_GEN_MODE=stable-privacy
  17. NAME=bond0-office
  18. UUID=86f5c5d1-7b22-425f-96ad-cce91da27f98
  19. ONBOOT=yes

由以上操作可以看出,nmcli connection modify 是可以添加减少,直接修改网络参数的

对配置文件和设备的一些操作

这些操作很简单,简单列出来就好了
nmcli connection down bond0-office 关闭bond0-office配置文件
nmcli connection up bond0-office 启用这个配置文件
nmcli device down bond0 关闭设备,是设备不是文件
nmcli device up bond0 启用这个设备

再来说一个新玩意儿”网络组Network Teaming”

网络组:是将多个网卡聚合在一起方法,从而实现冗错和提高吞吐量;网络组不同于旧版中bonding技术,提供更好的性能和扩展性,由内核驱动和teamd守护进程实现.这玩意儿展现的形式就和bond差不多,和bond的功能也差不多,据官方说这个要比bond性能高很多,但是在生产上还不太敢用,这里先把配置方法写出来吧,没准儿以后会用到。

我们来添加一个网络组:

1、我们先删掉所有的网卡配置文件

  1. [root@newhostname network-scripts]# nmcli connection show
  2. 名称 UUID 类型 设备
  3. Wired connection 1 f0c177b9-f8a8-3686-bbb1-f79af06df083 802-3-ethernet ens37
  4. bond-slave-ens33 0c0f0e30-6f4a-4fb2-9237-c8380225f61a 802-3-ethernet ens33
  5. bond-slave-ens38 1a21b214-4e3e-435c-8c2b-ab4ca2934980 802-3-ethernet ens38
  6. bond0-office 86f5c5d1-7b22-425f-96ad-cce91da27f98 bond bond0
  7. Bond bond0 ad33d8b0-1f7b-cab9-9447-ba07f855b143 bond --
  8. System ens33 c96bc909-188e-ec64-3a96-6a90982b08ad 802-3-ethernet --
  9. System ens38 be9e2b6b-674b-771d-7251-f3b49b3d23e0 802-3-ethernet --
  10. [root@newhostname network-scripts]# nmcli con del bond0-office
  11. 成功删除连接 'bond0-office'86f5c5d1-7b22-425f-96ad-cce91da27f98)。
  12. [root@newhostname network-scripts]# nmcli con del Bond\ bond0
  13. 成功删除连接 'Bond bond0'ad33d8b0-1f7b-cab9-9447-ba07f855b143)。
  14. [root@newhostname network-scripts]# nmcli con del bond-slave-ens33
  15. 成功删除连接 'bond-slave-ens33'0c0f0e30-6f4a-4fb2-9237-c8380225f61a)。
  16. [root@newhostname network-scripts]# nmcli connection delete bond-slave-ens38
  17. 成功删除连接 'bond-slave-ens38'1a21b214-4e3e-435c-8c2b-ab4ca2934980)。
  18. [root@newhostname network-scripts]# nmcli con del System\ ens33
  19. 成功删除连接 'System ens33'c96bc909-188e-ec64-3a96-6a90982b08ad)。
  20. [root@newhostname network-scripts]# nmcli con del System\ ens38
  21. 成功删除连接 'System ens38'be9e2b6b-674b-771d-7251-f3b49b3d23e0)。
  22. [root@newhostname network-scripts]# lsmod ' grep bond
  23. bonding 145728 0
  24. [root@newhostname network-scripts]# modprobe -r bonding #删除bonding驱动,如果有需要可以再添加回来
  25.  
  26. [root@newhostname network-scripts]# nmcli connection show
  27. 名称 UUID 类型 设备
  28. Wired connection 1 f0c177b9-f8a8-3686-bbb1-f79af06df083 802-3-ethernet ens37

现在只剩下终端连接的网卡了,我们查看一下设备

  1. [root@newhostname network-scripts]# nmcli device
  2. 设备 类型 状态 连接
  3. ens37 ethernet 连接的 Wired connection 1
  4. ens33 ethernet 已断开 --
  5. ens38 ethernet 已断开 --
  6. lo loopback 未托管 --

创建一个Team

  1. [root@newhostname network-scripts]# nmcli connection add type team con-name team_default ifname team0 config '{"runner":{"name":"loadbalance"}}' ipv4.method manual ipv4.addresses 172.18.30.252/16 ipv4.gateway 172.18.0.1 ipv4.dns 172.18.0.1
  2. 连接"team_default"(87361b99-da59-411f-8c22-e842a734e6b7) 已成功添加。

网络组type为team
注意:在添加team工作方式的时候,其配置表现形式是json的格式

‘{“runner”: {“name”: “METHOD”}}’
METHOD 可以是broadcast, roundrobin,activebackup, loadbalance, lacp

创建节点(port)

  1. [root@newhostname network-scripts]# nmcli connection add type team-slave con-name team-ens33 ifname ens33 master team0
  2. 连接"team-ens33"(dd0286bf-eb75-40a1-aa50-09bbd0f2fec9) 已成功添加。
  3. [root@newhostname network-scripts]# nmcli connection add type team-slave con-name team-ens38 ifname ens38 master team0
  4. 连接"team-ens38"(d6691baa-6a11-4c57-b038-e136940c219d) 已成功添加。
  5. [root@newhostname network-scripts]# nmcli connection show
  6. 名称 UUID 类型 设备
  7. Wired connection 1 f0c177b9-f8a8-3686-bbb1-f79af06df083 802-3-ethernet ens37
  8. team-ens33 dd0286bf-eb75-40a1-aa50-09bbd0f2fec9 802-3-ethernet ens33
  9. team-ens38 d6691baa-6a11-4c57-b038-e136940c219d 802-3-ethernet ens38
  10. team_default 87361b99-da59-411f-8c22-e842a734e6b7 team team0

连接名若不指定,默认为team-slave-IFACE
显而易见创建port的方法和bond极其相似,我们再来看一下设备状态

  1. [root@newhostname network-scripts]# nmcli device
  2. 设备 类型 状态 连接
  3. ens33 ethernet 连接的 team-ens33
  4. ens37 ethernet 连接的 Wired connection 1
  5. ens38 ethernet 连接的 team-ens38
  6. team0 team 连接的 team_default
  7. lo loopback 未托管 --

创建完配置之后设备直接启用了。

现在我们来看一下team的配置文件

  1. [root@newhostname network-scripts]# cat ifcfg-team-ens33 #节点的配置文件
  2. NAME=team-ens33
  3. UUID=dd0286bf-eb75-40a1-aa50-09bbd0f2fec9
  4. DEVICE=ens33
  5. ONBOOT=yes
  6. TEAM_MASTER=team0
  7. DEVICETYPE=TeamPort
  8. [root@newhostname network-scripts]# cat ifcfg-team_default #team组的配置文件
  9. DEVICE=team0
  10. TEAM_CONFIG="{\"runner\":{\"name\":\"loadbalance\"}}"
  11. PROXY_METHOD=none
  12. BROWSER_ONLY=no
  13. BOOTPROTO=none
  14. IPADDR=172.18.30.252
  15. PREFIX=16
  16. GATEWAY=172.18.0.1
  17. DNS1=172.18.0.1
  18. DEFROUTE=yes
  19. IPV4_FAILURE_FATAL=no
  20. IPV6INIT=yes
  21. IPV6_AUTOCONF=yes
  22. IPV6_DEFROUTE=yes
  23. IPV6_FAILURE_FATAL=no
  24. IPV6_ADDR_GEN_MODE=stable-privacy
  25. NAME=team_default
  26. UUID=87361b99-da59-411f-8c22-e842a734e6b7
  27. ONBOOT=yes
  28. DEVICETYPE=Team

删除Team组

  1. [root@newhostname network-scripts]# teamdctl team0 state #查看team0状态
  2. setup:
  3. runner: loadbalance #运行方式
  4. ports:
  5. ens33
  6. link watches:
  7. link summary: up #状态
  8. instance[link_watch_0]:
  9. name: ethtool
  10. link: up
  11. down count: 0
  12. ens38
  13. link watches:
  14. link summary: up #状态
  15. instance[link_watch_0]:
  16. name: ethtool
  17. link: up
  18. down count: 0
  19.  
  20. [root@newhostname network-scripts]# nmcli connection down team_default
  21. 成功取消激活连接 'team_default'D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/24
  22.  
  23. [root@newhostname network-scripts]# teamdctl team0 state
  24. Device "team0" does not exist

再将连个port删掉就ok了。

网桥的配置

写到这里,我突然感觉nmcli这个命令根本就是一个配置网卡的神器!Very big nice!

看一下现在的网络配置状态

  1. [root@newhostname network-scripts]# nmcli connection show
  2. 名称 UUID 类型 设备
  3. Wired connection 1 f0c177b9-f8a8-3686-bbb1-f79af06df083 802-3-ethernet ens37
  4. team-ens33 dd0286bf-eb75-40a1-aa50-09bbd0f2fec9 802-3-ethernet ens33
  5. team-ens38 d6691baa-6a11-4c57-b038-e136940c219d 802-3-ethernet ens38
  6. team_default 87361b99-da59-411f-8c22-e842a734e6b7 team team0

现在我们就将ens38和ens33连接在一起

  1. [root@newhostname ~]# nmcli connection show
  2. 名称 UUID 类型 设备
  3. Wired connection 1 f0c177b9-f8a8-3686-bbb1-f79af06df083 802-3-ethernet ens37
  4. team-ens33 dd0286bf-eb75-40a1-aa50-09bbd0f2fec9 802-3-ethernet ens33
  5. team-ens38 d6691baa-6a11-4c57-b038-e136940c219d 802-3-ethernet ens38
  6. team_default 87361b99-da59-411f-8c22-e842a734e6b7 team team0
  7.  
  8. [root@newhostname ~]# nmcli connection add type bridge con-name briage_default ifname bridge0 ipv4.method manual ipv4.addresses 172.18.30.252/16 #添加网桥
  9. 连接"briage_default"(478fcfee-e338-4a4b-9ed0-9c592b381e45) 已成功添加。
  10. [root@newhostname ~]# nmcli connection add type bridge-slave ifname ens33 master bridge0 #添加接口
  11. 连接"bridge-slave-ens33"(d4a58e67-e349-4dcf-8fbe-bb340eb4a0a7) 已成功添加。
  12. [root@newhostname ~]# nmcli connection add type bridge-slave ifname ens38 master bridge0 #添加接口
  13. 连接"bridge-slave-ens38"(9f64f919-a62a-4d4d-99b5-9a44f77d3658) 已成功添加。
  14. [root@newhostname ~]# nmcli connection show
  15. 名称 UUID 类型 设备
  16. Wired connection 1 f0c177b9-f8a8-3686-bbb1-f79af06df083 802-3-ethernet ens37
  17. briage_default 478fcfee-e338-4a4b-9ed0-9c592b381e45 bridge bridge0
  18. team-ens33 dd0286bf-eb75-40a1-aa50-09bbd0f2fec9 802-3-ethernet ens33
  19. team-ens38 d6691baa-6a11-4c57-b038-e136940c219d 802-3-ethernet ens38
  20. team_default 87361b99-da59-411f-8c22-e842a734e6b7 team team0
  21. bridge-slave-ens33 d4a58e67-e349-4dcf-8fbe-bb340eb4a0a7 802-3-ethernet --
  22. bridge-slave-ens38 9f64f919-a62a-4d4d-99b5-9a44f77d3658 802-3-ethernet --
  23.  
  24. [root@newhostname ~]# nmcli connection up bridge-slave-ens33 #激活接口
  25. 连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/34
  26. [root@newhostname ~]# nmcli connection up bridge-slave-ens38 #激活接口
  27. 连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/35
  28.  
  29. [root@newhostname ~]# nmcli connection show
  30. 名称 UUID 类型 设备
  31. Wired connection 1 f0c177b9-f8a8-3686-bbb1-f79af06df083 802-3-ethernet ens37
  32. briage_default 478fcfee-e338-4a4b-9ed0-9c592b381e45 bridge bridge0
  33. bridge-slave-ens33 d4a58e67-e349-4dcf-8fbe-bb340eb4a0a7 802-3-ethernet ens33
  34. bridge-slave-ens38 9f64f919-a62a-4d4d-99b5-9a44f77d3658 802-3-ethernet ens38
  35. team_default 87361b99-da59-411f-8c22-e842a734e6b7 team team0
  36. team-ens33 dd0286bf-eb75-40a1-aa50-09bbd0f2fec9 802-3-ethernet -- #team的接口被顶掉了
  37. team-ens38 d6691baa-6a11-4c57-b038-e136940c219d 802-3-ethernet -- #team的接口被顶掉了

这样一个网桥就ok了

查看网桥

  1. [root@newhostname network-scripts]# cat ifcfg-briage_default
  2. DEVICE=bridge0
  3. STP=yes
  4. BRIDGING_OPTS=priority=32768
  5. TYPE=Bridge
  6. PROXY_METHOD=none
  7. BROWSER_ONLY=no
  8. BOOTPROTO=none
  9. IPADDR=172.18.30.252
  10. PREFIX=16
  11. DEFROUTE=yes
  12. IPV4_FAILURE_FATAL=no
  13. IPV6INIT=yes
  14. IPV6_AUTOCONF=yes
  15. IPV6_DEFROUTE=yes
  16. IPV6_FAILURE_FATAL=no
  17. IPV6_ADDR_GEN_MODE=stable-privacy
  18. NAME=briage_default
  19. UUID=478fcfee-e338-4a4b-9ed0-9c592b381e45
  20. ONBOOT=yes
  1. [root@newhostname network-scripts]# brctl show
  2. bridge name bridge id STP enabled interfaces
  3. bridge0 8000.000c29ff3fce yes ens33
  4. ens38

现在删除网桥

  1. [root@newhostname network-scripts]# brctl delif bridge0 ens33 ens38
  2. [root@newhostname network-scripts]# ip link set bridge0 down #必须停掉,否则无法删除网桥
  3. [root@newhostname network-scripts]# brctl delbr bridge0

注意:NetworkManager只支持以太网接口接口连接到网桥,不支持聚合接口(这个我就不做实验了,确实不行!)如果需要配置聚合接口,那么在配置文件内填入”BRIDGE=bridge0”

以上删除操作只是把briage当掉了,也可以在nmcli中操作。就不再掩饰了,前面那么多操作看明白了,This so easy!

 

 

文档更新时间: 2022-06-10 10:57   作者:张尚