nmcli命令配置网络

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

首先执行systemctl status NetworkManager命令查看服务是否开启,该命令需要在服务开启才可以执行。

1.添加静态网络

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

   

参数信息说明:

add==> 添加   type 网络类型为==>ethernet   con-name==> 网络名  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

 

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>  

将静态连接方式修改成动态连接
nmcli connection modify eth0 ipv4.method auto
nmcli connection reload
将动态连接方式修改为静态连接方式
nmcli connection delete eth0
nmcli connection add type ethernet con-name eth0 ifname eth0 autoconnect yes 建立动态ip
nmcli connection modify eth0 ipv4.addresses 172.25.254.210/24修改为指定静态ip
nmcli connection modify eth0 ipv4.method manual    
nmcli connection down eth0
nmcli connection up eth0
ifconfig eth0

8.开启,断开设备

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

9.显示设备状态

nmcli device status  

         

  


 
 

猜你喜欢

转载自blog.csdn.net/weixin_43273168/article/details/83350650