NetworkManager Commands Reference (Part 1 of 4)

1. Introduction to NetworkManager

1.1 What is NetworkManager?

NetworkManager is a dynamic network control and configuration system that attempts to keep network connectivity active when available. It manages Ethernet, WiFi, mobile broadband (WWAN), and PPPoE devices while providing VPN integration.

Primary Tools:

1.2 Why Use NetworkManager?

2. nmcli - Command Line Interface

2.1 Basic Syntax

nmcli [OPTIONS] OBJECT { COMMAND | help }

Objects:
  general       NetworkManager's general status and operations
  networking    Overall networking control
  radio         NetworkManager radio switches
  connection    NetworkManager's connections
  device        Devices managed by NetworkManager
  agent         NetworkManager secret agent or polkit agent
  monitor       Monitor NetworkManager changes

2.2 Common Options

Option Description
-t, --terse Output for scripting (no headers, colon-separated)
-p, --pretty Human-readable output
-m, --mode Output mode: tabular, multiline
-c, --colors Use colors in output (yes/no/auto)
-f, --fields Specify fields to output
-w, --wait Wait for operation to complete

2.3 Quick Status Commands

# Show NetworkManager status
nmcli general status

# Show all devices
nmcli device status

# Show all connections
nmcli connection show

# Show active connections only
nmcli connection show --active

# Show device details
nmcli device show eth0

# Show connection details
nmcli connection show "Wired connection 1"

3. Managing Devices

3.1 Device Status and Information

# List all devices
nmcli device

# Show detailed device information
nmcli device show

# Show specific device
nmcli device show eth0

# Monitor device changes
nmcli device monitor

# Monitor specific device
nmcli device monitor eth0

3.2 Device Control

# Connect a device
nmcli device connect eth0

# Disconnect a device
nmcli device disconnect eth0

# Reapply connection on device
nmcli device reapply eth0

# Delete software device
nmcli device delete bond0

3.3 WiFi Device Management

# List available WiFi networks
nmcli device wifi list

# Rescan for WiFi networks
nmcli device wifi rescan

# Connect to WiFi network
nmcli device wifi connect "SSID" password "password"

# Connect to hidden WiFi
nmcli device wifi connect "SSID" password "password" hidden yes

# Show WiFi radio status
nmcli radio wifi

# Turn WiFi on/off
nmcli radio wifi on
nmcli radio wifi off

4. Managing Connections

4.1 Viewing Connections

# List all connections
nmcli connection show

# Show connection details
nmcli connection show "Wired connection 1"

# Show active connections
nmcli connection show --active

# Show connection in machine-readable format
nmcli -t connection show "Wired connection 1"

4.2 Creating Connections

Ethernet Connection with DHCP

nmcli connection add \
  type ethernet \
  con-name "My-Ethernet" \
  ifname eth0 \
  ipv4.method auto \
  ipv6.method auto

Ethernet Connection with Static IP

nmcli connection add \
  type ethernet \
  con-name "Static-Ethernet" \
  ifname eth0 \
  ipv4.method manual \
  ipv4.addresses "192.168.1.100/24" \
  ipv4.gateway "192.168.1.1" \
  ipv4.dns "8.8.8.8,8.8.4.4"

WiFi Connection

nmcli connection add \
  type wifi \
  con-name "Home-WiFi" \
  ifname wlan0 \
  ssid "MyNetwork" \
  wifi-sec.key-mgmt wpa-psk \
  wifi-sec.psk "password"

4.3 Modifying Connections

# Change to static IP
nmcli connection modify "Wired connection 1" \
  ipv4.method manual \
  ipv4.addresses "192.168.1.100/24" \
  ipv4.gateway "192.168.1.1" \
  ipv4.dns "8.8.8.8,8.8.4.4"

# Change to DHCP
nmcli connection modify "Wired connection 1" \
  ipv4.method auto

# Add additional DNS server
nmcli connection modify "Wired connection 1" \
  +ipv4.dns "1.1.1.1"

