nmcli Cheat Sheet

Most used
nmcli                                   # overview of every device and its connection
nmcli dev status                        # devices and their state
nmcli dev wifi list                     # visible Wi-Fi networks
nmcli dev wifi connect 'HomeNet' --ask  # join a network, prompt for the password
nmcli con show                          # saved connection profiles
sudo nmcli con up 'HomeNet'             # activate (or re-apply) a profile

nmcli controls NetworkManager, the network service on Ubuntu Desktop, Fedora, Linux Mint, openSUSE, Arch with a desktop and most other desktop installs. Ubuntu Server uses netplan with systemd-networkd instead, so check that NetworkManager is running first: systemctl is-active NetworkManager. Unlike the ip command, nmcli changes are saved in profiles and survive reboots. Objects and commands abbreviate: dev/d, con/c, show/s, modify/mod. Tab completion works for connection names.

Status and devices

CommandWhat it does
nmcliSummary of devices, addresses, routes and DNS
nmcli general statusOverall state and connectivity (full, limited, portal)
nmcli dev statusEach interface: type, state, active connection
nmcli dev show wlp2s0Addresses, gateway, DNS and MAC of one device
sudo nmcli dev connect enp3s0Activate the best profile on a device
sudo nmcli dev disconnect wlp2s0Disconnect and stop auto-connecting until told otherwise
sudo nmcli dev reapply enp3s0Apply profile changes without a full disconnect
nmcli radioWi-Fi and WWAN radio switches
nmcli radio wifi off / onTurn Wi-Fi off or on
sudo nmcli dev set enp3s0 managed noTell NetworkManager to leave an interface alone
nmcli monitorWatch state changes live

Wi-Fi

CommandWhat it does
nmcli dev wifi listNetworks in range with signal, channel and security
nmcli dev wifi rescanForce a new scan
nmcli dev wifi connect 'SSID' --askConnect and prompt for the password (keeps it out of shell history)
nmcli dev wifi connect 'SSID' password 'secret'Connect non-interactively
nmcli dev wifi connect 'SSID' --ask hidden yesConnect to a hidden network
nmcli dev wifi show-passwordShow the current network's password and a QR code
sudo nmcli dev wifi hotspot ssid MyHotspot password 'longpassword'Turn the Wi-Fi card into an access point
nmcli -f SSID,BSSID,CHAN,SIGNAL dev wifi listChoose columns (find the strongest access point)

If no networks appear at all, the problem is usually the driver or firmware; see Wi-Fi not working on Linux.

Connection profiles

CommandWhat it does
nmcli con showAll saved profiles (--active for active only)
nmcli con show 'NAME'Every setting of one profile
sudo nmcli con up 'NAME'Activate a profile (also re-applies edits)
sudo nmcli con down 'NAME'Deactivate it
sudo nmcli con mod 'NAME' connection.autoconnect noStop it connecting automatically
sudo nmcli con mod 'NAME' connection.autoconnect-priority 10Prefer this profile over others
sudo nmcli con mod 'Wired connection 1' connection.id officeRename a profile
sudo nmcli con delete 'NAME'Delete a profile (forget a network)
sudo nmcli con reloadRe-read profile files edited by hand
sudo nmcli con export 'VPN'Export a VPN profile
sudo nmcli con import type wireguard file wg0.confImport a WireGuard (or openvpn) config

Profiles are stored in /etc/NetworkManager/system-connections/ (keyfiles, readable by root only).

IP address, gateway and DNS

CommandWhat it does
sudo nmcli con mod 'NAME' ipv4.method manual ipv4.addresses 192.168.1.50/24 ipv4.gateway 192.168.1.1Static IPv4 address and gateway
sudo nmcli con mod 'NAME' ipv4.dns '1.1.1.1 9.9.9.9'Set DNS servers
sudo nmcli con mod 'NAME' ipv4.ignore-auto-dns yesUse only your DNS servers, not the ones DHCP hands out
sudo nmcli con mod 'NAME' +ipv4.addresses 192.168.1.51/24Add a second address (+ appends, - removes)
sudo nmcli con mod 'NAME' ipv4.method auto ipv4.addresses '' ipv4.gateway ''Back to DHCP
sudo nmcli con mod 'NAME' +ipv4.routes '10.20.0.0/16 192.168.1.5'Add a static route
sudo nmcli con mod 'NAME' ipv6.method disabledDisable IPv6 on this profile
sudo nmcli con mod 'NAME' 802-3-ethernet.mtu 9000Set MTU on a wired profile
sudo nmcli con add type ethernet ifname enp3s0 con-name lan ipv4.method manual ipv4.addresses 10.0.0.5/24Create a new wired profile from scratch

