nmcli Command Deep-Dive: Your Secret Weapon for Managing Linux Networks

Diving into the Linux terminal to manage network connections can feel like a trip to a foreign land. I get it.

But what if I told you there’s a powerful, friendly tool that can turn you into a network wizard? Meet nmcli.

nmcli might sound cryptic, but it’s one of those tools that, once you learn its language, becomes an indispensable part of your toolkit.

It’s a command-line interface that gives you complete control over your Linux system’s network connections, easily and efficiently.

This guide is your friendly translator. We’ll walk through what nmcli is, why it’s so awesome, and how to use its commands with practical, real-world examples. No jargon, just simple, clear instructions.

So, What Exactly is nmcli?

nmcli stands for NetworkManager Command-Line Interface. Think of NetworkManager as the “brain” that handles all your network connections—from Wi-Fi and Ethernet to mobile broadband. nmcli is your direct line to that brain, allowing you to give it commands right from your terminal.

With nmcli, you can:

  • See all your network devices and check their status.
  • Scan for and connect to Wi-Fi networks.
  • Set up static IP addresses for stable connections.
  • Turn networking on or off with a single command.
  • Manage VPNs and other advanced settings.

It’s fast, lightweight, and comes standard on most modern Linux distributions.

The best part? You don’t need a graphical interface. This makes nmcli perfect for managing servers, “headless” machines (computers without a screen), or for anyone who just loves the speed and power of the terminal.

It’s also a dream come true for automation, allowing you to write scripts that manage network settings for you.

See also: Mastering the Linux Command Line — Your Complete Free Training Guide

Understanding the Basic Language

Every nmcli command follows a simple pattern: nmcli [OPTIONS] OBJECT { COMMAND | help }

It looks a bit technical, but it breaks down easily:

  • OBJECT: This is what you want to manage. The most common objects are general, networking, radio, connection (or con), and device (or dev).
  • COMMAND: This is what you want to do. For example, show, status, up, down, or delete.

You can also use abbreviations, which makes typing commands even faster. For instance, nmcli con show does the same thing as nmcli connection show.

Let’s Get Practical: Essential nmcli Commands

Time to roll up our sleeves. Let’s explore some of the most common and useful tasks you can perform with nmcli.

Checking Your Network’s Pulse

First things first, let’s get a quick snapshot of your network’s health.

See the Big Picture To check the overall status of NetworkManager, just type:

nmcli general status
# Or the super-short version:
nmcli g s

This command tells you if your system is connected to the internet. Simple as that.

List All Your Network Devices To see every network device your system recognizes, use:

nmcli device status
# Or the short version:
nmcli d s

This will show you interfaces like ens18 (your Ethernet card) or lo (the loopback device) and whether they are connected or unmanaged.

View Your Saved Connections NetworkManager saves your network configurations as “profiles” or “connections.” You can have multiple profiles for the same device—like one for your home Wi–Fi and another for the office.

To see all your saved connection profiles, run:

nmcli connection show
# Or:
nmcli con show

This lists the connection names, their unique IDs (UUID), their type, and which device they’re linked to. To see only the connections that are currently active, just add the -a flag:

nmcli con show -a

Bringing Your Connections to Life

Now that you can see what’s going on, let’s start managing your connections.

Scan for and Connect to Wi-Fi This is one of the most common tasks. First, let’s see what Wi-Fi networks are available:

nmcli device wifi list

You’ll get a neat list of all nearby Wi-Fi networks, along with their signal strength and security type.

Found your network? Connecting is a breeze:

nmcli device wifi connect "Your_WiFi_SSID" password "Your_Password"

Just replace the details with your network’s name and password. If the network is hidden, you can add hidden yes to the end of the command.

Create a New Ethernet Connection Need to set up a wired connection? Let’s create one that gets its IP address automatically via DHCP (which is the most common setup).

nmcli connection add type ethernet con-name "My Office Connection" ifname ens18

This creates a new profile named “My Office Connection” for the ens18 interface. To start using it, you need to bring it “up”:

nmcli connection up "My Office Connection"

Set a Static IP Address Sometimes you need a specific, unchanging IP address. Here’s how to create a connection with a static IP:

nmcli con add type ethernet con-name "Static-IP" ifname ens18 ip4 192.168.1.50/24 gw4 192.168.1.1

This command sets the IP address to 192.168.1.50, the subnet mask to 24 (which is 255.255.255.0), and the gateway to 192.168.1.1.

You’ll also want to add DNS servers. You can modify the connection like this:

nmcli con modify "Static-IP" ipv4.dns "8.8.8.8 8.8.4.4"