# Remove DNS server
nmcli connection modify "Wired connection 1" \
  -ipv4.dns "8.8.8.8"

# Change connection autoconnect priority
nmcli connection modify "Wired connection 1" \
  connection.autoconnect-priority 10

4.4 Activating/Deactivating Connections

# Bring connection up
nmcli connection up "Wired connection 1"

# Bring connection down
nmcli connection down "Wired connection 1"

# Reload connection from disk
nmcli connection reload

# Reload specific connection
nmcli connection reload "Wired connection 1"

4.5 Deleting Connections

# Delete a connection
nmcli connection delete "Wired connection 1"

# Delete by UUID
nmcli connection delete uuid 12345678-1234-1234-1234-123456789abc

5. Interactive Editing

5.1 Using nmcli Interactive Mode

# Edit connection interactively
nmcli connection edit "Wired connection 1"

# Commands within interactive mode:
# print              - Print current values
# set                - Set property value
# remove             - Remove property
# describe           - Describe property
# save               - Save changes
# activate           - Activate connection
# back               - Go to upper level
# quit               - Quit without saving

5.2 nmtui - Text User Interface

# Launch nmtui
nmtui

# Options:
nmtui edit          # Edit a connection
nmtui connect       # Activate a connection
nmtui hostname      # Set system hostname
Note: nmtui provides a curses-based interface that's easier for those who prefer a semi-graphical approach while still working in the terminal.

6. Connection Profiles

6.1 Profile Locations

Connection profiles are stored as keyfiles in:

/etc/NetworkManager/system-connections/
Warning: These files contain sensitive information like passwords. Permissions are typically 600 (readable only by root).

6.2 Example Connection Profile

[connection]
id=MyEthernet
uuid=12345678-1234-1234-1234-123456789abc
type=ethernet
autoconnect=true
interface-name=eth0

[ethernet]

[ipv4]
method=manual
address1=192.168.1.100/24,192.168.1.1
dns=8.8.8.8;8.8.4.4;

[ipv6]
method=auto

[proxy]

6.3 Manually Editing Profiles

# Edit profile with your favorite editor
sudo vi /etc/NetworkManager/system-connections/MyEthernet.nmconnection

# Set correct permissions
sudo chmod 600 /etc/NetworkManager/system-connections/MyEthernet.nmconnection

# Reload the connection
sudo nmcli connection reload MyEthernet

# Bring it up
sudo nmcli connection up MyEthernet

7. Common Configuration Scenarios

7.1 Setting Static IP Address

# Complete static IP configuration
nmcli connection modify "Wired connection 1" \
  ipv4.method manual \
  ipv4.addresses "192.168.1.100/24" \
  ipv4.gateway "192.168.1.1" \
  ipv4.dns "8.8.8.8,8.8.4.4" \
  ipv4.dns-search "example.com"

# Apply changes
nmcli connection up "Wired connection 1"

7.2 Setting Up Multiple IP Addresses

# Add primary and secondary IP
nmcli connection modify "Wired connection 1" \
  ipv4.addresses "192.168.1.100/24,192.168.1.101/24"

# Or add additional IP to existing
nmcli connection modify "Wired connection 1" \
  +ipv4.addresses "192.168.1.102/24"

7.3 Configuring DNS

# Set DNS servers
nmcli connection modify "Wired connection 1" \
  ipv4.dns "8.8.8.8,8.8.4.4"

# Add additional DNS server
nmcli connection modify "Wired connection 1" \
  +ipv4.dns "1.1.1.1"

# Ignore automatic DNS from DHCP
nmcli connection modify "Wired connection 1" \
  ipv4.ignore-auto-dns yes

7.4 Setting MTU

# Set MTU for connection
nmcli connection modify "Wired connection 1" \
  802-3-ethernet.mtu 1500

8. Next Steps

This covers the basics of NetworkManager and nmcli. Continue to:

← Back to NetworkManager Index ↑ Back to EXPANDED