Understanding "nmcli" and "nmtui" in Linux

Understanding "nmcli" and "nmtui" in Linux

Table of contents

NetworkManager

The NetworkManager service in Linux is a system daemon that manages network connectivity on the system. It is responsible for handling and configuring network devices, connections, and network settings. NetworkManager provides a unified and consistent interface to manage wired and wireless connections.

There are different ways to interact with the NetworkManager service using either the command line or the GUI. The "nmcli" and "nmtui" utilities are two different ways to interact with the NetworkManager service. The configuration files for the service are stored in the /etc/NetworkManager/system-connections/ directory.

The main role of the NetworkManager service is to handle network devices and connections. A "device" refers to a physical or virtual network interface that enables network traffic, while, a "connection" represents a specific configuration for a particular network device. It can also be referred to as a "network profile".

While a single device can have multiple connection configurations, only one connection can be active at a time for each device.

nmcli

The "nmcli" utility is used to create and edit connection files (network profiles) from the command line.

nmcli device status
#displays the status of all network devices

nmcli connection show
#displays a list of all connections

  • Wired connection 1 :- Name of the network profile.

  • ethernet :- connection type e.g. ethernet, wifi, vlan etc.

  • enp0s3 :- the network interface.

To create a new network profile, we use the "nmcli connection add" command. This command comes with a lot of parameters we can set, but we'll only be covering a few in this article. The data for the added connection is stored in the /etc/NetworkManager/system-connections/ directory as a file with the .nmconnection suffix.

nmcli connection add con-name "Sample Connection Profile" \
type ethernet \
ifname enps03 \
ipv4.method auto 
#use the tab key for auto-completion to see various options to set

The command above adds a new connection called "Sample Connection Profile". It is an ethernet connection for the "enps03" network interface.

"ipv4.method auto" is used to set the network interface to automatically receive IP addresses from the DHCP server. Alternatively, this option can be set to "manual," allowing the configuration of IP addresses using the "ipv4.addresses x.x.x.x/x" parameters.

The network profile has been created but is not activated. The "nmcli connection up" command activates the network connection on the device that it is bound to.

The "nmcli connection modify" command is used to update connection settings. These changes are saved in the /etc/NetworkManager/system-connections/<nameofconnectionfile>.nmconnection as shown in the image below

Read the "man" page for more information on the "nmcli" utility

man nmcli

nmtui

The "nmtui" utility is a text user interface for controlling the NetworkManager service.

With "nmtui" users can configure and manage network connections directly from the terminal, without the need for a graphical user interface (GUI) and without the need to remember "nmcli" commands. It offers a menu-driven interface that allows users to view available network devices, create or modify network connections, connect or disconnect from networks, and configure various network settings.

run the "nmtui" command without any options, it brings out the text interface as shown in the image below.

The arrow and enter keys can be used to easily navigate the text interface to edit connections, create new connections, activate connections etc. Below are snippets of simple navigation steps.

Editing the "Sample Profile Connection" that was created using "nmcli"

"nmtui" provides a straightforward and intuitive method to interact with NetworkManager, enabling users to make network-related configurations effortlessly using simple text-based menus and prompts. This makes it particularly useful for managing network connections in environments without a GUI or when working on remote servers accessed via SSH (Secure Shell).

Voila! QED!