nmcli - NetworkManager Command Line Interface

Quick Command: nmcli
Purpose: Command-line tool for controlling NetworkManager and reporting network status
Best For: Scripting, automation, remote administration, and quick operations

1. Introduction to nmcli

1.1 What is nmcli?

nmcli is a command-line client for NetworkManager. It allows users to control NetworkManager and report network status without requiring a graphical interface. It's designed for both interactive use and scripting.

1.2 Key Features

1.3 Why Use nmcli?

Scenario Why nmcli
Automation Scriptable, consistent output, exit codes
Remote Administration Works over SSH, no GUI required
Server Management Lightweight, headless-friendly
Quick Status Checks Fast, one-line commands
CI/CD Pipelines Integrates with build systems
Mass Deployment Batch operations across systems

2. Basic Syntax and Structure

2.1 Command Structure

nmcli [OPTIONS] OBJECT { COMMAND | help }

2.2 Common Options

Option Description Example
-t, --terse Machine-readable output (colon-separated) nmcli -t device status
-p, --pretty Human-readable formatted output nmcli -p connection show
-m, --mode Output mode: tabular or multiline nmcli -m multiline
-c, --colors Use colors: yes, no, auto nmcli -c no
-f, --fields Specify which fields to display nmcli -f NAME,TYPE connection show
-g, --get-values Get specific values (script-friendly) nmcli -g IP4.ADDRESS device show
-w, --wait Timeout for operations (seconds) nmcli -w 30 connection up eth0
-a, --ask Prompt for missing parameters nmcli -a connection add
-s, --show-secrets Display passwords/secrets nmcli -s connection show
-h, --help Show help nmcli --help
-v, --version Show version nmcli --version

2.3 Objects

Object Abbreviation Purpose
general g NetworkManager status and operations
networking n Overall networking control
radio r Radio switches (WiFi, WWAN)
connection c, con Connection profiles
device d, dev Network devices
agent - Secret agent operations
monitor m Monitor NetworkManager changes

2.4 Command Abbreviations

Pro Tip: nmcli supports abbreviations for faster typing. As long as the abbreviation is unambiguous, it will work:
# These are all equivalent:
nmcli connection show
nmcli con show
nmcli c s

# These are equivalent:
nmcli device status
nmcli dev status
nmcli d s

3. General Operations

3.1 General Status and Information

# Show NetworkManager status
nmcli general status

# Show NetworkManager version
nmcli --version

# Show overall connectivity
nmcli general

# Get system hostname
nmcli general hostname

# Set system hostname
nmcli general hostname new-hostname

3.2 General Status Output

Example Output:
$ nmcli general status
STATE         CONNECTIVITY  WIFI-HW  WIFI     WWAN-HW  WWAN    
connected     full          enabled  enabled  enabled  enabled
Field Possible Values Meaning
STATE asleep, disconnected, disconnecting, connecting, connected local, connected site, connected, connected global Overall NetworkManager state
CONNECTIVITY none, portal, limited, full, unknown Internet connectivity status
WIFI-HW enabled, disabled WiFi hardware availability
WIFI enabled, disabled WiFi software state
WWAN-HW enabled, disabled Mobile broadband hardware
WWAN enabled, disabled Mobile broadband state

3.3 Networking Control

# Check if networking is enabled
nmcli networking

# Enable networking
nmcli networking on

# Disable networking (disconnects all)
nmcli networking off

# Check connectivity
nmcli networking connectivity
# Returns: none, portal, limited, full, unknown

# Force connectivity check
nmcli networking connectivity check

3.4 Radio Management

# Show all radio states
nmcli radio all

# Enable/disable WiFi
nmcli radio wifi on
nmcli radio wifi off

# Enable/disable mobile broadband
nmcli radio wwan on
nmcli radio wwan off

# Enable/disable all radios
nmcli radio all on
nmcli radio all off

4. Device Management

4.1 Device Status

# List all devices
nmcli device status
# or
nmcli device
# or
nmcli d

# Show detailed information about all devices
nmcli device show

# Show specific device details
nmcli device show eth0

# Show in script-friendly format
nmcli -t device status

# Show only specific fields
nmcli -f DEVICE,STATE,CONNECTION device status

4.2 Device Status Output

Example Output:
$ nmcli device status
DEVICE   TYPE      STATE         CONNECTION
eth0     ethernet  connected     Wired connection 1
wlan0    wifi      disconnected  --
lo       loopback  unmanaged     --
State Meaning
connected Device is connected with active connection
disconnected Device is available but not connected
unavailable Device is not available (carrier off, firmware missing)
unmanaged Device is not managed by NetworkManager
connecting Connection in progress
deactivating Connection being torn down

4.3 Device Operations

# Connect a device (activates connection)
nmcli device connect eth0

# Disconnect a device
nmcli device disconnect eth0

# Reapply connection settings
nmcli device reapply eth0

# Set device to managed
nmcli device set eth0 managed yes

# Set device to unmanaged
nmcli device set eth0 managed no

# Delete software device (bond, bridge, etc.)
nmcli device delete bond0

4.4 WiFi Operations

# List available WiFi networks
nmcli device wifi list

# Rescan for WiFi networks
nmcli device wifi rescan

# Rescan specific device
nmcli device wifi rescan ifname wlan0

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

# Connect to WiFi with specific interface
nmcli device wifi connect "SSID" password "password" ifname wlan0

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

# Show WiFi passwords for saved networks
nmcli -s device wifi show-password

# Show QR code for current WiFi (if supported)
nmcli device wifi show-password

4.5 WiFi List Output

Example Output:
$ nmcli device wifi list
IN-USE  BSSID              SSID            MODE   CHAN  RATE       SIGNAL  BARS  SECURITY
*       00:11:22:33:44:55  MyHomeNetwork   Infra  6     130 Mbit/s  85      ▂▄▆█  WPA2
        00:AA:BB:CC:DD:EE  OfficeWiFi      Infra  11    65 Mbit/s   65      ▂▄▆_  WPA2
        00:99:88:77:66:55  GuestNetwork    Infra  1     54 Mbit/s   45      ▂▄__  WPA2

4.6 Monitoring Devices

# Monitor all device changes (real-time)
nmcli device monitor

# Monitor specific device
nmcli device monitor eth0

# Monitor multiple devices
nmcli device monitor eth0 wlan0

# Press Ctrl+C to stop monitoring

5. Connection Management

5.1 Listing Connections

# Show all connection profiles
nmcli connection show
# or
nmcli con show
# or
nmcli c s

# Show only active connections
nmcli connection show --active

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

# Show with all settings including secrets
nmcli -s connection show "Wired connection 1"

# Script-friendly output
nmcli -t connection show

# Show only specific fields
nmcli -f NAME,UUID,TYPE connection show

5.2 Creating Connections

Ethernet Connection with DHCP

# Basic DHCP connection
nmcli connection add \
    type ethernet \
    con-name "My-DHCP" \
    ifname eth0

# With autoconnect enabled
nmcli connection add \
    type ethernet \
    con-name "My-DHCP" \
    ifname eth0 \
    connection.autoconnect yes

Ethernet Connection with Static IP

# Complete static IP configuration
nmcli connection add \
    type ethernet \
    con-name "My-Static" \
    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"

# With additional settings
nmcli connection add \
    type ethernet \
    con-name "Server-Static" \
    ifname eth0 \
    ipv4.method manual \
    ipv4.addresses "192.168.1.50/24" \
    ipv4.gateway "192.168.1.1" \
    ipv4.dns "8.8.8.8,8.8.4.4,1.1.1.1" \
    ipv4.dns-search "company.local" \
    connection.autoconnect yes \
    connection.autoconnect-priority 10

WiFi Connection

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

# Hidden WiFi network
nmcli connection add \
    type wifi \
    con-name "Hidden-WiFi" \
    ifname wlan0 \
    ssid "HiddenSSID" \
    wifi-sec.key-mgmt wpa-psk \
    wifi-sec.psk "password" \
    802-11-wireless.hidden yes

Quick WiFi Connect (creates connection automatically)

# Quick connect (creates connection if needed)
nmcli device wifi connect "SSID" password "password"

# Quick connect on specific interface
nmcli device wifi connect "SSID" password "password" ifname wlan0

5.3 Modifying Connections

Change IP Configuration

# Change to static IP
nmcli connection modify "My-Connection" \
    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 "My-Connection" \
    ipv4.method auto

# Add secondary IP address
nmcli connection modify "My-Connection" \
    +ipv4.addresses "192.168.1.101/24"

# Remove IP address
nmcli connection modify "My-Connection" \
    -ipv4.addresses "192.168.1.101/24"

Modify DNS Settings

# Replace all DNS servers
nmcli connection modify "My-Connection" \
    ipv4.dns "8.8.8.8,8.8.4.4"

# Add additional DNS server
nmcli connection modify "My-Connection" \
    +ipv4.dns "1.1.1.1"

# Remove specific DNS server
nmcli connection modify "My-Connection" \
    -ipv4.dns "8.8.8.8"

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

# Set DNS search domains
nmcli connection modify "My-Connection" \
    ipv4.dns-search "company.local,example.com"

Modify Connection Settings

# Change connection name
nmcli connection modify "Old-Name" \
    connection.id "New-Name"

# Set autoconnect
nmcli connection modify "My-Connection" \
    connection.autoconnect yes

# Set autoconnect priority (lower = higher priority)
nmcli connection modify "My-Connection" \
    connection.autoconnect-priority 10

# Bind to specific device
nmcli connection modify "My-Connection" \
    connection.interface-name eth0

# Change MTU
nmcli connection modify "My-Connection" \
    802-3-ethernet.mtu 9000

# Clone MAC address
nmcli connection modify "My-Connection" \
    802-3-ethernet.cloned-mac-address "00:11:22:33:44:55"

WiFi Connection Modifications

# Change WiFi password
nmcli connection modify "WiFi-Connection" \
    wifi-sec.psk "newpassword"

# Change SSID
nmcli connection modify "WiFi-Connection" \
    802-11-wireless.ssid "NewSSID"

# Make WiFi connection hidden
nmcli connection modify "WiFi-Connection" \
    802-11-wireless.hidden yes

5.4 Activating and Deactivating Connections

# Activate (bring up) a connection
nmcli connection up "My-Connection"

# Activate by UUID
nmcli connection up uuid 12345678-1234-1234-1234-123456789abc

# Activate connection on specific device
nmcli connection up "My-Connection" ifname eth0

# Deactivate (bring down) a connection
nmcli connection down "My-Connection"

# Deactivate by UUID
nmcli connection down uuid 12345678-1234-1234-1234-123456789abc

# Reload a connection from disk
nmcli connection reload

# Reload specific connection
nmcli connection reload "My-Connection"

# Load connection from file
nmcli connection load /etc/NetworkManager/system-connections/My-Connection.nmconnection

5.5 Deleting Connections

# Delete a connection
nmcli connection delete "My-Connection"

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

# Delete multiple connections
nmcli connection delete "Connection1" "Connection2" "Connection3"
Warning: Deleting a connection is permanent. The connection profile file is removed from /etc/NetworkManager/system-connections/. Consider exporting the connection first.

5.6 Cloning Connections

# Clone an existing connection
nmcli connection clone "Original-Connection" "Cloned-Connection"

# Clone and modify
nmcli connection clone "Original" "Clone"
nmcli connection modify "Clone" \
    ipv4.addresses "192.168.1.200/24"

6. Interactive Connection Editor

6.1 Entering Interactive Mode

# Edit existing connection interactively
nmcli connection edit "My-Connection"

# Edit by type (creates new if doesn't exist)
nmcli connection edit type ethernet

# Edit by UUID
nmcli connection edit uuid 12345678-1234-1234-1234-123456789abc

6.2 Interactive Editor Commands

Command Description
print Print all settings or specific property
describe Describe a property
set Set property value
remove Remove property value
add Add new value to property
change Change property value
goto Go to setting or submenu
back Go up one level
save Save connection (persistent or temporary)
activate Activate the connection
verify Verify connection settings
help Show help
quit Exit editor

6.3 Interactive Editor Example Session

Example Interactive Session:
$ nmcli connection edit type ethernet

===| nmcli interactive connection editor |===

Adding a new '802-3-ethernet' connection

Type 'help' or '?' for available commands.
Type 'describe [<setting>.<prop>]' for detailed property description.

You may edit the following settings: connection, 802-3-ethernet (ethernet), 
802-1x, dcb, ipv4, ipv6, tc, proxy
nmcli> set connection.id My-Static-Connection
nmcli> set connection.interface-name eth0
nmcli> set ipv4.method manual
nmcli> set ipv4.addresses 192.168.1.100/24
nmcli> set ipv4.gateway 192.168.1.1
nmcli> set ipv4.dns 8.8.8.8 8.8.4.4
nmcli> print
...
nmcli> save
Connection 'My-Static-Connection' successfully saved.
nmcli> activate
Connection successfully activated
nmcli> quit

7. Advanced Connection Types

7.1 Bond Configuration

# Create bond interface
nmcli connection add \
    type bond \
    con-name bond0 \
    ifname bond0 \
    bond.options "mode=active-backup,miimon=100"

# Add slave interface 1
nmcli connection add \
    type ethernet \
    con-name bond0-slave1 \
    ifname eth0 \
    master bond0

# Add slave interface 2
nmcli connection add \
    type ethernet \
    con-name bond0-slave2 \
    ifname eth1 \
    master bond0

# Configure IP on bond
nmcli connection modify bond0 \
    ipv4.method manual \
    ipv4.addresses "192.168.1.100/24" \
    ipv4.gateway "192.168.1.1"

# Bring up bond
nmcli connection up bond0
nmcli connection up bond0-slave1
nmcli connection up bond0-slave2

Bond Modes

Mode Value Description
balance-rr 0 Round-robin load balancing
active-backup 1 One active, others standby
balance-xor 2 XOR load balancing
broadcast 3 Broadcast on all
802.3ad 4 Dynamic link aggregation (LACP)
balance-tlb 5 Transmit load balancing
balance-alb 6 Adaptive load balancing

7.2 Bridge Configuration

# Create bridge interface
nmcli connection add \
    type bridge \
    con-name br0 \
    ifname br0

# Add interface to bridge
nmcli connection add \
    type ethernet \
    con-name br0-slave \
    ifname eth0 \
    master br0

# Configure IP on bridge
nmcli connection modify br0 \
    ipv4.method manual \
    ipv4.addresses "192.168.1.100/24" \
    ipv4.gateway "192.168.1.1"

# Bring up bridge
nmcli connection up br0
nmcli connection up br0-slave

# Advanced bridge options
nmcli connection modify br0 \
    bridge.stp no \
    bridge.forward-delay 0

7.3 VLAN Configuration

# Create VLAN interface
nmcli connection add \
    type vlan \
    con-name vlan100 \
    ifname eth0.100 \
    dev eth0 \
    id 100

# Configure IP on VLAN
nmcli connection modify vlan100 \
    ipv4.method manual \
    ipv4.addresses "192.168.100.10/24"

# Bring up VLAN
nmcli connection up vlan100

# Multiple VLANs on same interface
nmcli connection add type vlan con-name vlan200 ifname eth0.200 dev eth0 id 200
nmcli connection add type vlan con-name vlan300 ifname eth0.300 dev eth0 id 300

7.4 Team Configuration (Alternative to Bonding)

# Create team interface
nmcli connection add \
    type team \
    con-name team0 \
    ifname team0 \
    config '{"runner": {"name": "activebackup"}}'

# Add team slaves
nmcli connection add \
    type ethernet \
    con-name team0-slave1 \
    ifname eth0 \
    master team0

nmcli connection add \
    type ethernet \
    con-name team0-slave2 \
    ifname eth1 \
    master team0

# Configure IP
nmcli connection modify team0 \
    ipv4.method manual \
    ipv4.addresses "192.168.1.100/24"

8. Scripting and Automation

8.1 Script-Friendly Output

# Terse mode (colon-separated values)
nmcli -t device status
# Output: eth0:ethernet:connected:Wired connection 1

# Get specific values
nmcli -g IP4.ADDRESS device show eth0
# Output: 192.168.1.100/24

