Quick Start: Up and Running in 5 Minutes
SSHed into a server and need to check or change network configuration right away? Here are the 3 commands you need to know first:
# Show status of all connections
nmcli connection show
# Show network interface information
nmcli device status
# Show detailed IP, gateway, DNS for a device
nmcli device show ens33
Getting command not found? Install NetworkManager first:
# Ubuntu/Debian
sudo apt install network-manager
# CentOS/AlmaLinux/RHEL
sudo dnf install NetworkManager
sudo systemctl enable --now NetworkManager
Got it working? Now let’s go through each step in detail.
Understanding nmcli Before You Use It
nmcli is the CLI frontend for NetworkManager — the default network management daemon on Ubuntu 18.04+, Fedora 21+, RHEL/CentOS 7+, and Debian 10+. Instead of manually editing /etc/network/interfaces or /etc/sysconfig/network-scripts/, you use nmcli to communicate with NetworkManager, and it handles the rest.
There are 2 key concepts to distinguish:
- Device: a physical or virtual network interface (eth0, ens33, wlan0…)
- Connection: a network configuration profile (name, IP, DNS…) — a device can have multiple connections but only one is active at a time
# List devices and their status
nmcli device
# List connections — including inactive ones
nmcli connection show
# Show only active connections
nmcli connection show --active
The output of nmcli connection show looks like this:
NAME UUID TYPE DEVICE
ens33 a1b2c3d4-e5f6-... ethernet ens33
lo ... loopback lo
The NAME column is what you use in all subsequent modify commands.
Configuring a Static IP with nmcli
Step 1: Identify the Connection Name
nmcli connection show
Get the value from the NAME column — it usually matches the device name (ens33, eth0…) but not always.
Step 2: Set a Static IP
nmcli connection modify "ens33" \
ipv4.method manual \
ipv4.addresses "192.168.1.100/24" \
ipv4.gateway "192.168.1.1" \
ipv4.dns "8.8.8.8,1.1.1.1"
Step 3: Apply the Changes
nmcli connection up "ens33"
This command disconnects and reconnects with the new configuration. If you’re SSHed in and the IP changes, your session will drop — have a console backup ready or make sure the new IP is still reachable before running this.
Reverting to DHCP
nmcli connection modify "ens33" ipv4.method auto
nmcli connection up "ens33"
Managing DNS the Right Way
This is where I see a lot of newcomers go wrong: on systems using NetworkManager, /etc/resolv.conf is typically a symlink and gets overwritten every time the connection changes. Edit it by hand and then restart NetworkManager — and your changes are gone.
The right way is to set DNS through nmcli:
# Set DNS server for the connection
nmcli connection modify "ens33" ipv4.dns "8.8.8.8,1.1.1.1"
# Add DNS search domain (useful in corporate environments)
nmcli connection modify "ens33" ipv4.dns-search "company.local internal.dev"
# View currently configured DNS
nmcli connection show "ens33" | grep -i dns
To ignore DNS provided by the DHCP server and only use manually configured DNS:
nmcli connection modify "ens33" ipv4.ignore-auto-dns yes
nmcli connection up "ens33"
Creating a New Connection from Scratch
Early in my sysadmin career, I once spent an entire afternoon debugging this issue just because I hadn’t read the logs carefully — the connection was conflicting with an old profile left over from a previous OS install. Since then, I’ve made it a habit to create a new connection rather than modifying the old one when setting up a fresh server:
nmcli connection add \
type ethernet \
ifname ens33 \
con-name "server-static" \
ipv4.method manual \
ipv4.addresses "10.0.0.50/24" \
ipv4.gateway "10.0.0.1" \
ipv4.dns "8.8.8.8"
# Activate the new connection
nmcli connection up "server-static"
# Delete the old connection if no longer needed
nmcli connection delete "ens33"
Advanced: Common Scenarios
Adding a Second IP to the Same Network Interface
# Use + to append, not overwrite
nmcli connection modify "ens33" +ipv4.addresses "192.168.1.101/24"
nmcli connection up "ens33"
Configuring IPv6
nmcli connection modify "ens33" \
ipv6.method manual \
ipv6.addresses "2001:db8::1/64" \
ipv6.gateway "2001:db8::fffe"
nmcli connection up "ens33"
Disabling IPv6 on a Connection
nmcli connection modify "ens33" ipv6.method disabled
nmcli connection up "ens33"
Viewing Full Connection Details in a Readable Format
nmcli -p connection show "ens33"
The -p flag (pretty) displays output in a table format, much easier to read than the default.
Disabling Autoconnect on Boot
nmcli connection modify "ens33" connection.autoconnect no
Practical Tips for Daily Work
1. Verify immediately after making changes:
ip addr show ens33
ip route show
cat /etc/resolv.conf
2. Test that DNS is working:
resolvectl query google.com
# or use nslookup if resolvectl is not available
nslookup google.com
3. View NetworkManager logs when debugging:
# Follow in real time
journalctl -u NetworkManager -f
# View the last 50 lines
journalctl -u NetworkManager -n 50
4. Back up and replicate your configuration: Connection files live in /etc/NetworkManager/system-connections/. Copy this folder to a new server and you’re done — no need to retype every command:
rsync -avz /etc/NetworkManager/system-connections/ \
root@new-server:/etc/NetworkManager/system-connections/
ssh root@new-server systemctl restart NetworkManager
5. Restart NetworkManager when needed:
sudo systemctl restart NetworkManager
Use this when changes aren’t taking effect, DNS is serving stale cached results, or after manually editing config files.
Most of a sysadmin’s daily network tasks fit into about 10–15 commonly used nmcli commands — no need to memorize different config file paths per distro. Another useful point when writing scripts or Ansible playbooks: nmcli exit codes are unambiguous — 0 means success, non-zero means error — which makes conditional checks far easier than parsing ifconfig or route output the old way.

