DEV Community

Cover image for NMCLI : The networking master
SAHIL
SAHIL

Posted on

NMCLI : The networking master

The nmcli command is a powerful, versatile command-line tool for controlling the NetworkManager daemon and reporting on the network's status. It's the modern, go-to utility for network management on Linux systems that use NetworkManager, which is most modern distributions.

What it's for 🛠️
nmcli is primarily used for tasks that would otherwise require a graphical user interface (GUI) or manual editing of configuration files. It allows you to manage network connections, devices, and global networking settings directly from the terminal. This makes it ideal for servers, headless machines, or for system administrators who prefer the command line.

Key Use Cases
nmcli is structured around a few key objects, each with its own set of commands:

  • nmcli general: Provides a quick overview of the overall network status, including connectivity and hardware states.
  • Example: nmcli general status shows if you're connected to a network and if Wi-Fi and mobile broadband are enabled.
  • nmcli connection (or nmcli con): Manages network connections, which are essentially profiles containing all the information needed to connect to a network.
  • Viewing connections: nmcli con show
  • lists all saved connection profiles.
  • Adding a connection: You can create new connections for Ethernet, Wi-Fi, VPNs, and more. For instance, to add a static Ethernet connection: Bash

sudo nmcli con add type ethernet con-name my-static-eth ifname eth0 ipv4.method manual ipv4.address 192.168.1.100/24 ipv4.gateway 192.168.1.1

Enter fullscreen mode Exit fullscreen mode

Activating/Deactivating:


nmcli con up "my-static-eth" activates the connection, and nmcli con down "my-static-eth" deactivates it.

Enter fullscreen mode Exit fullscreen mode

Modifying: nmcli con mod "my-static-eth" ipv4.dns "8.8.8.8" changes the DNS server for that connection profile.

Deleting: nmcli con del "my-static-eth" removes the connection profile.

nmcli device (or nmcli dev): Interacts with network devices (e.g., eth0, wlan0).

Checking device status: nmcli dev status lists all network interfaces and their current state.

Connecting to Wi-Fi: nmcli dev wifi connect "My_WiFi_SSID" password "my_password" connects to a wireless network.

nmcli radio: Manages the radio switches for wireless technologies like Wi-Fi and WWAN.

Toggling Wi-Fi: nmcli radio wifi off disables the wireless radio.

nmcli is also designed to be script-friendly, with options like -t (for terse output) and -g (for getting a specific value) that make it easy to parse its output in scripts.

Mastering the nmcli command is a significant step toward becoming proficient in Linux networking. Its powerful, script-friendly nature makes it an essential tool for system administrators and developers alike. By moving beyond traditional tools like ifconfig and embracing NetworkManager's command-line interface, you gain precise control over your network configurations. So, the next time you need to connect to a new Wi-Fi network, troubleshoot a connection, or automate network setup on a server, remember that nmcli is your go-to command for getting the job done efficiently and effectively.

Top comments (0)