Skip to content

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:

nmcli general status

List all connections (active and inactive):

nmcli connection show

Show details of a specific connection:

nmcli connection show "Wired connection 1"

Show device status:

nmcli device status

Show device details including IP info:

nmcli device show eth0

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:

nmcli connection modify "static-eth0" ipv4.dns "8.8.8.8 8.8.4.4"

Bring a connection up or down:

nmcli connection up "static-eth0"
nmcli connection down "static-eth0"

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:

nmcli -t -f NAME,DEVICE,TYPE connection show --active

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.dns vs system-wide /etc/resolv.conf

Common Mistakes

  • Forgetting to run nmcli connection up after 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

Cleanup

nmcli connection delete "static-eth0" 2>/dev/null