Becoming an nmcli Power User

Ready to level up? nmcli has some neat tricks to make your life even easier.

Tailor the Output for Scripts (-t) When you’re writing a script, you don’t want pretty headers and spacing. You just want the data. The “terse” option is your best friend. nmcli -t device

This gives you clean, simple output that’s perfect for scripts to read and process.

nmcli -t device
ens192:ethernet:connected:ens192
docker0:bridge:connected (externally):docker0
lo:loopback:unmanaged:

Focus on What Matters (-f) Tired of seeing a dozen columns of information when you only need one or two? Use the fields option to specify exactly what you want to see.

nmcli -f DEVICE,TYPE device
DEVICE   TYPE     
ens192   ethernet 
docker0  bridge   
lo       loopback 

This command will only show the DEVICE and TYPE columns, making the output much cleaner.

Make It Pretty (-p) On the flip side, if you’re reading the output yourself, the “pretty” option formats everything with nice headers and spacing, making it much easier on the eyes.

nmcli -p device
=====================
  Status of devices
=====================
DEVICE   TYPE      STATE                   CONNECTION 
----------------------------------------------------------------------------
ens192   ethernet  connected               ens192     
docker0  bridge    connected (externally)  docker0    
lo       loopback  unmanaged               --     

Disconnect a Device Completely Sometimes, connection down isn’t enough. If you want to take a device completely offline and prevent it from auto-connecting to anything, use disconnect.

nmcli device disconnect ens18


Pro-Tips to Level Up nmcli

Once you’ve got the basics down, these tips and tricks will save you time and headaches.

  • Use Tab Completion, Seriously. Your shell’s tab completion is your best friend with nmcli. Type nmcli con and hit Tab twice. You’ll see all the possible commands (show, up, down, edit, etc.). It’s a fantastic way to discover features without memorizing everything.
  • When in Doubt, Quote It. If your connection name has spaces, like “My Office Wi-Fi”, you must wrap it in quotes. Otherwise, the shell will see My, Office, and Wi-Fi as three separate arguments, and the command will fail.
    • Wrong: nmcli con up My Office Wi-Fi
    • Right: nmcli con up "My Office Wi-Fi"
  • Understand down vs. disconnect. These two commands seem similar but have a key difference. nmcli connection down deactivates a connection profile, but NetworkManager might immediately try to auto-activate another suitable one. nmcli device disconnect takes the entire physical device offline, preventing it from connecting to anything until you manually bring it back up with nmcli device connect.
  • Force a Wi-Fi Rescan. Not seeing a network that you know is there? You can tell nmcli to perform a fresh scan for Wi-Fi networks.
    nmcli device wifi rescan


    Then, run nmcli device wifi list again to see the updated list.

  • Inspect a Connection’s Details. If a connection isn’t working right, you can view every single setting associated with its profile—from IP addresses and DNS servers to MAC addresses and MTU settings. This is a lifesaver for troubleshooting.
    nmcli connection show "Your-Connection-Name"


  • Manually Edited a File? Reload! Sometimes, advanced users edit the connection profiles directly (they live in /etc/NetworkManager/system-connections/). If you do this, NetworkManager won’t see the changes until you tell it to reload.
    nmcli connection reload



Your nmcli Cheatsheet for Everyday Use

Here’s a quick-reference guide to the commands you’ll find yourself using most often.

PurposeCommand
Overall Statusnmcli general status
List Devicesnmcli device status
List All Connectionsnmcli connection show
List Active Connectionsnmcli connection show -a
Scan for Wi-Finmcli device wifi list
Connect to Wi-Finmcli device wifi connect "SSID" password "PASS"
Activate a Connectionnmcli connection up "Connection-Name"
Deactivate a Connectionnmcli connection down "Connection-Name"
Delete a Connectionnmcli connection delete "Connection-Name"
Reload Profilesnmcli connection reload

Final Thoughts

The nmcli tool is truly a Swiss Army knife for anyone managing a Linux system. It gives you precise, powerful control over your network, whether you’re a system administrator, a developer, or just a curious enthusiast.

By getting comfortable with these commands, you’ll be able to handle nearly any networking task from the command line. So go ahead, open up that terminal, and give it a try.

David Cao
David Cao

David is a Cloud & DevOps Enthusiast. He has years of experience as a Linux engineer. He had working experience in AMD, EMC. He likes Linux, Python, bash, and more. He is a technical blogger and a Software Engineer. He enjoys sharing his learning and contributing to open-source.

Articles: 547

Leave a Reply

Your email address will not be published. Required fields are marked *