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:
- Device: The physical or virtual network interface
hardware (e.g.,
eth0,ens33,wlan0). - Connection: The collection of settings (configurations) applied to a device, such as static IP configurations, DHCP settings, security credentials, and routing tables.
Core nmcli Operations and Commands
1. Checking Network Status
To view the overall operational status of NetworkManager:
nmcli general statusTo list all available network devices and their current operational state:
nmcli device statusTo display all configured connection profiles:
nmcli connection showTo display active connections only:
nmcli connection show --active2. 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 manualApply 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 offScan for available Wi-Fi access points:
nmcli device wifi listConnect 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 eth0To 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.1To delete an unneeded profile:
nmcli connection delete "Old-Profile"Why Use nmcli?
- Headless Servers: It enables full network configuration in server environments that lack a desktop environment.
- Automation and Scripting: Because it returns clear status outputs and exit codes, it is well suited for shell scripts, Ansible playbooks, and cloud-init provisioning.
- Persistent Settings: Changes are automatically
written to underlying configuration files (such as
/etc/NetworkManager/system-connections/or/etc/sysconfig/network-scripts/), eliminating manual configuration file syntax errors.