What it does
NetworkManager is the service that runs the network on Red Hat Enterprise Linux. It keeps your settings in connection profiles. A profile holds the IP addresses, the gateway, DNS servers and more. nmcli is the command-line tool to read and change these profiles and the devices (network cards).
Settings you make with nmcli are saved in the profile, so they stay after a reboot. This is the big difference with the ip command, whose changes are lost at reboot.
Most commands can be shortened: nmcli connection show = nmcli con show = nmcli c s. Tab completion helps you find the next word.
How to write it
nmcli [OPTIONS] OBJECT { COMMAND | help }
nmcli connection { show | up | down | modify | add | edit | clone | delete | reload | load | import | export | monitor }
nmcli device { status | show | set | connect | disconnect | reapply | modify | delete | monitor | wifi | lldp }
nmcli general { status | hostname | permissions | logging | reload }
nmcli networking { on | off | connectivity }
nmcli radio { all | wifi | wwan } [ on | off ]Main parts
general- Overall status of NetworkManager, the hostname, your permissions and the log level.
networking- Turn all networking on or off, or check the internet connectivity.
radio- Turn Wi-Fi and mobile broadband radios on or off.
connection(con,c)- Work with profiles: show, add, modify, up, down, delete, reload.
device(dev,d)- Work with network cards: status, details, connect, disconnect, Wi-Fi.
monitor- Watch changes of devices and connections live.
agent- Run as a secret or polkit agent (asks for passwords).
Options 45
Most used
Global options (before the object)
Options of connection commands
Settings you change often (setting.property)
Nothing matches this filter.
Examples 16
$ run as a normal user# run as root (or with sudo)
1Show all profiles and which device uses them
nmcli connection show NAME UUID TYPE DEVICE enp1s0 3f0c3a8e-6c35-4c5a-9a0e-7f1a2b3c4d5e ethernet enp1s0 lo 2b1c5e3a-1d2e-4f5a-8b9c-0d1e2f3a4b5c loopback loA profile with an empty DEVICE column is not active now.
2Show the state of every network card
nmcli device status DEVICE TYPE STATE CONNECTION enp1s0 ethernet connected enp1s0 lo loopback connected (externally) lo"disconnected" means the card works but no profile is active on it. "unmanaged" means NetworkManager does not control it.
3Give a server a fixed IPv4 address
nmcli con mod enp1s0 ipv4.method manual ipv4.addresses 192.168.122.10/24 \ ipv4.gateway 192.168.122.1 ipv4.dns 192.168.122.1 nmcli con up enp1s0The change is saved in the profile.
con upuses it right now.4Add a second address without removing the first
nmcli con mod enp1s0 +ipv4.addresses 192.168.122.110/24 nmcli con up enp1s0Use a minus to remove one address again:
-ipv4.addresses 192.168.122.110/24.5Create a new profile with a fixed address
nmcli con add con-name app-net type ethernet ifname enp2s0 \ ipv4.method manual ipv4.addresses 10.10.20.15/24 ipv4.gateway 10.10.20.1 ipv4.dns 10.10.20.53Good for a second network card, for example a separate network for backups or databases.
6Use only your own DNS servers (ignore DHCP)
nmcli con mod enp1s0 ipv4.dns "10.0.0.53 10.0.1.53" ipv4.ignore-auto-dns yes ipv4.dns-search corp.example.com nmcli con up enp1s0 cat /etc/resolv.confNetworkManager writes /etc/resolv.conf for you. A hardened server should use only the internal resolvers that log queries.
7Add a fixed route to another network
nmcli con mod enp1s0 +ipv4.routes "10.20.0.0/16 192.168.122.254" nmcli con up enp1s0 ip route show 10.20.0.0/16Typical for a management network or a VPN gateway. The route stays after a reboot, unlike
ip route add.8Get one value for a script
nmcli -g IP4.ADDRESS device show enp1s0 192.168.122.10/24 nmcli -t -f NAME,DEVICE con show --active enp1s0:enp1s0-g and -t give clean output without headers. Use it in provisioning scripts and health checks.
9Make a VLAN interface for a separate network
nmcli con add type vlan con-name vlan30 dev enp1s0 id 30 \ ipv4.method manual ipv4.addresses 172.16.30.5/24 nmcli con up vlan30VLANs keep traffic apart, for example a DMZ for public servers. The switch port must allow VLAN 30.
10Make a bond of two cards for failover
nmcli con add type bond con-name bond0 ifname bond0 bond.options "mode=active-backup,miimon=100" \ ipv4.method manual ipv4.addresses 192.168.50.10/24 ipv4.gateway 192.168.50.1 nmcli con add type ethernet port-type bond controller bond0 con-name bond0-p1 ifname enp3s0 nmcli con add type ethernet port-type bond controller bond0 con-name bond0-p2 ifname enp4s0 nmcli con up bond0If one cable or switch fails, the other card takes over. Check with
cat /proc/net/bonding/bond0.11Put a profile in a firewalld zone
nmcli con mod enp2s0 connection.zone internal nmcli con up enp2s0 firewall-cmd --get-active-zonesEach network card can have its own firewall rules: public for the internet side, internal for the private side.
12Turn off IPv6 on a profile
nmcli con mod enp1s0 ipv6.method disabled nmcli con up enp1s0Only do this when a policy asks for it. Many services work fine with IPv6.
13Set the hostname
nmcli general hostname web01.example.com hostnamectl --static web01.example.comSame result as
hostnamectl set-hostname.14Check who may change the network
nmcli general permissionsOver SSH a normal user usually gets "no" or "auth". Use sudo.
15Read a profile edited by hand again
vim /etc/NetworkManager/system-connections/enp1s0.nmconnection nmcli con reload nmcli con up enp1s0reloadonly reads the files again.upmakes the new settings active.16Watch network changes live
nmcli monitorUseful while you unplug a cable or restart a switch. Press Ctrl+C to stop.
Nothing matches this filter.
Watch out
nmcli con modonly changes the profile. Runnmcli con up NAMEto use the change now.- Over SSH, a wrong address or gateway cuts your own connection. Keep a console open.
- Without
+, a setting likeipv4.addressesreplaces all old values. - Two profiles with autoconnect on for one device: you cannot know which one starts after a reboot.
ipv4.method manualneeds at least one address inipv4.addresses, or the command fails.- Do not edit
/etc/resolv.confby hand. NetworkManager writes it again.
Files
/etc/NetworkManager/system-connections/- The profiles, one keyfile (.nmconnection) per profile. Root only (mode 600).
/etc/NetworkManager/NetworkManager.conf- Main settings of NetworkManager.
/etc/NetworkManager/conf.d/- Extra settings files, read after the main file.
/run/NetworkManager/system-connections/- Profiles that are not saved to disk (they are gone after reboot).
/etc/resolv.conf- DNS settings. Written by NetworkManager.
Tips to remember
- Remember the order: show → modify → up → check.
nmcli con show NAMElists every setting of a profile. Search it with| grep ipv4.- Lost in the words? Press Tab twice after any word, or type
nmcli con mod NAME ipv4.and Tab. man nmcli-exampleshas many ready-to-use examples.