在现代社会,网络已成为人们生活中不可或缺的一部分。对于操作系统而言,网络功能的支持和管理显得尤为重要。本节课我们将探讨如何在centos8中管理网络。
NetworkManager和常用工具及其基本用法
NetworkManager介绍
在Linux系统中,传统的网络管理方式是通过名为”network”的服务来实现的。在CentOS7中仍然可以看到这个服务,但在CentOS8中已不再使用”network”服务,取而代之的是”NetworkManager”服务。NetworkManager服务简化了有线和无线连接的管理工作,并且能够管理各种类型的网络,包括物理网卡、虚拟网卡、以太网和非以太网等。
常用工具
nmcli:命令行工具nmtui:文本图形界面工具cockpit:基于web的管理工具
nmcli基本用法
nmcli命令的使用类似于Linux中之前的ip命令,支持tab补全,并且可以通过-h或--help获取帮助信息。
[root@zutuanxue ~]# nmcli -h[root@zutuanxue ~]# nmcli connection -h
可以看到,不同阶段获取的帮助内容有所不同,具体用法将在后续详细介绍。nmcli工具有两个常用命令:
nmcli connection(nmcli c):与连接相关的操作
[root@zutuanxue network-scripts]# nmcli connectionNAME UUID TYPE DEVICEens33 b5ecf570-543c-4da7-b082-bdc073b56acb ethernet ens33ens37 077945cb-1d12-4c06-bba3-562426336b67 ethernet --
在查看时,有颜色的字体标注的是处于活跃状态的网卡,即已连接的;正常颜色的字体标记的是非活跃状态的网卡,即未连接的,未连接的网卡不生效。
乾坤圈新媒体矩阵管家
新媒体账号、门店矩阵智能管理系统
17 查看详情
nmcli device(nmcli d):与设备相关的操作
[root@zutuanxue network-scripts]# nmcli deviceDEVICE TYPE STATE CONNECTIONens33 ethernet 已连接 ens33ens37 ethernet 已断开 --lo loopback 未托管 --
在日常使用中,这两个命令相互配合,通过nmcli device可以查看到有哪些网络设备被NetworkManager托管,通过nmcli connection控制网络设备的连接状态。
使用nmcli命令设置网卡信息
查看网卡信息
[root@zutuanxue ~]# nmcliens33: 已连接 to ens33#设备状态和名称"Intel 82545EM"#设备型号ethernet (e1000), 00:0C:29:11:47:97, 硬件, mtu 1500ip4 默认inet4 192.168.1.55/24route4 0.0.0.0/0route4 192.168.1.0/24inet6 fe80::ea62:91c6:114:18bb/64route6 fe80::/64route6 ff00::/8
为网卡设置静态IP
[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 connectionNAME UUID TYPE DEVICEens33 b5ecf5... ethernet ens33ens-test1 da7fdc... ethernet ens37ens37 077945... ethernet --
为网卡设置动态IP
[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 connectionNAME UUID TYPE DEVICEens33 b5ec... ethernet ens33ens-test2 25b9... ethernet ens37ens37 0779... ethernet --ens-test1 da7f... ethernet --
交互式设置IP地址
[root@zutuanxue ~]# nmcli connection edit ens-test1nmcli> goto ipv4.addressesnmcli ipv4.addresses> change编辑 "addresses" 值:192.168.20.100/24您是否也要将 "ipv4.method" 设为 "manual"?[yes]:yesnmcli ipv4.addresses> backnmcli ipv4> save成功地更新了连接 "ens-test1" (da7fdc9a-e7cc-4a1c-8b2c-7751ed2fc4d2)。nmcli ipv4> activate正在监视连接激活(按任意键继续)连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/18)nmcli ipv4> quit[root@zutuanxue ~]# nmcliens37: 已连接 to ens-test1"Intel 82545EM"ethernet (e1000), 00:0C:29:11:47:A1, 硬件, mtu 1500ip4 默认inet4 192.168.20.100/24route4 192.168.20.0/24route4 192.168.18.1/32route4 0.0.0.0/0inet6 fe80::11c3:e0a4:f62e:9f31/64route6 fe80::/64route6 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 connectionNAME UUID TYPE DEVICEens33 b5ec...ethernet ens33ens37 0779...ethernet ens37[root@zutuanxue ~]# nmcli connection showNAME UUID TYPE DEVICEens33 b5ec... ethernet ens33ens37 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 deviceDEVICE TYPE STATE CONNECTIONens37 ethernet 已连接 ens37ens33 ethernet 已连接 ens33lo loopback 未托管 --[root@zutuanxue ~]# nmcli device show ens33GENERAL.DEVICE: ens33GENERAL.TYPE: ethernetGENERAL.HWADDR: 00:0C:29:11:47:97GENERAL.MTU: 1500GENERAL.STATE: 100(已连接)GENERAL.CONNECTION: ens33GENERAL.CON-PATH: /org/freedesktop/NetworkMana...WIRED-PROPERTIES.CARRIER: 开IP4.ADDRESS[1]: 192.168.1.55/24IP4.GATEWAY: --IP4.ROUTE[1]: dst = 192.168.1.0/24, nh = 0.0.0.0, mt = 102IP4.DNS[1]: 202.106.0.20IP4.DNS[2]: 114.114.114.114IP6.ADDRESS[1]: fe80::ea62:91c6:114:18bb/64IP6.GATEWAY: --IP6.ROUTE[1]: dst = fe80::/64, nh = ::, mt = 102IP6.ROUTE[2]: dst = ff00::/8, nh = ::, mt = 256, table=255
连接/断开网卡
[root@zutuanxue ~]# nmcli device connect/disconnect ens37
开启/关闭无线网络
[root@zutuanxue ~]# nmcli radio all on/off
开启/关闭NetworkManager的网络管理功能
[root@zutuanxue ~]# nmcli networking on/off
监控网络状态
[root@zutuanxue ~]# nmcli monitor (ctrl+c结束)ens37: 停用中网络管理器现在处于 "已连接(仅本地)" 状态连接性现在是 "受限"ens37: 已断开
询问NetworkManager网络连接状态(默认等待30秒)
[root@zutuanxue ~]# nm-online正在连接............... 30s [online]
使用其他网络管理方式配置网络
nmtui
[root@zutuanxue ~]# nmtui

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


以上就是linux 网络管理的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/463952.html
微信扫一扫
支付宝扫一扫