在进行操作之前,我们要先开启network服务才能进行操作

systemctl start NetworkManager.service


通过nmcli查看网络信息

要显示所有连接的列表,可以使用 nmcli connection show

如果仅仅需要查看正在活动的连接,可用nmcli connection show --active

nmcli命令管理网络

指定连接名称,查看该连接的详情信息 nmcli connection show “xxx”

nmcli命令管理网络

显示设备状态 nmcli device status xxx

查看设备信息 nmcli device show xxx

nmcli命令管理网络

 

通过nmcli创建网络连接

定义一个新连接westos:它将使用dhcp通过eth0设备的以太网连接自动连接

nmcli connection add con-name "westos" type ethernet ifname eth0

nmcli命令管理网络

定义一个新连接redhat:并指定ip地址和网关

nmcli connection add con-name "redhat" ifname eth0  type ethernet ip4 172.25.254.2/24

nmcli命令管理网络

通过nmcli修改网络连接

nmcli connection modify "westos" ipv4.addresses xxx.xxx.xxx.xxx/24 ---- 改变wetos的ip

nmcli connection modify "westos" ipv4.method <auto|manual> ---- 改变westos的工作方式为动态或者静态

nmcli命令管理网络

nmcli connection down westos ---- 关闭指定链接

nmcli connection delete westos ---- 删除westos链接

nmcli命令管理网络

nmcli命令摘要

命令 用途
nmcli device status 列出所有设备
nmcli connection show 列出所有连接
nmcli connection up "ID" **连接
nmcli connection down "ID" 取消**连接,如果自动重新连接为是,则该连接将重新启动
nmcli device disconnect DEVICENAME 中断接口,并且暂时禁用自动连接
nmcli net off 禁用所有管理接口
nmcli connection add 添加新连接
nmcli connection modify "ID" ... 修改连接参数
nmcli connection del "ID"

删除连接

 

相关文章: