nmcli Command Examples¶
Introduction¶
This guide focuses on nmcli command examples from an administrator's terminal. The goal is to configure or verify networking without guessing which layer is broken.
When You Need This¶
Use this workflow when a host cannot reach another system, name resolution fails, a route is missing, a port is blocked, or NetworkManager configuration needs to be persistent.
Key Files and Commands¶
bash -n script.sh
chmod +x script.sh
./script.sh /var/log
echo $?
Important areas to check are syntax, executable permissions, environment, exit codes, and logged script output. On RHEL-style systems, NetworkManager and firewalld are usually part of the answer.
Step-by-Step Configuration¶
Start by viewing live state, then change the persistent connection profile if needed. For NetworkManager-managed systems, prefer persistent profiles over runtime-only changes.
bash -n script.sh
chmod +x script.sh
./script.sh /var/log
Verification¶
echo $?
shellcheck script.sh
A healthy result should look similar to:
script.sh: syntax OK
0
Troubleshooting¶
Check interface state, IP address, default route, DNS server, firewall zone, and listening process. If a connection works by IP but not by name, focus on DNS. If DNS works but traffic fails, focus on routes, firewall, and service binding.
Common Mistakes¶
- Making several changes at once, which hides the real cause.
- Skipping logs or verification commands after a change.
- Assuming the problem is fixed because one command returned successfully.
Quick Checklist¶
- Confirm link state and IP address.
- Confirm default gateway and specific routes.
- Confirm DNS separately from IP connectivity.
- Check listening sockets and firewall zones.
- Make persistent changes through NetworkManager when appropriate.
Related Guides¶
- IP Command Networking Guide
- ss Command Networking Guide
- Configure firewalld Linux
- Troubleshoot DNS Linux
Summary¶
Good Linux networking work separates address, route, DNS, firewall, and service checks. Verify each layer before moving to the next one.