获取命令帮助

# nmcli help
# nmcli general help

显示网卡链接情况

# nmcli connection show
NAME                UUID                                  TYPE      DEVICE 
Wired connection 1  4e1e3b02-517c-3ca6-9f99-f217f49c33f0  ethernet  enp0s8 
enp0s3              c02f0099-e58b-4a2d-91ea-f0b2a896e617  ethernet  enp0s3 


#仅显示活动链接
# nmcli connection show --active
NAME                UUID                                  TYPE      DEVICE 
Wired connection 1  4e1e3b02-517c-3ca6-9f99-f217f49c33f0  ethernet  enp0s8 
enp0s3              c02f0099-e58b-4a2d-91ea-f0b2a896e617  ethernet  enp0s3 

显示网卡设备详情

# 查看全部网卡配置
# nmcli device show
#单独查看enp0s3网卡配置
# nmcli device show enp0s3
GENERAL.DEVICE:                         enp0s3
GENERAL.TYPE:                           ethernet
GENERAL.HWADDR:                         08:00:27:96:9E:12
GENERAL.MTU:                            1500
GENERAL.STATE:                          100 (connected)
GENERAL.CONNECTION:                     enp0s3
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/ActiveConnection/6
WIRED-PROPERTIES.CARRIER:               on
IP4.ADDRESS[1]:                         192.168.1.11/24
IP4.GATEWAY:                            192.168.1.1
IP4.ROUTE[1]:                           dst = 192.168.1.0/24, nh = 0.0.0.0, mt = 102
IP4.ROUTE[2]:                           dst = 0.0.0.0/0, nh = 192.168.1.1, mt = 102
IP4.DNS[1]:                             192.168.1.1
IP6.ADDRESS[1]:                         fe80::3063:8496:e488:fd4/64
IP6.GATEWAY:                            --
IP6.ROUTE[1]:                           dst = fe80::/64, nh = ::, mt = 102
IP6.ROUTE[2]:                           dst = ff00::/8, nh = ::, mt = 256, table=255

添加网卡配置

# nmcli connection add type ethernet ifname enp0s9
# 可指定IP等信息
# nmcli connection add type ethernet ifname enp0s9 ipv4.address 10.10.10.10/24 \
ipv4.gateway 10.10.10.254 \
ipv4.method manual
Connection 'ethernet-enp0s9' (c08d023f-dce4-4e91-8fa5-22ea49fdf15b) successfully added.

启动网卡

# nmcli connection up ethernet-enp0s9 
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/9)

修改IP地址

# nmcli connection modify ethernet-enp0s9 ipv4.address 172.25.0.100/24

修改dns

# nmcli con mod test-lab ipv4.dns "8.8.8.8 8.8.4.4"

修改获取IP模式

# nmcli connection modify ethernet-enp0s9 ipv4.method manual
# DHCP=atuo|STATIC=manual

重启网卡连接读取配置

# nmcli connection down ethernet-enp0s9 && nmcli connection up ethernet-enp0s9
Connection 'ethernet-enp0s9' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/11)
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/12)

删除网卡

# nmcli connection down ethernet-enp0s9 && nmcli connection delete ethernet-enp0s9