在现代社会,网络已成为人们生活中不可或缺的一部分。对于操作系统而言,网络功能的支持和管理显得尤为重要。本节课我们将探讨如何在centos8中管理网络。
在Linux系统中,传统的网络管理方式是通过名为"network"的服务来实现的。在CentOS7中仍然可以看到这个服务,但在CentOS8中已不再使用"network"服务,取而代之的是"NetworkManager"服务。NetworkManager服务简化了有线和无线连接的管理工作,并且能够管理各种类型的网络,包括物理网卡、虚拟网卡、以太网和非以太网等。
nmcli命令的使用类似于Linux中之前的ip命令,支持tab补全,并且可以通过-h或--help获取帮助信息。
[root@zutuanxue ~]# nmcli -h [root@zutuanxue ~]# nmcli connection -h
可以看到,不同阶段获取的帮助内容有所不同,具体用法将在后续详细介绍。nmcli工具有两个常用命令:
[root@zutuanxue network-scripts]# nmcli connection NAME UUID TYPE DEVICE ens33 b5ecf570-543c-4da7-b082-bdc073b56acb ethernet ens33 ens37 077945cb-1d12-4c06-bba3-562426336b67 ethernet --
在查看时,有颜色的字体标注的是处于活跃状态的网卡,即已连接的;正常颜色的字体标记的是非活跃状态的网卡,即未连接的,未连接的网卡不生效。
[root@zutuanxue network-scripts]# nmcli device DEVICE TYPE STATE CONNECTION ens33 ethernet 已连接 ens33 ens37 ethernet 已断开 -- lo loopback 未托管 --
在日常使用中,这两个命令相互配合,通过nmcli device可以查看到有哪些网络设备被NetworkManager托管,通过nmcli connection控制网络设备的连接状态。
[root@zutuanxue ~]# nmcli ens33: 已连接 to ens33 #设备状态和名称 "Intel 82545EM" #设备型号 ethernet (e1000), 00:0C:29:11:47:97, 硬件, mtu 1500 ip4 默认 inet4 192.168.1.55/24 route4 0.0.0.0/0 route4 192.168.1.0/24 inet6 fe80::ea62:91c6:114:18bb/64 route6 fe80::/64 route6 ff00::/8
[root@zutuanxue ~]# nmcli connection add type ethernet con-name ens-test1 ifname ens37 ipv4.addresses 192.168.18.100/24 ipv4.gateway 192.168.18.1 ipv4.method manual 连接 "ens-test1" (da7fdc9a-e7cc-4a1c-8b2c-7751ed2fc4d2) 已成功添加。
[root@zutuanxue ~]# nmcli connection up ens-test1 连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/16)
[root@zutuanxue ~]# nmcli connection NAME UUID TYPE DEVICE ens33 b5ecf5... ethernet ens33 ens-test1 da7fdc... ethernet ens37 ens37 077945... ethernet --
[root@zutuanxue ~]# nmcli connection add type ethernet con-name ens-test2 ifname ens37 ipv4.method auto 连接 "ens-test2" (25b9dd2f-a4c0-452d-bd22-992cf12b55b2) 已成功添加。 [root@zutuanxue ~]# nmcli connection up ens-test2 连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/17) [root@zutuanxue ~]# nmcli connection NAME UUID TYPE DEVICE ens33 b5ec... ethernet ens33 ens-test2 25b9... ethernet ens37 ens37 0779... ethernet -- ens-test1 da7f... ethernet --
[root@zutuanxue ~]# nmcli connection edit ens-test1 nmcli> goto ipv4.addresses nmcli ipv4.addresses> change 编辑 "addresses" 值:192.168.20.100/24 您是否也要将 "ipv4.method" 设为 "manual"?[yes]:yes nmcli ipv4.addresses> back nmcli ipv4> save 成功地更新了连接 "ens-test1" (da7fdc9a-e7cc-4a1c-8b2c-7751ed2fc4d2)。 nmcli ipv4> activate 正在监视连接激活(按任意键继续) 连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/18) nmcli ipv4> quit [root@zutuanxue ~]# nmcli ens37: 已连接 to ens-test1 "Intel 82545EM" ethernet (e1000), 00:0C:29:11:47:A1, 硬件, mtu 1500 ip4 默认 inet4 192.168.20.100/24 route4 192.168.20.0/24 route4 192.168.18.1/32 route4 0.0.0.0/0 inet6 fe80::11c3:e0a4:f62e:9f31/64 route6 fe80::/64 route6 ff00::/8
[root@zutuanxue ~]# nmcli connection up ens-test1 连接已成功激活(D-Bus 活动路径:... [root@zutuanxue ~]# nmcli connection down ens-test1 成功停用连接 "ens-test1"(D-Bus 活动路...
[root@zutuanxue ~]# nmcli connection delete ens-test1 成功删除连接 "ens-test1" (4fc43f65-ea53-43a1-85d4-692e425fcd7d)。 [root@zutuanxue ~]# nmcli connection NAME UUID TYPE DEVICE ens33 b5ec...ethernet ens33 ens37 0779...ethernet ens37 [root@zutuanxue ~]# nmcli connection show NAME UUID TYPE DEVICE ens33 b5ec... ethernet ens33 ens37 0779... ethernet ens37
[root@zutuanxue ~]# nmcli connection reload
[root@zutuanxue ~]# nmcli connection load /etc/sysconfig/network-scripts/ifcfg-ens37
[root@zutuanxue ~]# nmcli connection up ens37 连接已成功激活(D-Bus 活动路径...
[root@zutuanxue ~]# nmcli device connect ens37 [root@zutuanxue ~]# nmcli device reapply ens37
[root@zutuanxue ~]# nmcli device DEVICE TYPE STATE CONNECTION ens37 ethernet 已连接 ens37 ens33 ethernet 已连接 ens33 lo loopback 未托管 -- [root@zutuanxue ~]# nmcli device show ens33 GENERAL.DEVICE: ens33 GENERAL.TYPE: ethernet GENERAL.HWADDR: 00:0C:29:11:47:97 GENERAL.MTU: 1500 GENERAL.STATE: 100(已连接) GENERAL.CONNECTION: ens33 GENERAL.CON-PATH: /org/freedesktop/NetworkMana... WIRED-PROPERTIES.CARRIER: 开 IP4.ADDRESS[1]: 192.168.1.55/24 IP4.GATEWAY: -- IP4.ROUTE[1]: dst = 192.168.1.0/24, nh = 0.0.0.0, mt = 102 IP4.DNS[1]: 202.106.0.20 IP4.DNS[2]: 114.114.114.114 IP6.ADDRESS[1]: fe80::ea62:91c6:114:18bb/64 IP6.GATEWAY: -- IP6.ROUTE[1]: dst = fe80::/64, nh = ::, mt = 102 IP6.ROUTE[2]: dst = ff00::/8, nh = ::, mt = 256, table=255
[root@zutuanxue ~]# nmcli device connect/disconnect ens37
[root@zutuanxue ~]# nmcli radio all on/off
[root@zutuanxue ~]# nmcli networking on/off
[root@zutuanxue ~]# nmcli monitor (ctrl+c结束) ens37: 停用中 网络管理器现在处于 "已连接(仅本地)" 状态 连接性现在是 "受限" ens37: 已断开
[root@zutuanxue ~]# nm-online 正在连接............... 30s [online]
[root@zutuanxue ~]# nmtui

[root@zutuanxue ~]# rpm -qa | grep cockpit cockpit-packagekit-184.1-1.el8.noarch cockpit-system-185-2.el8.noarch cockpit-185-2.el8.x86_64 cockpit-bridge-185-2.el8.x86_64 cockpit-ws-185-2.el8.x86_64 cockpit-storaged-184.1-1.el8.noarch [root@zutuanxue ~]# systemctl start cockpit


以上就是linux 网络管理的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号