# Multiple fields
nmcli -g NAME,UUID connection show
# Output: Wired connection 1:uuid-here

# Fields option with terse mode
nmcli -t -f NAME,TYPE,DEVICE connection show

# Mode for machine parsing
nmcli -m tabular connection show

8.2 Exit Codes

Exit Code Meaning
0 Success
1 Unknown or unspecified error
2 Invalid user input, wrong nmcli invocation
3 Timeout expired
4 Connection activation failed
5 Connection deactivation failed
6 Disconnecting device failed
7 Connection deletion failed
8 NetworkManager is not running
10 Connection, device, or access point does not exist

8.3 Example Scripts

Network Status Check Script

#!/bin/bash
# network-check.sh - Check network connectivity

# Check if NetworkManager is running
if ! systemctl is-active --quiet NetworkManager; then
    echo "ERROR: NetworkManager is not running"
    exit 1
fi

# Get connectivity status
CONNECTIVITY=$(nmcli -t -f CONNECTIVITY general)

echo "Connectivity: $CONNECTIVITY"

case "$CONNECTIVITY" in
    full)
        echo "✓ Full internet connectivity"
        exit 0
        ;;
    limited|portal)
        echo "⚠ Limited connectivity (captive portal?)"
        exit 1
        ;;
    none)
        echo "✗ No connectivity"
        exit 2
        ;;
    *)
        echo "? Unknown connectivity status"
        exit 3
        ;;
esac

Connection Setup Script

#!/bin/bash
# setup-network.sh - Configure network connection

CONNECTION_NAME="Production-Eth"
INTERFACE="eth0"
IP_ADDRESS="192.168.1.100/24"
GATEWAY="192.168.1.1"
DNS="8.8.8.8,8.8.4.4"

# Check if connection exists
if nmcli connection show "$CONNECTION_NAME" &>/dev/null; then
    echo "Connection exists, modifying..."
    nmcli connection modify "$CONNECTION_NAME" \
        ipv4.method manual \
        ipv4.addresses "$IP_ADDRESS" \
        ipv4.gateway "$GATEWAY" \
        ipv4.dns "$DNS"
else
    echo "Creating new connection..."
    nmcli connection add \
        type ethernet \
        con-name "$CONNECTION_NAME" \
        ifname "$INTERFACE" \
        ipv4.method manual \
        ipv4.addresses "$IP_ADDRESS" \
        ipv4.gateway "$GATEWAY" \
        ipv4.dns "$DNS"
fi

# Activate connection
if nmcli connection up "$CONNECTION_NAME"; then
    echo "✓ Connection activated successfully"
    
    # Verify IP assignment
    IP=$(nmcli -g IP4.ADDRESS device show "$INTERFACE")
    echo "Current IP: $IP"
    
    # Test gateway
    if ping -c 3 -W 2 "$GATEWAY" &>/dev/null; then
        echo "✓ Gateway reachable"
    else
        echo "⚠ Cannot reach gateway"
    fi
else
    echo "✗ Failed to activate connection"
    exit 1
fi

WiFi Auto-Connect Script

#!/bin/bash
# wifi-connect.sh - Connect to preferred WiFi network

PREFERRED_NETWORKS=("HomeWiFi" "OfficeWiFi" "MobileHotspot")

# Rescan for networks
nmcli device wifi rescan

# Try each preferred network
for network in "${PREFERRED_NETWORKS[@]}"; do
    # Check if network is available
    if nmcli -t -f SSID device wifi list | grep -q "^${network}$"; then
        echo "Found network: $network"
        
        # Check if connection profile exists
        if nmcli -t -f NAME connection show | grep -q "^${network}$"; then
            echo "Connecting to $network..."
            if nmcli connection up "$network"; then
                echo "✓ Connected to $network"
                exit 0
            fi
        else
            echo "Connection profile not found for $network"
        fi
    fi
done

echo "✗ No preferred networks found"
exit 1

Connection Monitor Script

#!/bin/bash
# monitor-connection.sh - Monitor and log connection changes

LOG_FILE="/var/log/network-changes.log"

log_message() {
    echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOG_FILE"
}

