格式:nmcli [OPTIONS…] {connection | device} [COMMAND] [ARGUMENTS…]
device – 显示和管理网络接口;可简写成“dev”
status:查看网路接口状态
show interface:查看指定网络接口属性信息;不指定接口显示所有接口属性信息
connection – 启动、停止和管理网络连接;可简写成“con”
show:查看当前所有可用状态的连接
up interface:激活(更新)指定接口
down interface:禁用指定接口
modify interface [+|-]setting.property value:配置IP地址等属性;此配置同时写入接口配置文件中,永久有效。配置后执行(nmcli con up interface)使之生效;
[+|-]:原有的基础上增加或删除指定属性;按需使用
setting.property:
ipv4.addresses 0.0.0.0/0:配置v4地址
ipv4.gateway:配置v4网关
ipv4.dns:配置DNS地址;多地址用空格隔开加引号
device – 显示和管理网络接口;可简写成“dev”
status:查看网路接口状态
show interface:查看指定网络接口属性信息;不指定接口显示所有接口属性信息
connection – 启动、停止和管理网络连接;可简写成“con”
show:查看当前所有可用状态的连接
up interface:激活(更新)指定接口
down interface:禁用指定接口
modify interface [+|-]setting.property value:配置IP地址等属性;此配置同时写入接口配置文件中,永久有效。配置后执行(nmcli con up interface)使之生效;
[+|-]:原有的基础上增加或删除指定属性;按需使用
setting.property:
ipv4.addresses 0.0.0.0/0:配置v4地址
ipv4.gateway:配置v4网关
ipv4.dns:配置DNS地址;多地址用空格隔开加引号
status:查看网路接口状态
[root@localhost ~]# nmcli dev status DEVICE TYPE STATE CONNECTION eno16777736 ethernet connected eno16777736 lo loopback unmanaged --
show interface:查看指定网络接口状态信息;不指定接口显示所有接口状态信息
[root@localhost ~]# nmcli dev show eno16777736 GENERAL.DEVICE: eno16777736 GENERAL.TYPE: ethernet GENERAL.HWADDR: 00:0C:29:BA:B7:75 GENERAL.MTU: 1500 GENERAL.STATE: 100 (connected) GENERAL.CONNECTION: eno16777736 GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1 WIRED-PROPERTIES.CARRIER: on IP4.ADDRESS[1]: 192.168.1.251/24 IP4.GATEWAY: 192.168.1.1 IP4.DNS[1]: 61.177.7.1 IP6.ADDRESS[1]: fe80::20c:29ff:feba:b775/64 IP6.GATEWAY:
show:查看当前所有可用状态的连接
[root@localhost ~]# nmcli con show NAME UUID TYPE DEVICE eno16777736 3995f76e-6a53-4eb1-afbc-9bedae0e1318 802-3-ethernet eno16777736
up interface:激活(更新)指定接口
[root@localhost ~]# nmcli con up eno16777736 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)
modify interface [+|-]setting.property value:配置IP地址等属性;此配置同时写入接口配置文件中,永久有效。配置后执行(nmcli con up interface)使之生效;
ipv4.addresses 0.0.0.0/0:配置v4地址
ipv4.addresses 0.0.0.0/0:配置v4地址
[root@localhost ~]# nmcli con mod eno16777736 ipv4.address 192.168.1.249/24 [root@localhost ~]# nmcli con up eno16777736 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3) [root@localhost ~]# nmcli dev sh eno16777736 GENERAL.DEVICE: eno16777736 GENERAL.TYPE: ethernet GENERAL.HWADDR: 00:0C:29:BA:B7:75 GENERAL.MTU: 1500 GENERAL.STATE: 100 (connected) GENERAL.CONNECTION: eno16777736 GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/3 WIRED-PROPERTIES.CARRIER: on IP4.ADDRESS[1]: 192.168.1.249/24 IP4.GATEWAY: 192.168.1.1 IP4.DNS[1]: 61.177.7.1 IP6.ADDRESS[1]: fe80::20c:29ff:feba:b775/64 IP6.GATEWAY:
ipv4.gateway:配置v4网关
[root@localhost ~]# nmcli con mod eno16777736 ipv4.gateway 192.168.1.254 [root@localhost ~]# nmcli con up eno16777736 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5) [root@localhost ~]# nmcli dev show eno16777736 GENERAL.DEVICE: eno16777736 GENERAL.TYPE: ethernet GENERAL.HWADDR: 00:0C:29:BA:B7:75 GENERAL.MTU: 1500 GENERAL.STATE: 100 (connected) GENERAL.CONNECTION: eno16777736 GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/5 WIRED-PROPERTIES.CARRIER: on IP4.ADDRESS[1]: 192.168.1.251/24 IP4.GATEWAY: 192.168.1.254 IP4.DNS[1]: 61.177.7.1 IP6.ADDRESS[1]: fe80::20c:29ff:feba:b775/64 IP6.GATEWAY:
ipv4.dns:配置DNS地址;多地址用空格隔开加引号
[root@localhost ~]# nmcli con mod eno16777736 ipv4.dns 192.168.1.1 [root@localhost ~]# nmcli con up eno16777736 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7) [root@localhost ~]# nmcli dev show eno16777736 GENERAL.DEVICE: eno16777736 GENERAL.TYPE: ethernet GENERAL.HWADDR: 00:0C:29:BA:B7:75 GENERAL.MTU: 1500 GENERAL.STATE: 100 (connected) GENERAL.CONNECTION: eno16777736 GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/7 WIRED-PROPERTIES.CARRIER: on IP4.ADDRESS[1]: 192.168.1.251/24 IP4.GATEWAY: 192.168.1.1 IP4.DNS[1]: 192.168.1.1 IP6.ADDRESS[1]: fe80::20c:29ff:feba:b775/64 IP6.GATEWAY: [root@localhost ~]# nmcli con mod eno16777736 ipv4.dns "61.177.7.1 221.228.255.1" [root@localhost ~]# nmcli con up eno16777736 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/8) [root@localhost ~]# nmcli dev show eno16777736 GENERAL.DEVICE: eno16777736 GENERAL.TYPE: ethernet GENERAL.HWADDR: 00:0C:29:BA:B7:75 GENERAL.MTU: 1500 GENERAL.STATE: 100 (connected) GENERAL.CONNECTION: eno16777736 GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/8 WIRED-PROPERTIES.CARRIER: on IP4.ADDRESS[1]: 192.168.1.251/24 IP4.GATEWAY: 192.168.1.1 IP4.DNS[1]: 61.177.7.1 IP4.DNS[2]: 221.228.255.1 IP6.ADDRESS[1]: fe80::20c:29ff:feba:b775/64 IP6.GATEWAY:
[+|-]:原有的基础上增加或删除指定属性;按需使用,下面以增加IP地址和删除DNS演示
[root@localhost ~]# nmcli con mod eno16777736 +ipv4.address 192.168.1.250/24 [root@localhost ~]# nmcli con up eno16777736 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/9) [root@localhost ~]# nmcli dev show eno16777736 GENERAL.DEVICE: eno16777736 GENERAL.TYPE: ethernet GENERAL.HWADDR: 00:0C:29:BA:B7:75 GENERAL.MTU: 1500 GENERAL.STATE: 100 (connected) GENERAL.CONNECTION: eno16777736 GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/9 WIRED-PROPERTIES.CARRIER: on IP4.ADDRESS[1]: 192.168.1.251/24 IP4.ADDRESS[2]: 192.168.1.250/24 IP4.GATEWAY: 192.168.1.1 IP4.DNS[1]: 61.177.7.1 IP4.DNS[2]: 221.228.255.1 IP6.ADDRESS[1]: fe80::20c:29ff:feba:b775/64 IP6.GATEWAY: [root@localhost ~]# nmcli con mod eno16777736 -ipv4.dns 221.228.255.1 [root@localhost ~]# nmcli con up eno16777736 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/10) [root@localhost ~]# nmcli dev show eno16777736 GENERAL.DEVICE: eno16777736 GENERAL.TYPE: ethernet GENERAL.HWADDR: 00:0C:29:BA:B7:75 GENERAL.MTU: 1500 GENERAL.STATE: 100 (connected) GENERAL.CONNECTION: eno16777736 GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/10 WIRED-PROPERTIES.CARRIER: on IP4.ADDRESS[1]: 192.168.1.251/24 IP4.ADDRESS[2]: 192.168.1.250/24 IP4.GATEWAY: 192.168.1.1 IP4.DNS[1]: 61.177.7.1 IP6.ADDRESS[1]: fe80::20c:29ff:feba:b775/64 IP6.GATEWAY: