Linux nmcli Command with Examples
Linux nmcli Command with Examples
Modern Linux systems often use NetworkManager to manage wired, wireless, and other network connections. The nmcli command is the command-line interface for NetworkManager. It allows students, system administrators, and DevOps engineers to inspect network status, create connections, configure IP addresses, connect to Wi-Fi, and troubleshoot networking directly from the terminal.
What is nmcli?
nmcli stands for NetworkManager Command-Line Interface. It is particularly useful on servers or remote systems where a graphical network tool is unavailable. The general syntax is:
nmcli [OPTIONS] OBJECT { COMMAND | help }
Common objects include device, connection, general, and radio.
Check Network Status
To see the overall NetworkManager status, use:
nmcli general status
This displays information such as whether networking is enabled and whether NetworkManager is running.
List Network Devices
To view available network interfaces:
nmcli device status
A typical result may show interfaces such as eth0, wlan0, or modern names such as enp0s3 and wlp2s0, along with their current state.
Show IP Address Information
You can display detailed information about a network device with:
nmcli device show eth0
This can reveal the IP address, gateway, DNS servers, MAC address, and other network parameters.
List Network Connections
NetworkManager stores connection profiles. To list them, run:
nmcli connection show
This is useful for identifying saved Wi-Fi networks, Ethernet profiles, VPN connections, and other configurations.
Connect to Wi-Fi
To list nearby wireless networks:
nmcli device wifi list
To connect to a wireless network:
nmcli device wifi connect "MyWiFi" password "MyPassword"
NetworkManager normally creates and saves a connection profile for future use.
Activate or Disconnect a Connection
To activate an existing connection:
nmcli connection up "Home Network"
To disconnect it:
nmcli connection down "Home Network"
Configure a Static IP Address
An existing connection can be configured with a static IPv4 address:
nmcli connection modify "Office Ethernet" ipv4.addresses 192.168.1.50/24
nmcli connection modify "Office Ethernet" ipv4.gateway 192.168.1.1
nmcli connection modify "Office Ethernet" ipv4.dns "8.8.8.8"
nmcli connection modify "Office Ethernet" ipv4.method manual
nmcli connection up "Office Ethernet"
The nmcli command provides practical experience with Linux networking and NetworkManager. It is valuable for configuring servers, diagnosing connectivity problems, automating network administration, and working in cloud and DevOps environments.