# Get initial state
PREV_STATE=$(nmcli -t -f STATE general)
log_message "Monitoring started. Initial state: $PREV_STATE"

while true; do
    sleep 5
    
    CURR_STATE=$(nmcli -t -f STATE general)
    
    if [ "$CURR_STATE" != "$PREV_STATE" ]; then
        log_message "State changed: $PREV_STATE -> $CURR_STATE"
        
        # Log active connections
        ACTIVE=$(nmcli -t -f NAME connection show --active)
        log_message "Active connections: $ACTIVE"
        
        PREV_STATE="$CURR_STATE"
    fi
done

8.4 Error Handling in Scripts

#!/bin/bash
# Example with proper error handling

# Enable error handling
set -e  # Exit on error
set -u  # Exit on undefined variable

# Function to handle errors
error_exit() {
    echo "ERROR: $1" >&2
    exit 1
}

# Check if running as root (if needed)
[[ $EUID -eq 0 ]] || error_exit "This script must be run as root"

# Check if NetworkManager is running
systemctl is-active --quiet NetworkManager || \
    error_exit "NetworkManager is not running"

# Try to bring up connection with timeout
if ! nmcli -w 30 connection up "My-Connection"; then
    error_exit "Failed to activate connection"
fi

# Verify connectivity
if ! ping -c 3 8.8.8.8 &>/dev/null; then
    echo "WARNING: No internet connectivity" >&2
fi

echo "SUCCESS: Network configured"
exit 0

9. Advanced Features

9.1 Connection Import and Export

# Export connection to file
# (Note: Use nm-connection-editor GUI for graphical export)
# Via command line, manually copy the file:
sudo cp /etc/NetworkManager/system-connections/My-Connection.nmconnection \
    ~/backup/

# Import VPN connection
nmcli connection import type openvpn file /path/to/config.ovpn

# Import generic connection
nmcli connection load /path/to/connection.nmconnection

