Install and use NMCLI tool on Debian Linux

|
Last Updated:
|
|

In this tutorial, we provide a step by step guide on how to install and use NMCLI tool on Debian Linux.

According to man pages:

NMCLI is a command-line tool for controlling NetworkManager and reporting network status. It can be utilized as a replacement for nm-applet or other graphical clients. nmcli is used to create, display, edit, delete, activate, and deactivate network connections, as well as control and display network device status.

Typical uses include:

  • Scripts: Utilize NetworkManager via nmcli instead of managing network connections manually. nmcli supports a terse output format which is better suited for script processing. Note that NetworkManager can also execute scripts, called “dispatcher scripts”, in response to network events. See NetworkManager(8) for details about these dispatcher scripts.
  • Servers, headless machines, and terminals: nmcli can be used to control NetworkManager without a GUI, including creating, editing, starting and stopping network connection and viewing network status.

Using NMCLI tool on Debian Linux

On on headless Debian systems, nmcli tool may not be installed by default.

If not installed, then you can run the command below to install it;

apt install network-manager

The command installs a command line tool, nmcli and nmtui, a text User Interface for controlling NetworkManager.

You can then use nmcli command to create, display, edit, delete, activate, and deactivate network connections, as well as control and display network device status.

The command line syntax for nmcli command;

nmcli [OPTIONS...] {help | general | networking | radio | connection | device | agent | monitor} [COMMAND] [ARGUMENTS...]

When run with no arguments;

nmcli

This is the sample output;


enp0s8: connected to Wired connection 1
        "Intel 82540EM"
        ethernet (e1000), 08:00:27:56:8E:61, hw, mtu 1500
        inet4 192.168.58.26/24
        route4 192.168.58.0/24
        inet6 fe80::a00:27ff:fe56:8e61/64
        route6 fe80::/64

enp0s3: unmanaged
        "Intel 82540EM"
        ethernet (e1000), 08:00:27:88:1B:AE, hw, mtu 1500

lo: unmanaged
        "lo"
        loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536

Use "nmcli device show" to get complete information about known devices and
"nmcli connection show" to get an overview on active connection profiles.

Consult nmcli(1) and nmcli-examples(7) manual pages for complete usage details.

To show overall status of NetworkManager;

nmcli general
STATE      CONNECTIVITY  WIFI-HW  WIFI     WWAN-HW  WWAN    
connected  limited       enabled  enabled  enabled  enabled

To show complete information about known devices;

nmcli device show

GENERAL.DEVICE:                         enp0s8
GENERAL.TYPE:                           ethernet
GENERAL.HWADDR:                         08:00:27:56:8E:61
GENERAL.MTU:                            1500
GENERAL.STATE:                          100 (connected)
GENERAL.CONNECTION:                     Wired connection 1
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/ActiveConnection/2
WIRED-PROPERTIES.CARRIER:               on
IP4.ADDRESS[1]:                         192.168.58.31/24
IP4.ADDRESS[2]:                         192.168.58.26/24
IP4.GATEWAY:                            --
IP4.ROUTE[1]:                           dst = 192.168.58.0/24, nh = 0.0.0.0, mt = 100
IP4.ROUTE[2]:                           dst = 169.254.0.0/16, nh = 0.0.0.0, mt = 1000
IP6.ADDRESS[1]:                         fe80::f3aa:9e8c:be4b:daf9/64
IP6.GATEWAY:                            --
IP6.ROUTE[1]:                           dst = fe80::/64, nh = ::, mt = 100
IP6.ROUTE[2]:                           dst = ff00::/8, nh = ::, mt = 256, table=255
...

To show information about specific device;

nmcli dev sh enp0s8

To show an overview on active connection profiles;

nmcli connection show
NAME                UUID                                  TYPE      DEVICE 
Wired connection 1  049a12b7-79f5-3236-bc50-e69be0d2b618  ethernet  enp0s8

Show system hostname using nmcli;

nmcli general hostname

you can even use abbreviations;

nmcli g h

To see more example usage of nmcli command, run;

man nmcli-examples

More nmcli command usage examples;

Listing available Wi-Fi APs

nmcli device wifi list
IN-USE  BSSID              SSID       MODE   CHAN  RATE        SIGNAL  BARS  SECURITY 
*       E0:CC:7A:3F:78:64  SUDO       Infra  5     130 Mbit/s  43      ▂▄__  WPA2     
        E0:CC:7A:3E:40:6C  CMT_M-A4   Infra  3     130 Mbit/s  19      ▂___  WPA2

Connect to a password-protected wifi network;

nmcli device wifi connect "$SSID" password "$PASSWORD"
nmcli --ask device wifi connect "$SSID"

Showing general information and properties for a Wi-Fi interface;

nmcli -p -f general,wifi-properties device show 

===============================================================================
                          Device details (wlp0s20f3)
===============================================================================
GENERAL.DEVICE:                         wlp0s20f3
GENERAL.TYPE:                           wifi
GENERAL.NM-TYPE:                        NMDeviceWifi
GENERAL.DBUS-PATH:                      /org/freedesktop/NetworkManager/Devices/13
GENERAL.VENDOR:                         Intel Corporation
GENERAL.PRODUCT:                        Wireless-AC 9462
GENERAL.DRIVER:                         iwlwifi
GENERAL.DRIVER-VERSION:                 5.4.0-48-generic
GENERAL.FIRMWARE-VERSION:               48.4fa0041f.0
GENERAL.HWADDR:                         5C:80:B6:86:61:0E
GENERAL.MTU:                            1500
GENERAL.STATE:                          100 (connected)
GENERAL.REASON:                         0 (No reason given)
GENERAL.IP4-CONNECTIVITY:               4 (full)
GENERAL.IP6-CONNECTIVITY:               3 (limited)
GENERAL.UDI:                            /sys/devices/pci0000:00/0000:00:14.3/net/wlp0s20f3
GENERAL.IP-IFACE:                       wlp0s20f3
GENERAL.IS-SOFTWARE:                    no
GENERAL.NM-MANAGED:                     yes
GENERAL.AUTOCONNECT:                    yes
GENERAL.FIRMWARE-MISSING:               no
GENERAL.NM-PLUGIN-MISSING:              no
GENERAL.PHYS-PORT-ID:                   --
GENERAL.CONNECTION:                     SUDO
GENERAL.CON-UUID:                       2f048f49-9ffd-45f4-91e1-0dab7a88a12b
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/ActiveConnection/7
GENERAL.METERED:                        no (guessed)
-------------------------------------------------------------------------------
WIFI-PROPERTIES.WEP:                    yes
WIFI-PROPERTIES.WPA:                    yes
WIFI-PROPERTIES.WPA2:                   yes
WIFI-PROPERTIES.TKIP:                   yes
WIFI-PROPERTIES.CCMP:                   yes
WIFI-PROPERTIES.AP:                     yes
WIFI-PROPERTIES.ADHOC:                  yes
WIFI-PROPERTIES.2GHZ:                   yes
WIFI-PROPERTIES.5GHZ:                   yes

Go through more examples on man nmcli-exmaples.

You can also check our example in the links below;

Connect to WiFi in Linux Using NMCLI command

Create Virtual/Secondary IP addresses on an Interface in Linux

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
koromicha
I am the Co-founder of Kifarunix.com, Linux and the whole FOSS enthusiast, Linux System Admin and a Blue Teamer who loves to share technological tips and hacks with others as a way of sharing knowledge as: "In vain have you acquired knowledge if you have not imparted it to others".

Leave a Comment