nmcli - NetworkManager Command-Line Interface

mail

How to declare / update DNS resolvers ?

Change settings (source) :

Reload settings

Looks like this command is not available on old versions of NetworkManager, such as in RHEL 7.
mail

nmcli

Usage

nmcli is the NetworkManager Command-Line Interface

Flags

Parent command Options Usage
connection
conn
con
down deactivate the specified active connection(s)
modify / mod add / modify / remove properties in the connection profile
reload reload all connection files from disk
NetworkManager does not monitor changes to connection. So you need to run this command so that NetworkManager reloads the connection profiles from disk when a change is made.
show --active list active connections only
--order [options]
  • sort connections by :
    • active status
    • name
    • type
  • defaults to active:name:path
  • may be prefixed by :
    • + or nothing : sort ascending
    • - : sort descending
up activate a connection
device (none) / status (default action) print status of devices
reapply ifName attempt to update device ifName with changes to the currently active connection made since it was last applied
This is not available on RHEL < 7.3
general (none) / status (default action) show overall status of NetworkManager
reload (none) reload NetworkManager's configuration and perform certain updates, like flushing caches or rewriting external state to disk
conf reload NetworkManager's configuration from disk, except for connections. To do so, run nmcli con reload
dns-rc update DNS configuration, which usually involves writing /etc/resolv.conf anew
mail

How to change the IP address of a connection ?

  1. nmcli con down myConnection
  2. nmcli con mod myConnection ipv4.addresses "10.27.26.44/27"
  3. nmcli con up myConnection
I'm not 100% sure the down + up is necessary.
mail

How to delete a connection ?

nmcli connection delete connectionToDelete
mail

How to view details of a connection ?

  1. list connections to retrieve the connection name
  2. nmcli con show connectionName
  3. The command above outputs a lot of information, and it is necessary to grep to find what you're looking for :
    • the IP addresses affected to the connection :
      nmcli con show myConnection | grep addresses
      ipv4.addresses:			12.34.56.78/32
      ipv6.addresses:			--
    • some DHCP settings :
      nmcli con show myDhcpConnection | grep -E 'DHCP4.*address'
      DHCP4.OPTION[1]:		broadcast_address = 192.168.1.255
      DHCP4.OPTION[7]:		ip_address = 192.168.1.103
      DHCP4.OPTION[9]:		requested_broadcast_address = 1
    • IPv4 DNS settings :
      nmcli con show myConnection | grep 'ipv4\.dns'
      ipv4.dns:                               12.34.56.78,12.34.56.79
      ipv4.dns-search:                        myCompany.tld
      ipv4.dns-options:                       (default)
      ipv4.dns-priority:                      0
mail

How to list connections and retrieve a connection name ?

List connections :

NAME		UUID					TYPE		DEVICE
myEssid		6ae98f8f-4d42-8db8-7a8a-29b931a57157	wifi		wlo1
tun0		032e09f7-badd-39d6-4623-02e0c22a66b4	tun		tun0
netplan-eno2	b180a970-372e-e833-8635-ff1f330b7d90	ethernet	--
The connection name is often set equal to the device it applies to, which I find particularly misleading and I discourage.

List connections by type :

NAME			UUID					TYPE		DEVICE
eth0			5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03	802-3-ethernet	eth0
br-d18efa87a21a		d2f29960-dc17-43b9-91e8-f55fbe3a8f4b	bridge		br-d18efa87a21a
docker0			cfd3bb11-9e20-43ca-a901-3480cbf7fcab	bridge		docker0
br-6a59b1f211e9		436c0a45-09dc-49c1-affe-df222a871acc	bridge		br-6a59b1f211e9