Linux_nmcli命令配置网络

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sr_1114/article/details/83342536

nmcli命令配置网络

要配置网卡的IP地址除了图形方式和编辑文本的方式,还可以通过nmcli命令配置,以下是常用的nmcli命令配置网络的方式。
1.添加静态网络

nmcli connection add type ethernet con-name westos ifname eth0 ip4 172.25.254.161/24

add #添加
type #网络类型,为ethernet
conname #网络名
ifname #指定网卡
172.25.254.161/24 #添加的IP地址,子网掩码为255.255.255.0
在这里插入图片描述

2.添加dhcp动态网络

nmcli connection add type ethernet con-name westos ifname eth0 autoconnect yes

在重启网络之后会在dhcp服务器上自动获取IP在这里插入图片描述

3.删除网络连接

nmcli connection delete westos

在删除westos链接之后,eth0上的ip就没有了
在这里插入图片描述

4.显示所有网络链接

nmcli connection show 

在这里插入图片描述
从上图中可以看到在添加westos网络链接之后,此命令可以查看。
5.关闭网络链接

nmcli connection down westos

关闭westos的网络链接之后,可以查看到westos网络,但是与eth0网卡断开了链接
在这里插入图片描述

6.开启指定的网络链接

nmcli connection up westos

在开启westos网络链接之后,wetsos网络与eth0网卡链接成功
在这里插入图片描述

7.修改网络链接的类型

nmcli connection modify "westos" ipv4.method <auto|manual>	

静态网络可以改为动态网络
动态网络在修改为静态网络之前,网络链接必须有IP地址
在这里插入图片描述
在这里插入图片描述

8.开启,断开设备

nmcli device connect eth0		#开启eth0
nmcli device disconnect eth0	#断开eth0

在这里插入图片描述
9.显示设备状态

nmcli device status			

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/sr_1114/article/details/83342536