What Is the nmcli Command in Linux and How to Use It

The nmcli command is a powerful command-line utility used in Linux for controlling NetworkManager and configuring network settings directly from the terminal. This article covers the primary purpose of nmcli, its key operational architecture, and practical examples for managing network interfaces, IP addresses, Wi-Fi connections, and network profiles without requiring a graphical user interface.

Understanding nmcli

nmcli stands for NetworkManager Command-Line Interface. It provides a fast, scriptable way to interact with NetworkManager, the default network management daemon across modern distributions such as Red Hat Enterprise Linux, CentOS, Fedora, Ubuntu, and Debian.

Unlike basic utilities like ip or ifconfig, which often apply temporary configurations to interfaces in runtime, nmcli creates and modifies persistent profiles. These profiles automatically reload and persist across system reboots.

The tool revolves around two primary concepts:


Core nmcli Operations and Commands

1. Checking Network Status

To view the overall operational status of NetworkManager:

nmcli general status

To list all available network devices and their current operational state:

nmcli device status

To display all configured connection profiles:

nmcli connection show

To display active connections only:

nmcli connection show --active

2. Managing Connections (Activate and Deactivate)

To bring a network connection down:

nmcli connection down "MyConnection"

To bring a network connection up:

nmcli connection up "MyConnection"

3. Configuring Static IP Addresses

To configure a device with a static IPv4 address, default gateway, and DNS servers:

nmcli connection modify "eth0-profile" ipv4.addresses 192.168.1.100/24
nmcli connection modify "eth0-profile" ipv4.gateway 192.168.1.1
nmcli connection modify "eth0-profile" ipv4.dns "8.8.8.8 8.8.4.4"
nmcli connection modify "eth0-profile" ipv4.method manual

Apply the changes immediately by reloading the connection:

nmcli connection up "eth0-profile"

To switch a static profile back to automatic DHCP:

nmcli connection modify "eth0-profile" ipv4.method auto
nmcli connection up "eth0-profile"

4. Managing Wi-Fi Networks

nmcli allows complete administration of wireless interfaces.

Enable or disable Wi-Fi radio:

nmcli radio wifi on
nmcli radio wifi off

Scan for available Wi-Fi access points:

nmcli device wifi list

Connect to a secure Wi-Fi network:

nmcli device wifi connect "SSID_NAME" password "WIFI_PASSWORD"

5. Creating New Network Profiles

To create a new Ethernet connection configured for DHCP from scratch:

nmcli connection add type ethernet con-name "Office-LAN" ifname eth0

To create a profile with a static IP directly at creation:

nmcli connection add type ethernet con-name "Server-Static" ifname eth0 ip4 10.0.0.50/24 gw4 10.0.0.1

To delete an unneeded profile:

nmcli connection delete "Old-Profile"

Why Use nmcli?