How to Use the Linux nmcli Command to Manage Network Manager Connections from the Terminal

The Headless Networking Challenge

When operating a standard Linux desktop environment, managing network connections is trivial. You click the Wi-Fi icon in the top right corner of the GUI, select an SSID, and type the password.

However, when deploying headless Linux servers, configuring Raspberry Pi IoT devices over SSH, or attempting to repair a broken server from a recovery terminal, there is no GUI. Historically, administrators were forced to manually edit complex, highly fragile text files like /etc/network/interfaces (Debian) or /etc/sysconfig/network-scripts/ifcfg-eth0 (Red Hat). A single typo in these files could completely isolate the server from the network upon reboot.

Modern Linux distributions utilize the NetworkManager daemon to dynamically handle network connections. To interact with this powerful daemon purely from the command line, administrators use the nmcli (Network Manager Command Line Interface) utility. nmcli provides a programmatic, object-oriented way to scan for Wi-Fi networks, build complex static IP configurations, and seamlessly switch between network profiles without ever touching a raw configuration file.

Step 1: Understanding the Object Hierarchy (Devices vs. Connections)

To use nmcli effectively, you must understand its core architectural distinction: the difference between a Device and a Connection.

  • Device: The physical hardware (e.g., the ethernet card eth0 or the Wi-Fi chip wlan0).
  • Connection: The software profile that holds the IP address, DNS servers, and passwords.

A single physical device (eth0) can have multiple different connection profiles saved on the system (e.g., “Office Network” and “Data Center Network”), but only one profile can be active on the device at a time.

To view the raw hardware devices on the system, run:

nmcli device status

This will list your physical cards and their current state (e.g., connected, disconnected, or unmanaged).

Step 2: Viewing and Activating Connections

To view the software profiles (Connections) saved on the machine, run:

nmcli connection show

You will see a table listing the Profile Name, the UUID, the Type (e.g., 802-3-ethernet), and the physical Device it is currently attached to.

If you have a profile named Wired connection 1 and it is currently down, you can activate it instantly with the up verb:

sudo nmcli connection up "Wired connection 1"

NetworkManager will immediately attempt to negotiate a DHCP lease or apply the static IP defined in that profile.

Step 3: Connecting to Wi-Fi from the Terminal

This is the most common use case for nmcli on headless IoT devices (like a Raspberry Pi).

First, verify your Wi-Fi radio is turned on. You can use the radio object:

nmcli radio wifi on

Next, command the physical Wi-Fi device (wlan0) to scan the local airspace for broadcasting SSIDs:

nmcli device wifi list

The output will beautifully format the available networks, showing the SSID, the signal strength (BSSID), and the security type (e.g., WPA2).

To connect to an SSID named Corp_Guest, you use the device wifi connect verb, providing the password inline:

sudo nmcli device wifi connect "Corp_Guest" password "SecurePassword123"

NetworkManager instantly performs the WPA2 handshake, pulls a DHCP IP address, and automatically creates a persistent Connection profile named Corp_Guest so the device will automatically reconnect upon reboot.

Step 4: Provisioning a Static IP Address (The Interactive Editor)

When provisioning a web server, relying on DHCP is unacceptable. You must assign a static IP address.

While you can string together a massive, single-line nmcli command to do this, it is highly prone to syntax errors. Instead, professional administrators use the interactive edit mode.

Suppose you want to modify the existing Wired connection 1 profile to use a static IP.

sudo nmcli connection edit "Wired connection 1"

Your terminal prompt will change to nmcli>. You are now inside the specific network profile.

First, change the IPv4 method from auto (DHCP) to manual (Static):

nmcli> set ipv4.method manual

Next, define the static IP address and the subnet mask (using CIDR notation, like /24):

nmcli> set ipv4.addresses 10.0.5.50/24

Next, set the default gateway (the router):

nmcli> set ipv4.gateway 10.0.5.1

Finally, set the DNS servers (e.g., Google’s public DNS):

nmcli> set ipv4.dns 8.8.8.8, 1.1.1.1

Once you have built the configuration, you must save it and exit the editor:

nmcli> save
nmcli> quit

To enforce the new static IP, you must aggressively restart the connection profile:

sudo nmcli connection up "Wired connection 1"

Step 5: Rapid Troubleshooting (The Connection Monitor)

If a server is experiencing intermittent packet loss or the DHCP lease keeps failing, troubleshooting network state changes is difficult.

nmcli includes a highly useful, real-time monitoring mode. By using the monitor verb, the terminal will hang and passively watch the NetworkManager daemon.

nmcli monitor

If someone unplugs the physical ethernet cable from the server, you will instantly see a real-time event log indicating the carrier signal was lost and the connection profile transitioned to the disconnected state. This provides immediate, undeniable proof of physical layer failures.

Conclusion

Manually hacking legacy text files to manage networking guarantees configuration drift and catastrophic syntax errors during server deployments. By mastering the nmcli utility, Linux engineers interface directly with the intelligent NetworkManager daemon. The ability to scan for Wi-Fi, toggle radios, and interactively build complex static IP profiles from a pure terminal environment provides absolute control over the server’s network perimeter without ever requiring a graphical user interface.

RELATED POSTS

  • How to Use the Linux jq Command to Parse JSON Data in the Terminal
  • How to Use the Linux tty Command to Identify the Current Terminal Session
  • How to Use the Linux journalctl Command to Read systemd Logs
  • How to Use the diff Command to Compare Two Text Files Line by Line in Linux
  • How to Prevent a Linux System from Sleeping via Terminal
  • Get the best tech tips delivered straight to your inbox.

    Join thousands of readers mastering Apple, Google, Microsoft, and Linux.