# Bulk export
for conn in /etc/NetworkManager/system-connections/*.nmconnection; do
    cp "$conn" ~/network-backup/
done

9.2 Secrets Management

# Show connection with passwords visible
nmcli -s connection show "My-Connection"

# Modify password
nmcli connection modify "WiFi" \
    wifi-sec.psk "newpassword"

# Remove saved password (will prompt when connecting)
nmcli connection modify "WiFi" \
    wifi-sec.psk ""

# Store password in keyring vs connection file
nmcli connection modify "My-Connection" \
    connection.permissions ""

9.3 Dispatcher Scripts

NetworkManager Dispatcher: Scripts in /etc/NetworkManager/dispatcher.d/ run when network state changes.
# Example dispatcher script
# File: /etc/NetworkManager/dispatcher.d/10-my-script

#!/bin/bash
# Arguments: $1 = interface, $2 = action

INTERFACE=$1
ACTION=$2

case "$ACTION" in
    up)
        echo "Interface $INTERFACE is up" | logger
        # Run custom commands
        ;;
    down)
        echo "Interface $INTERFACE is down" | logger
        # Run cleanup commands
        ;;
    vpn-up)
        echo "VPN connection established" | logger
        # VPN-specific actions
        ;;
    vpn-down)
        echo "VPN connection closed" | logger
        ;;
esac

exit 0

# Make executable:
# sudo chmod +x /etc/NetworkManager/dispatcher.d/10-my-script

9.4 Static Routes

# Add static route
nmcli connection modify "My-Connection" \
    +ipv4.routes "10.0.0.0/8 192.168.1.254"

# Add route with metric
nmcli connection modify "My-Connection" \
    +ipv4.routes "10.0.0.0/8 192.168.1.254 100"

# Remove route
nmcli connection modify "My-Connection" \
    -ipv4.routes "10.0.0.0/8 192.168.1.254"

# Ignore automatically obtained routes
nmcli connection modify "My-Connection" \
    ipv4.ignore-auto-routes yes

# Never use as default route
nmcli connection modify "My-Connection" \
    ipv4.never-default yes

9.5 Connection Permissions

# Make connection available to specific user
nmcli connection modify "My-Connection" \
    connection.permissions "user:john:;"

# Make available to multiple users
nmcli connection modify "My-Connection" \
    connection.permissions "user:john:;user:jane:;"

# Remove user restrictions (system-wide)
nmcli connection modify "My-Connection" \
    connection.permissions ""

10. Troubleshooting with nmcli

10.1 Diagnostic Commands

# Check overall status
nmcli general status

# Check device status
nmcli device status

# Check active connections
nmcli connection show --active

# Get detailed device info
nmcli device show eth0

# Check logs
journalctl -u NetworkManager -n 50

# Monitor real-time changes
nmcli monitor

# Test connectivity
nmcli networking connectivity check

10.2 Common Issues and Solutions

Issue: Connection Won't Activate

# Check connection details
nmcli connection show "My-Connection"

# Check device state
nmcli device status

# Try bringing device up first
nmcli device connect eth0

# Check for conflicts
nmcli connection show --active

# Deactivate conflicting connection
nmcli connection down "Other-Connection"

# Try with longer timeout
nmcli -w 60 connection up "My-Connection"

# Check logs for errors
journalctl -u NetworkManager -n 100 | grep -i error

Issue: No IP Address Assigned

# Check IP method
nmcli -f ipv4.method connection show "My-Connection"

# Verify DHCP is working (if using auto)
nmcli connection modify "My-Connection" ipv4.method auto
nmcli connection up "My-Connection"

# Check if address is assigned
nmcli -f IP4.ADDRESS device show eth0

# Try manual DHCP request
nmcli device reapply eth0

# Check DHCP logs
journalctl -u NetworkManager | grep -i dhcp

Issue: DNS Not Working

# Check DNS settings
nmcli -f ipv4.dns device show eth0

# Check resolv.conf
cat /etc/resolv.conf

# Set DNS manually
nmcli connection modify "My-Connection" \
    ipv4.dns "8.8.8.8,8.8.4.4"

# Ensure not ignoring auto DNS
nmcli connection modify "My-Connection" \
    ipv4.ignore-auto-dns no

# Restart connection
nmcli connection down "My-Connection"
nmcli connection up "My-Connection"

# Test DNS
nslookup google.com
dig google.com

Issue: Changes Not Persisting

# Ensure connection is saved
nmcli connection modify "My-Connection" connection.id "My-Connection"

# Check connection files exist
ls -l /etc/NetworkManager/system-connections/

# Reload connections from disk
nmcli connection reload

# Check permissions
ls -l /etc/NetworkManager/system-connections/My-Connection.nmconnection
# Should be: -rw------- root root

# Fix permissions if needed
sudo chmod 600 /etc/NetworkManager/system-connections/*.nmconnection
sudo chown root:root /etc/NetworkManager/system-connections/*.nmconnection

10.3 Debug Mode

# Enable debug logging temporarily
sudo nmcli general logging level DEBUG domains ALL

# View debug logs
journalctl -u NetworkManager -f

# Restore normal logging
sudo nmcli general logging level INFO domains ALL

# Or edit config file for persistent debug
sudo vi /etc/NetworkManager/NetworkManager.conf
# Add:
[logging]
level=DEBUG
domains=ALL

# Restart NetworkManager
sudo systemctl restart NetworkManager

11. Best Practices

11.1 Naming Conventions

Connection Naming Best Practices:

11.2 Script Best Practices

11.3 Configuration Management

Practice Implementation
Version Control Store connection files in Git
Backup Before Changes cp /etc/NetworkManager/system-connections/* /backup/
Document Changes Keep changelog with configuration files
Test Before Production Create test connections first
Automate Deployments Use Ansible/Puppet/Salt
Monitor Changes Use dispatcher scripts to log

11.4 Security Best Practices

Security Considerations:

12. Quick Reference

12.1 Most Common Commands

Task Command
Show status nmcli
List devices nmcli device
List connections nmcli connection
Show connection details nmcli connection show "Name"
Activate connection nmcli connection up "Name"
Deactivate connection nmcli connection down "Name"
List WiFi networks nmcli device wifi list
Connect to WiFi nmcli device wifi connect "SSID" password "pass"
Add static IP nmcli con add type ethernet ifname eth0 ipv4.method manual ipv4.addresses 192.168.1.100/24
Modify connection nmcli connection modify "Name" ipv4.dns "8.8.8.8"
Delete connection nmcli connection delete "Name"
Reload connections nmcli connection reload

12.2 Command Cheat Sheet

# === GENERAL ===
nmcli general status                    # Overall status
nmcli general hostname                  # Show hostname
nmcli general hostname new-name         # Set hostname

# === NETWORKING ===
nmcli networking on                     # Enable networking
nmcli networking off                    # Disable networking
nmcli networking connectivity           # Check connectivity

# === RADIO ===
nmcli radio wifi                        # WiFi status
nmcli radio wifi on/off                 # WiFi control
nmcli radio all on/off                  # All radios control

# === DEVICES ===
nmcli device                            # List devices
nmcli device show                       # Show device details
nmcli device show eth0                  # Specific device
nmcli device connect eth0               # Connect device
nmcli device disconnect eth0            # Disconnect device
nmcli device wifi list                  # List WiFi networks
nmcli device wifi rescan                # Rescan WiFi
nmcli device monitor                    # Monitor changes

# === CONNECTIONS ===
nmcli connection                        # List connections
nmcli connection show                   # List all
nmcli connection show --active          # Active only
nmcli connection show "Name"            # Details
nmcli connection up "Name"              # Activate
nmcli connection down "Name"            # Deactivate
nmcli connection reload                 # Reload all
nmcli connection delete "Name"          # Delete
nmcli connection clone "Old" "New"      # Clone

# === MODIFY ===
nmcli con mod "Name" ipv4.method auto                        # DHCP
nmcli con mod "Name" ipv4.method manual                      # Static
nmcli con mod "Name" ipv4.addresses "192.168.1.100/24"      # Set IP
nmcli con mod "Name" ipv4.gateway "192.168.1.1"             # Set gateway
nmcli con mod "Name" ipv4.dns "8.8.8.8,8.8.4.4"            # Set DNS
nmcli con mod "Name" +ipv4.dns "1.1.1.1"                    # Add DNS
nmcli con mod "Name" -ipv4.dns "8.8.8.8"                    # Remove DNS
nmcli con mod "Name" connection.autoconnect yes             # Autoconnect

# === CREATE ===
# DHCP Ethernet
nmcli con add type ethernet con-name "Name" ifname eth0

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

# WiFi
nmcli con add type wifi con-name "Name" ifname wlan0 ssid "SSID" \
    wifi-sec.key-mgmt wpa-psk wifi-sec.psk "password"

# === SCRIPTING ===
nmcli -t device status                  # Terse output
nmcli -g IP4.ADDRESS device show eth0   # Get specific value
nmcli -f NAME,TYPE connection show      # Specific fields

12.3 Connection Property Reference

Property Example Value Description
connection.id My-Connection Connection name
connection.interface-name eth0 Network interface
connection.autoconnect yes/no Auto-activate
connection.autoconnect-priority 0-999 Priority (lower=higher)
ipv4.method auto, manual, disabled IP configuration method
ipv4.addresses 192.168.1.100/24 IP address(es)
ipv4.gateway 192.168.1.1 Default gateway
ipv4.dns 8.8.8.8,8.8.4.4 DNS servers
ipv4.dns-search company.local DNS search domains
ipv4.routes 10.0.0.0/8 192.168.1.254 Static routes
802-3-ethernet.mtu 1500, 9000 MTU size
802-11-wireless.ssid MyNetwork WiFi SSID
wifi-sec.key-mgmt wpa-psk WiFi security type
wifi-sec.psk password WiFi password

13. Summary

nmcli Quick Start

  1. Check status: nmcli
  2. List devices: nmcli device
  3. List connections: nmcli connection
  4. Create connection: nmcli connection add type ethernet ...
  5. Modify connection: nmcli connection modify "Name" ...
  6. Activate connection: nmcli connection up "Name"
  7. Quick WiFi: nmcli device wifi connect "SSID" password "pass"
Key Advantages of nmcli:

← Back to NetworkManager Index ↑ Back to EXPANDED