nmcli and nmtui (1/2)
nmcli is the command-line client of NetworkManager, the daemon that manages networking on Fedora, RHEL and Ubuntu desktops/servers. Part 1 covers global output options, general, networking, radio, monitor and everything about connection profiles: show, add, up/down, modify, types, edit/clone/delete and reload/import.
25.1 How it works: daemon, device, connection
- The NetworkManager daemon does the real work; nmcli and nmtui only talk to it over D-Bus.
- Device = the real interface (eth1, wlan0). Connection = a saved profile with IP, gateway, DNS, Wi-Fi secrets.
- One device can have many profiles, but only one is active at a time (applied with connection up).
- Profiles are stored as keyfiles in /etc/NetworkManager/system-connections/NAME.nmconnection.
- Linux only. Lab: alpine:3.20 + NetworkManager 1.46 managing eth1, router r1 192.168.45.1 runs DHCP.
- Step 1
1.You type nmcli connection up 'Wired connection 1'
- Step 2
2.nmcli sends a D-Bus request to NetworkManager
- Step 3
3.Profile says ipv4.method auto (DHCP)
- Step 4
4.NetworkManager sends DHCP discover out of eth1
- Step 5
5.DHCP server on r1 (192.168.45.1) returns a lease
- Step 6
6.NetworkManager puts 192.168.45.134/24 on eth1
25.2 Global options: output control
| Option | What it does |
|---|---|
| -t | Terse: colon-separated, for scripts |
| -m tabular | multiline | One entry per line / one property per line |
| -f FIELDS | all | common | Choose columns or properties |
| -g FIELDS | Values only (= -m tabular -t -f), great in scripts |
| -e yes|no | Escape ':' and '\' in terse output |
| -p / -o | Pretty headers / only properties that are set |
| -c, -s, -a | Colours, show secrets, ask for missing values |
| -w N | Wait up to N s (0 = return at once) |
| --offline | No daemon: print a keyfile |
nmcli -t device statusnmcli -m multiline device statusnmcli -f NAME,UUID,TYPE,DEVICE \ connection shownmcli -t -e no -f NAME,DEVICE connection shownmcli -g ip4.address \ connection show 'Wired connection 1'nmcli -p connection show 'Wired connection 1'nmcli -o connection show 'Wired connection 1'$ nmcli -t device statuseth1:ethernet:connected:Wired connection 1lo:loopback:connected (externally):loerspan0:erspan:unmanaged:$ nmcli -m multiline device statusDEVICE: eth1TYPE: ethernetSTATE: connectedCONNECTION: Wired connection 1$ nmcli -f NAME,UUID,TYPE,DEVICE connection showNAME UUID TYPE DEVICEWired connection 1 b5affc06-ac52-3540-bd5d-63bdb6e6bc16 ethernet eth1lo 6db1d4e1-49c5-475b-9b7b-6e58af747166 loopback lo$ nmcli -t -e no -f NAME,DEVICE connection showWired connection 1:eth1lo:lo$ nmcli -g ip4.address connection show 'Wired connection 1'192.168.45.134/24$ nmcli -o connection show 'Wired connection 1'connection.id: Wired connection 1connection.type: 802-3-ethernetconnection.autoconnect-priority: -999ipv4.method: autoipv6.method: auto25.3 nmcli general
- general (= general status): STATE, CONNECTIVITY, Wi-Fi/WWAN hardware and software switches.
- -t -f RUNNING general: is the daemon running? The first debug step on a server.
- hostname shows/sets the hostname; permissions lists what this user may do; logging shows/sets level and domains.
- reload [conf | dns-rc | dns-full] reloads config like SIGHUP, rewrites resolv.conf or restarts the DNS plugin.
nmcli generalnmcli -t -f RUNNING generalnmcli -t -f STATE generalnmcli general hostnamenmcli general permissionsnmcli general loggingnmcli general logging level INFOnmcli general reload conf$ nmcli generalSTATE CONNECTIVITY WIFI-HW WIFI WWAN-HW WWANconnected full missing enabled missing enabled$ nmcli -t -f RUNNING generalrunning$ nmcli -t -f STATE generalconnected$ nmcli general hostnamen025-nm$ nmcli general permissionsPERMISSION VALUEorg.freedesktop.NetworkManager.checkpoint-rollback yesorg.freedesktop.NetworkManager.enable-disable-network yesorg.freedesktop.NetworkManager.enable-disable-wifi yes$ nmcli general loggingLEVEL DOMAINSINFO PLATFORM,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,IP4,IP6,...25.4 nmcli networking, radio
- networking on|off enables/disables all networking; off makes every device unmanaged.
- networking connectivity [check]: none, portal, limited, full or unknown.
- radio wifi|wwan|all on|off: radio switches; radio all off = airplane mode. WIFI-HW 'missing' in a container.
nmcli networkingnmcli networking connectivitynmcli networking connectivity checknmcli networking offnmcli device statusnmcli networking onnmcli device statusnmcli radionmcli radio wifi offnmcli radio allnmcli radio wifi onnmcli radio wwan$ nmcli networkingenabled$ nmcli networking connectivityfull$ nmcli networking connectivity checkfull$ nmcli networking off$ nmcli device statusDEVICE TYPE STATE CONNECTIONerspan0 erspan unmanaged --eth1 ethernet unmanaged --$ nmcli networking on$ nmcli device statusDEVICE TYPE STATE CONNECTIONeth1 ethernet connected Wired connection 1lo loopback connected (externally) lo$ nmcli radioWIFI-HW WIFI WWAN-HW WWANmissing enabled missing enabled$ nmcli radio wifi off$ nmcli radio allWIFI-HW WIFI WWAN-HW WWANmissing disabled missing enabled$ nmcli radio wifi on$ nmcli radio wwanenabled25.5 nmcli connection show
- Lists profiles (NAME, UUID, TYPE, DEVICE); --active only active ones; --order -active:+name sorts (minus = descending).
- show NAME prints every setting; -f ipv4.method,... picks properties; -f GENERAL,IP4,DHCP4 shows runtime data.
- Select by id NAME, uuid UUID, path N or apath N.
nmcli connection shownmcli connection show --activenmcli connection show --order -active:+namenmcli -f GENERAL.NAME,GENERAL.STATE,\IP4.ADDRESS,IP4.GATEWAY,DHCP4 \ connection show 'Wired connection 1'nmcli -f ipv4.method,ipv4.addresses,\ipv4.dns \ connection show 'Wired connection 1'$ nmcli connection showNAME UUID TYPE DEVICEWired connection 1 b5affc06-ac52-3540-bd5d-63bdb6e6bc16 ethernet eth1lo 7b3f7409-f8db-49df-a015-2e3ee053190e loopback lo$ nmcli connection show --order -active:+nameNAME UUID TYPE DEVICElo 7b3f7409-f8db-49df-a015-2e3ee053190e loopback loWired connection 1 b5affc06-ac52-3540-bd5d-63bdb6e6bc16 ethernet eth1$ nmcli -f GENERAL.NAME,...,DHCP4 connection show 'Wired connection 1'GENERAL.NAME: Wired connection 1GENERAL.STATE: activatedIP4.ADDRESS[1]: 192.168.45.134/24IP4.GATEWAY: 192.168.45.1DHCP4.OPTION[3]: dhcp_lease_time = 43200DHCP4.OPTION[4]: dhcp_server_identifier = 192.168.45.1DHCP4.OPTION[8]: ip_address = 192.168.45.134$ nmcli -f ipv4.method,ipv4.addresses,ipv4.dns connection show 'Wired connection 1'ipv4.method: autoipv4.addresses: --ipv4.dns: --25.6 connection add, up / down
- add type ethernet ifname eth1 con-name office-static ipv4.method manual ipv4.addresses ... ipv4.gateway ... ipv4.dns ... creates a static profile.
- Adding a profile changes nothing on the device; connection up applies it, down deactivates it and the device falls back to another profile.
- -w 30 waits up to 30 s for activation, -w 0 returns at once.
- up ifname eth0 picks the best profile; up NAME ap BSSID; up NAME passwd-file F.
nmcli connection add type ethernet \ ifname eth1 con-name office-static \ ipv4.method manual \ ipv4.addresses 192.168.45.10/24 \ ipv4.gateway 192.168.45.1 \ ipv4.dns 1.1.1.1 autoconnect nonmcli -f ipv4.method,ipv4.addresses,\ipv4.gateway,ipv4.dns \ connection show office-staticls /etc/NetworkManager/system-connections/$ nmcli connection add type ethernet ...Connection 'office-static' (e46c0912-c850-4d99-ab4f-49bd051dd171) successfully added.$ nmcli -f ipv4.method,... connection show office-staticipv4.method: manualipv4.addresses: 192.168.45.10/24ipv4.gateway: 192.168.45.1ipv4.dns: 1.1.1.1$ ls /etc/NetworkManager/system-connections/office-static.nmconnection- Step 1
1.connection add office-static: only a file is saved
- Step 2
2.nmcli connection up office-static -> NetworkManager
- Step 3
3.NetworkManager puts 192.168.45.10/24 on eth1
- Step 4
4.ping 192.168.45.1 reaches r1 and the reply returns
- Step 5
5.connection down: eth1 falls back to 'Wired connection 1' (DHCP)
nmcli connection up office-staticnmcli device statusip -4 addr show eth1ping -c 2 192.168.45.1nmcli connection down office-staticnmcli device statusnmcli -w 30 connection up \ 'Wired connection 1'nmcli -g IP4.ADDRESS device show eth1nmcli -w 0 connection up office-staticnmcli -g IP4.ADDRESS device show eth1$ nmcli connection up office-staticConnection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)$ nmcli device statusDEVICE TYPE STATE CONNECTIONeth1 ethernet connected office-static$ ip -4 addr show eth1 inet 192.168.45.10/24 brd 192.168.45.255 scope global noprefixroute eth1$ ping -c 2 192.168.45.164 bytes from 192.168.45.1: seq=0 ttl=64 time=0.156 ms2 packets transmitted, 2 packets received, 0% packet loss$ nmcli connection down office-staticConnection 'office-static' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)$ nmcli device statusDEVICE TYPE STATE CONNECTIONeth1 ethernet connected Wired connection 1$ nmcli -w 30 connection up 'Wired connection 1'Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)$ nmcli -g IP4.ADDRESS device show eth1192.168.45.134/24$ nmcli -w 0 connection up office-static$ nmcli -g IP4.ADDRESS device show eth1192.168.45.10/2425.7 connection modify
- modify changes only the saved profile; the device gets it at the next connection up.
- +ipv4.dns VAL appends, -ipv4.dns 0 removes by index (or value), prop "" resets to default.
- --temporary changes the profile in memory only (not written to the keyfile).
- Short names work: con mod, ethernet.mtu; remove 802-1x removes a whole setting.
nmcli connection modify office-static \ +ipv4.dns 8.8.8.8nmcli connection modify office-static \ -ipv4.dns 0nmcli con mod office-static \ ipv4.addresses 192.168.45.20/24nmcli -g IP4.ADDRESS device show eth1nmcli connection modify --temporary \ office-static ethernet.mtu 1400grep -c mtu /etc/NetworkManager/\system-connections/office-static.nmconnectionnmcli connection up office-staticnmcli -g IP4.ADDRESS device show eth1ip link show eth1$ nmcli -g ipv4.dns connection show office-static1.1.1.1$ nmcli connection modify office-static +ipv4.dns 8.8.8.8$ nmcli -g ipv4.dns connection show office-static1.1.1.1,8.8.8.8$ nmcli connection modify office-static -ipv4.dns 0$ nmcli -g ipv4.dns connection show office-static8.8.8.8$ nmcli con mod office-static ipv4.addresses 192.168.45.20/24$ nmcli -g ipv4.addresses connection show office-static192.168.45.20/24$ nmcli -g IP4.ADDRESS device show eth1192.168.45.10/24$ nmcli connection modify --temporary office-static ethernet.mtu 1400$ nmcli -g 802-3-ethernet.mtu connection show office-static1400$ grep -c mtu .../office-static.nmconnection0$ nmcli connection up office-staticConnection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/9)$ nmcli -g IP4.ADDRESS device show eth1192.168.45.20/24$ ip link show eth110: eth1@if9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1400 qdisc noqueue state UP25.8 nmcli monitor
nmcli monitornmcli connection monitor office-static$ nmcli monitorNetworkManager is runningoffice-static: connection profile changedeth1: deactivatingConnectivity is now 'none'eth1: disconnectedeth1: using connection 'office-static'eth1: connecting (getting IP configuration)'office-static' is now the primary connectioneth1: connectedNetworkmanager is now in the 'connected' stateConnectivity is now 'full'25.9 Connection types
| Group | Types |
|---|---|
| Wired / wireless | ethernet, wifi, wifi-p2p |
| Aggregation / L2 | bond, team, bridge (bond-slave etc. deprecated: ethernet + master) |
| L2 virtual | vlan, vxlan, macvlan, macsec |
| Tunnels / VPN | ip-tunnel, wireguard, vpn |
| Virtual devices | veth, tun, dummy, vrf |
| Mobile / DSL | gsm, cdma, adsl, pppoe |
| Other | bluetooth, infiniband, 6lowpan, wpan, olpc-mesh, ovs-*, generic, wimax |
nmcli connection add type dummy \ ifname dummy0 con-name dummy0 \ ipv4.method manual \ ipv4.addresses 10.45.0.1/32nmcli connection add type bridge \ ifname br0 con-name br0 \ ipv4.method disabled ipv6.method disablednmcli connection add type vlan \ ifname eth1.100 dev eth1 id 100 \ con-name vlan100 ipv4.method manual \ ipv4.addresses 10.45.100.1/24nmcli connection add save no type ethernet \ ifname eth1 con-name temp-eth autoconnect nonmcli -f NAME,TYPE,DEVICE connection showip -br addr showConnection 'dummy0' (44921c39-4bc2-445f-9eb0-401542dd656d) successfully added.Connection 'br0' (80974d4a-b2df-41df-8b49-ba18af201db1) successfully added.Connection 'vlan100' (f97a9251-0ef4-4091-b78c-ce856b6722df) successfully added.Connection 'temp-eth' (f796a179-56e4-4904-9ad6-95ee9c558ccf) successfully added.$ nmcli -f NAME,TYPE,DEVICE connection showNAME TYPE DEVICEoffice-static ethernet eth1vlan100 vlan eth1.100dummy0 dummy dummy0br0 bridge br0Wired connection 1 ethernet --temp-eth ethernet --$ ip -br addr showeth1@if9 UP 192.168.45.20/24dummy0 UNKNOWN 10.45.0.1/32br0 DOWNeth1.100@eth1 UP 10.45.100.1/2425.10 edit, clone, delete, reload, load, import, export, migrate
- edit opens the interactive editor (set, save, quit); clone copies a profile (--temporary = until restart); delete takes several names.
- After editing keyfiles by hand: connection reload (all) or connection load FILE (one).
- import / export are for VPN configs (needs the VPN plugin, e.g. openvpn); export of a non-VPN profile fails.
- migrate moves profiles to the keyfile plugin (--plugin keyfile | ifcfg-rh).
nmcli connection edit type ethernet \ con-name office-lannmcli> set ipv4.method manualnmcli> set ipv4.addresses 192.168.45.30/24nmcli> savenmcli> quitnmcli connection clone office-static \ office-copynmcli connection clone --temporary \ office-static test-copynmcli connection delete office-copy \ test-copy office-lan===| nmcli interactive connection editor |===Adding a new '802-3-ethernet' connectionnmcli> set ipv4.method manualnmcli> set ipv4.addresses 192.168.45.30/24nmcli> saveDo you still want to save? (yes/no) [yes] yesConnection 'office-lan' (0a2b0ca1-c4e9-48a2-a342-da07bef34ef6) successfully saved.nmcli> quitoffice-static (e46c0912-...) cloned as office-copy (b1a63d5a-c2c6-44f7-ab6b-e50985c47569).office-static (e46c0912-...) cloned as test-copy (65529239-adbe-4d6e-8b6b-531a645df564).$ nmcli connection delete office-copy test-copy office-lanConnection 'office-copy' (b1a63d5a-...) successfully deleted.Connection 'test-copy' (65529239-...) successfully deleted.Connection 'office-lan' (0a2b0ca1-...) successfully deleted.cd /etc/NetworkManager/system-connectionssed -i s/^dns=1.1.1.1/dns=9.9.9.9/ \ lab-dns.nmconnectionnmcli -g ipv4.dns connection show lab-dnsnmcli connection reloadnmcli -g ipv4.dns connection show lab-dnsnmcli connection load lab-dns.nmconnectionnmcli connection export lab-dnsnmcli connection import type openvpn \ file client.ovpnnmcli connection migrate$ sed -i s/^dns=1.1.1.1/dns=9.9.9.9/ lab-dns.nmconnection$ nmcli -g ipv4.dns connection show lab-dns1.1.1.1$ nmcli connection reload$ nmcli -g ipv4.dns connection show lab-dns9.9.9.9$ sed -i s/^dns=9.9.9.9/dns=8.8.4.4/ lab-dns.nmconnection$ nmcli connection load lab-dns.nmconnection$ nmcli -g ipv4.dns connection show lab-dns8.8.4.4$ nmcli connection export lab-dnsError: the connection is not VPN.$ nmcli connection import type openvpn file client.ovpnError: failed to load VPN plugin: unknown VPN plugin "org.freedesktop.NetworkManager.openvpn".$ nmcli connection migrateConnection 'Wired connection 1' (b5affc06-...) successfully migrated.Connection 'lo' (7b3f7409-...) successfully migrated.Connection 'office-static' (e46c0912-...) successfully migrated.Connection 'lab-dns' (fa1d5d7b-...) successfully migrated.25.11 Common mistakes
- Running modify and expecting ip addr to change: it only edits the profile; run connection up NAME.
- Thinking nmcli configures the network itself: it is only a client; if the daemon is stopped nothing works (check -t -f RUNNING general).
- Editing a keyfile by hand and forgetting connection reload / load.
- Mixing up device and connection names (eth1 vs 'Wired connection 1').
25.12 Interview tips
- Device = real interface (eth0, wlan0); connection = saved profile (IP, gateway, DNS, secrets); one active profile per device, applied with connection up.
- Static IP: nmcli con add type ethernet ifname eth0 con-name X ipv4.method manual ipv4.addresses A/24 ipv4.gateway G ipv4.dns D, then con up X.
- Use -g / -t in scripts for stable, parseable output.
- Profiles live in /etc/NetworkManager/system-connections as keyfiles.