nmcli
命令的全称network manager client
一台设备如果想要上网,首先需要一块网卡,还需要与之绑定的网络连接(会话)描述文件。
nmcli:主要的功能就是对系统中网卡和会话进行管理
# 使用nmcli展示网卡信息以及会话信息
# 展示网卡的网络信息
[root@RHEL9 ~]# nmcli device show
GENERAL.DEVICE: enp0s5
GENERAL.TYPE: ethernet
GENERAL.HWADDR: 00:1C:42:3A:68:14
GENERAL.MTU: 1500
GENERAL.STATE: 100 (connected)
GENERAL.CONNECTION: enp0s5
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveC>
WIRED-PROPERTIES.CARRIER: on
IP4.ADDRESS[1]: 172.25.254.7/24
IP4.GATEWAY: 172.25.254.1
IP4.ROUTE[1]: dst = 172.25.254.0/24, nh = 0.0.0.0, mt>
IP4.ROUTE[2]: dst = 0.0.0.0/0, nh = 172.25.254.1, mt >
IP4.DNS[1]: 172.25.254.1
.....
# 展示系统中网卡数量及状态
[root@RHEL9 ~]# nmcli device status
DEVICE TYPE STATE CONNECTION
enp0s5 ethernet connected enp0s5
lo loopback connected (externally) lo
# 获取Connection的信息
[root@RHEL9 ~]# nmcli connection show
NAME UUID TYPE DEVICE
enp0s5 6e463271-224b-3c0f-b7e0-70aef397277a ethernet enp0s5
lo 4d63ebd2-72a8-4253-8491-c85f9a8160a2 loopback lo
# 新建Connection配置自动获取ip
# con-name haha 会话名称为haha type ethernet 会话类型:以太网 ifname enp0s5 使用的网卡为enp0s5
# ipv4.method auto 上网方式自动
# 一块网卡可以有多个会话文件,但是同时只能使用一个会话
[root@localhost ~]# nmcli connection add con-name haha type ethernet ifname enp0s5 ipv4.method auto
连接 "haha" (598afc3a-2013-4fe7-8107-d41aa1898569) 已成功添加。
# 新建Connection设置静态ip
# 手动 :ipv4.method manual 设置ip及掩码:ipv4.addresses 172.25.254.100/24
# 设置网关:ipv4.gateway 172.25.254.1 设置dns: ipv4.dns 114.114.114.114
[root@RHEL9 ~]# nmcli connection modify con-name hehe type ethernet ifname enp0s5 ipv4.method manual ipv4.addresses 172.25.254.100/24 ipv4.gateway 172.25.254.1 ipv4.dns 114.114.114.114
# 激活会话
[root@RHEL9 ~]# nmcli connection up hehe
# 修改Connection
[root@RHEL9 ~]# nmcli c modify hehe ipv4.method manual
[root@RHEL9 ~]# nmcli connection up hehe
# 添加多个ip
[root@localhost ~]# nmcli c m hehe +ipv4.addresses 172.25.254.7/24
[root@localhost ~]# nmcli c up hehe
# 删除Connection
[root@RHEL9 ~]# nmcli connection delete 22d8ebe3-41e9-42b5-9922-05d3198f5595
成功删除连接 "hehe" (22d8ebe3-41e9-42b5-9922-05d3198f5595)。
ping
ping命令可以判断,当前设备和互联网中某个服务器是否能够联通
# icmp就是ping命令发送的消息包
# icmp_seq 包序号
# 64 比特 包大小
# ttl:time to live(生存次数),消息包没经过一个路由器 就会ttl-1 当ttl归0时,消息包将不再继续传递。
# 时间=1.82 毫秒:是消息包发送给对方,对方又反馈回来整套流程小好的时间。
[root@localhost ~]# ping www.sina.com
PING spool.grid.sinaedge.com (36.159.95.166) 56(84) 比特的数据。
64 比特,来自 36.159.95.166 (36.159.95.166): icmp_seq=1 ttl=128 时间=1.82 毫秒
64 比特,来自 36.159.95.166 (36.159.95.166): icmp_seq=2 ttl=128 时间=1.98 毫秒
64 比特,来自 36.159.95.166 (36.159.95.166): icmp_seq=3 ttl=128 时间=1.81 毫秒
64 比特,来自 36.159.95.166 (36.159.95.166): icmp_seq=4 ttl=128 时间=0.836 毫秒
# -c:可以控制ping命令ping多少次
[root@localhost ~]# ping -c 4 www.sina.com
PING spool.grid.sinaedge.com (36.159.95.166) 56(84) 比特的数据。
64 比特,来自 36.159.95.166 (36.159.95.166): icmp_seq=1 ttl=128 时间=1.25 毫秒
64 比特,来自 36.159.95.166 (36.159.95.166): icmp_seq=2 ttl=128 时间=1.44 毫秒
64 比特,来自 36.159.95.166 (36.159.95.166): icmp_seq=3 ttl=128 时间=0.790 毫秒
64 比特,来自 36.159.95.166 (36.159.95.166): icmp_seq=4 ttl=128 时间=1.50 毫秒
--- spool.grid.sinaedge.com ping 统计 ---
已发送 4 个包, 已接收 4 个包, 0% packet loss, time 3003ms
rtt min/avg/max/mdev = 0.790/1.243/1.500/0.277 ms
# -b:设置消息包大小
[root@localhost ~]# ping -s 1000 www.sina.com
PING spool.grid.sinaedge.com (36.159.95.166) 1000(1028) 比特的数据。
1008 比特,来自 36.159.95.166 (36.159.95.166): icmp_seq=1 ttl=128 时间=1.20 毫秒
1008 比特,来自 36.159.95.166 (36.159.95.166): icmp_seq=2 ttl=128 时间=1.07 毫秒
1008 比特,来自 36.159.95.166 (36.159.95.166): icmp_seq=3 ttl=128 时间=1.06 毫秒
# -i 修改ping包之间的时间间隔
[root@localhost ~]# ping -i 3 www.sina.com
PING spool.grid.sinaedge.com (36.159.95.166) 56(84) 比特的数据。
64 比特,来自 36.159.95.166 (36.159.95.166): icmp_seq=1 ttl=128 时间=0.688 毫秒
64 比特,来自 36.159.95.166 (36.159.95.166): icmp_seq=2 ttl=128 时间=0.895 毫秒
64 比特,来自 36.159.95.166 (36.159.95.166): icmp_seq=3 ttl=128 时间=0.999 毫秒
nmtui
nmtui 是 Linux 系统中基于文本界面(TUI)的网络管理工具,属于 NetworkManager 的一部分。它允许用户通过简单的菜单操作配置网络连接,无需手动编辑配置文件或记忆复杂的命令行参数。通过 nmtui
,用户可快速完成网络配置,尤其适合不熟悉命令行的场景。如需更高级操作(如批量配置),可结合 nmcli
工具