Network

The nmcli command

Controls NetworkManager from the terminal: shows interface status, lists wifi networks, activates and deactivates profiles and changes their settings. It is the console alternative to the desktop network icon.

Syntax

nmcli [opciones] objeto comandoTry it in the terminal →

Most useful options

-tCompact output, with fields separated by colons. Made for scripts
-f <campos>Chooses the columns to show, for example -f NAME,TYPE
-g <campos>Returns only the value of those fields, without a header. Ideal to store in a variable
-a--ask: asks for what is missing, such as the password, instead of leaving it in the history
-sAlso shows stored secrets, such as the wifi key (with show)
-w <segundos>Maximum wait time for an operation, such as connecting

Copy-ready examples

$ nmcli device statusstatus of each interface: connected, disconnected or unmanaged.

Example output

DEVICE   TYPE      STATE         CONNECTION
enp3s0   ethernet  connected     Casa
wlp2s0   wifi      disconnected  --
lo       loopback  unmanaged     --
$ nmcli -f SSID,SIGNAL,SECURITY dev wifi listwifi networks in range, with their signal (0 to 100) and security.

Example output

SSID        SIGNAL  SECURITY
Casa        82      WPA2
Vecinos-5G  45      WPA2 WPA3
Invitados   30      --
$ nmcli --ask dev wifi connect Casaconnects to the Casa network and asks for the password by keyboard, without leaving it written in the history.
$ nmcli -t -f NAME,TYPE con showsaved profiles in compact format, ready for a script.

Example output

Casa:802-11-wireless
enp3s0-cable:802-3-ethernet
$ nmcli -g IP4.ADDRESS dev show enp3s0the current IPv4 address of the interface, without headers.

Example output

192.168.1.20/24

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
Error: No network with SSID 'Casa' found.The network is out of range or missing from the last scan. Check capitals and spaces in the name too.Refresh the list with nmcli dev wifi rescan, wait a few seconds and retry with the exact name from nmcli -f SSID dev wifi list.

Typical mistakes

  • A change to a profile does not apply until you reactivate it: after modifying it, run nmcli con up NAME.
  • Without --ask, nmcli dev wifi connect leaves the password in the shell history.

Differences from similar commands

  • ip: shows and changes addresses and routes at a low level, without profiles. A change made with ip is lost on reconnect, because NetworkManager applies its configuration again.

Security

wifi profiles store the key in /etc/NetworkManager/system-connections, readable only by root. nmcli -s prints it on screen, so do not use it where others can see or in screenshots. And a password typed on the command line stays in the shell history: that is why --ask is better on shared machines.

Related commands

FAQ

How do I see a saved wifi key?

With sudo nmcli -s -g 802-11-wireless-security.psk con show NAME. Do it only for your own networks: the key is the secret that protects access.

Why does my wifi show as disconnected even though I can see the network?

Because the interface is free and has no active profile. Activate one with nmcli con up NAME or connect with nmcli dev wifi connect SSID.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course