Drill: Manage Network Connections with nmcli¶
Goal¶
Use nmcli to view, create, modify, and troubleshoot NetworkManager-managed connections.
Setup¶
- Linux system with NetworkManager running
- Root access for modifying connections
Commands¶
Show overall status:
List all connections (active and inactive):
Show details of a specific connection:
Show device status:
Show device details including IP info:
Create a new static IP connection:
nmcli connection add type ethernet con-name "static-eth0" ifname eth0 \
ip4 10.0.0.50/24 gw4 10.0.0.1
Add a DNS server to a connection:
Bring a connection up or down:
Switch a connection from DHCP to static:
nmcli connection modify "Wired connection 1" ipv4.method manual \
ipv4.addresses "10.0.0.50/24" ipv4.gateway "10.0.0.1"
Show active connection details in terse format for scripting:
What to Look For¶
- Connection state: activated, deactivating, or deactivated
- IP4.ADDRESS and IP4.GATEWAY confirm the active network configuration
- GENERAL.STATE of the device shows carrier and connection status
- DNS configuration in
ipv4.dnsvs system-wide /etc/resolv.conf
Common Mistakes¶
- Forgetting to run
nmcli connection upafter modifying a connection - Confusing connection names with interface names (they can differ)
- Not checking if NetworkManager is actually managing the interface
- Overwriting DNS settings without checking if they are managed by DHCP