Changes to a profile take effect the next time it is activated, so finish with sudo nmcli con up 'NAME'. The static IP guide covers netplan and systemd-networkd too.

Common recipes

Switch the wired connection to a static address in one go and apply it:

nmcli -g NAME,DEVICE con show --active
sudo nmcli con mod 'Wired connection 1' \
  ipv4.method manual ipv4.addresses 192.168.1.50/24 \
  ipv4.gateway 192.168.1.1 ipv4.dns '192.168.1.1 1.1.1.1'
sudo nmcli con up 'Wired connection 1'

Show the address, gateway and DNS of the active connections in script-friendly form:

nmcli -g IP4.ADDRESS,IP4.GATEWAY,IP4.DNS dev show wlp2s0

Restart networking without rebooting:

sudo nmcli networking off && sudo nmcli networking on
sudo systemctl restart NetworkManager     # heavier: restarts the service

Fix DNS names not resolving on a connection (see Temporary failure in name resolution):

sudo nmcli con mod 'NAME' ipv4.dns '1.1.1.1 9.9.9.9' ipv4.ignore-auto-dns yes
sudo nmcli con up 'NAME'
resolvectl status

Set the hostname through NetworkManager:

sudo nmcli general hostname web01

Find NetworkManager's own log entries:

journalctl -u NetworkManager -b --no-pager | tail -50

Gotchas

  • Edits do not apply themselves. nmcli con mod only changes the saved profile. Run nmcli con up NAME or nmcli dev reapply DEV.
  • Profile names contain spaces. Quote them: 'Wired connection 1'. Use nmcli con show to get the exact name or UUID.
  • Over SSH, changing the IP drops your session. Have console access, or run the change with nohup or in tmux so it completes after you lose the connection.
  • Passwords on the command line. password 'secret' ends up in your shell history and in ps. Use --ask.
  • Not every interface is managed. On Ubuntu Server, netplan or systemd-networkd may own the interface and nmcli shows it as unmanaged. Edit /etc/netplan/*.yaml there instead.
  • Hotspot fails on some cards. The driver must support AP mode: check iw list | grep -A10 'Supported interface modes'.

Every setting is documented in nmcli(1) and nm-settings-nmcli(5) on the NetworkManager project site.

Frequently asked questions

How do I connect to Wi-Fi with nmcli?

List networks with nmcli dev wifi list, then run nmcli dev wifi connect 'SSID' --ask and type the password at the prompt. NetworkManager saves the profile and reconnects automatically.

How do I set a static IP with nmcli?

Modify the connection profile: sudo nmcli con mod 'NAME' ipv4.method manual ipv4.addresses 192.168.1.50/24 ipv4.gateway 192.168.1.1 ipv4.dns '1.1.1.1 9.9.9.9', then apply it with sudo nmcli con up 'NAME'.

How do I see a saved Wi-Fi password?

Run nmcli dev wifi show-password for the current network, or sudo nmcli -s -g 802-11-wireless-security.psk con show 'NAME' for any saved profile.

What is the difference between a device and a connection in nmcli?

A device is a network interface such as wlp2s0. A connection is a saved profile of settings (SSID, password, IP method) that NetworkManager activates on a device. One device can have many profiles.

Is there a menu version of nmcli?

Yes, nmtui gives a text menu for editing connections, activating them and setting the hostname. It ships with NetworkManager on most distros (package network-manager or NetworkManager-tui).

Spotted a mistake or a command that no longer works? Send a correction — pages are re-checked when reports come in.