In this post I want to summarize some commands you can use in your daily work to configure the network on Linux by using the NetworkManager and its nmcli.

NetworkManager is the standard Linux network configuration tool suite. It supports large range of networking setups, from desktop to servers and mobile and integrates well with popular desktop environments and server configuration management tools.

NetworkManager is designed to be fully automatic by default. It manages the primary network connection and other network interfaces, like Ethernet, Wi-Fi, and Mobile Broadband devices. To use NetworkManager, its service must be started. Starting up NetworkManager depends on the distribution you are running, but NetworkManager ships with systemd service files to do this for most distributions. NetworkManager will then automatically start other services as it requires them (wpa_supplicant for WPA and 802.1x connections, pppd for mobile broadband).

Source: https://networkmanager.dev/docs/admins/




History of the NetworkManager

Red Hat initiated the NetworkManager project in 2004 with the goal of enabling Linux users to deal more easily with modern networking needs, particularly wireless networking.

Its primary goal was to automate the process of connecting to networks (wired, wireless, mobile broadband, etc.) and make it seamless for desktop users. The idea was to create a tool that would automatically manage network connections without requiring manual configuration, especially for laptops that would frequently switch between different networks (home, office, public Wi-Fi, etc.).

NetworkManager was initially developed for GNOME and became closely integrated with it, using tools like nm-applet to provide a system tray icon for managing network connections. The 1.0 release of NetworkManager occurred in 2005, and it quickly became the default network management tool for many Linux desktop distributions, especially those using GNOME.

By the late 2000s, major Linux distributions like Fedora, Ubuntu, and Debian had adopted NetworkManager as their default tool for handling network connections. Its ease of use and growing feature set made it a key component in desktop Linux systems.

While initially aimed at desktop users, NetworkManager started gaining traction in server environments during the 2010s. This was partly driven by its ability to manage more complex networking configurations like bridges, bonds, and VLANs.

NetworkManager’s command-line interface (nmcli) was improved to allow administrators to configure networks in headless or server environments without needing a GUI. This made it a more attractive option for system administrators who were looking for a unified tool to manage both desktop and server network configurations.

As of 2024, NetworkManager is the default network management tool in many major Linux distributions, including Fedora, Ubuntu, Debian, and Arch Linux. It has become the go-to tool for network management, from simple desktop setups to complex server environments, containers, and cloud infrastructure.


Key Components

  • nmcli: A command-line interface for NetworkManager that allows users to configure and manage network connections in a terminal or on headless systems.
  • nmtui: A text-based user interface for NetworkManager, providing a simpler way to manage networks without requiring a full GUI.
  • nm-applet: A system tray applet for managing networks in desktop environments, providing a graphical interface for NetworkManager.



NetworkManager in SUSE Linux

In the SUSE world, NetworkManager is only supported by SUSE for desktop workloads with SLED or the Workstation extension. All server certifications are done with wicked as the network configuration tool, and using NetworkManager may invalidate them. NetworkManager is not supported by SUSE for server workloads.

Source: https://documentation.suse.com/sles/15-SP5/html/SLES-all/cha-nm.html


SUSE Linux Enterprise (SLE) is a Linux-based operating system developed by SUSE. It is available in two editions, suffixed with Server (SLES) for servers and mainframes, and Desktop (SLED) for workstations and desktop computers.

Source: https://en.wikipedia.org/wiki/SUSE_Linux_Enterprise



Checking the Status of NetworkManager

To check whether NetworkManager is running:

# systemctl status NetworkManager


In case NetworkManager is running and our network interface (NIC) is managed by the NetworkManager, we can retrieve the IP configuration for each device by just issue the nmcli command as shown below.


To list all devices detected by NetworkManager, we can just enter:

# nmcli device

On the figure above you can see the network interface (NIC) named ens224 under the DEVICE column, this is the name of the device.

The last column CONNECTION is the connection name which is here also ens224.

NetworkManager configuration is based on the concepts of device and connection. A device maps a network interface and a connection represents the full configuration to be applied on a device and is just a list of properties.

Properties belonging to the same configuration area are grouped into settings (e.g., the ipv4 setting group properties like addresses, gateway, and routes).

Source: https://www.redhat.com/sysadmin/becoming-friends-networkmanager


We can also configure a device to be not managed by the NetworkManager by using the following command. This change is not persistent, after rebooting the device is managed again by NetworkManager.

# nmcli device set <interface_name> managed no
# nmcli device set ens224 managed no




Change IP Address and Subnet Mask by using the nmcli

# nmcli device status
# nmcli connection show

# sudo nmcli connection modify <connection_name> ipv4.addresses <xxx.xxx.xxx.xxx/xx>
# sudo nmcli connection modify ens224 ipv4.addresses 192.168.2.85/24

# sudo nmcli device reapply <interface_name>
# sudo nmcli device reapply ens224


Check if the new IP address and subnet mask was correctly applied.
# ip addr show


List devices managed by NetworkManager
# nmcli device

List details for all devices
# nmcli device show

List details for a given device
# nmcli device <interface_name>
# nmcli device ens224



Assign multiple IP addresses to a single Network Interface

We can assign multiple IP addresses to a single network interface (NIC) by using the nmcli in interactive mode.

# nmcli device status

# nmcli connection edit <connection_name>
# nmcli connection edit ens224

nmcli> set ipv4.addresses 192.168.2.85/24,192.168.2.86/24,192.168.2.87/24
nmcli> save persistent
nmcli> quit


Finally in order to take effect we need to reapply the changes to the network interface by executing the following command.

# sudo nmcli device reapply <interface_name>
# sudo nmcli device reapply ens224




Change the Default Gateway by using the nmcli

To set or change the IPv4 default gateway, enter:

# nmcli connection modify <connection_name> ipv4.gateway <IPv4_gateway_address>
# nmcli connection modify <connection_name> ipv6.gateway <IPv6_gateway_address>

# nmcli connection modify ens224 ipv4.gateway 192.168.2.1

In order the changes to take effect we can either reapply the settings or restart the network connection
# nmcli device reapply <interface_name>
# nmcli device reapply ens224

or 

Restart network connection
# nmcli connection up <connection_name>
# nmcli connection up ens224


Verify the changes:

# ip route show

or

# ip -4 route



Configuring Static Routes Using nmcli

To configure a static route for an existing Ethernet connection using the command line:

nmcli connection modify <connection_name> +ipv4.routes "<destination subnet> <IPv4_gateway_address>"
# nmcli connection modify ens224 +ipv4.routes "10.0.0.0/24 192.168.2.253"

This will route all traffic for the 10.0.0.0/24 subnet through the gateway with the IP 192.168.2.253.


Delete a static route

To delete a static route we can use the ip route del command.

# ip route del 10.0.0.0/24

To delete default route run:
# sudo ip route del default



Configuring Host Names Using nmcli

The NetworkManager tool nmcli can also be used to query and set the static host name in the /etc/hostname file.

To query the static host name, issue the following command:
# nmcli general hostname

To set the static host name to my-server, issue the following command as root:
# nmcli general hostname my-server




Using the nmcli Interactive Mode to configure the Network

You can also change the default gateway and in general the network configuration on an existing connection by using the nmcli interactive mode like show below.

Open the nmcli interactive mode for the required connection:
# nmcli connection edit <connection_name>

We are now in the nmcli shell:
nmcli> set ipv4.gateway <IPv4_gateway_address>
nmcli> set ipv6.gateway <IPv6_gateway_address>

verify the changes:
nmcli> print

Save the configuration:
nmcli> save persistent

Restart the network connection for changes to take effect:
nmcli> activate <connection_name>

Leave the nmcli interactive mode:
nmcli> quit


Source: https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/8/html/configuring_and_managing_networking/managing-the-default-gateway-setting_configuring-and-managing-networking#setting-the-default-gateway-on-an-existing-connection-by-using-the-nmcli-interactive-mode_managing-the-default-gateway-setting




Using the nm-connection-editor to configure the Network

For desktop environments with a GNOME GUI we can also use the nm-connection-editor application to change the default gateway and in general the network configuration.

Alternatively when just using the command line with PuTTY we can enable X11 Forwarding to redirect the GUI to a local installed X Window System Server like shown in my following post.






Using the nmtui tool to configure the Network

We have one more tool with nmtui to configure the network if managed by the NetworkManager.

The nmtui tool is used in a terminal window. It is contained in the NetworkManager-tui package, but it is not installed along with NetworkManager by default. To install NetworkManager-tui:

# yum install NetworkManager-tui


Start the nmtui tool to configure the network. The configuration is similar to the YaST tool for SUSE Linux and I think self-explaining.

# nmtui






Where does NetworkManager store the Configuration

Previously, NetworkManager stored network profiles in ifcfg format in this directory (/etc/sysconfig/network-scripts/). However, the ifcfg format is deprecated. By default, NetworkManager no longer creates new profiles in this format.

Connection profiles in keyfile format have many benefits. For example, this format is INI file-based and can easily be parsed and generated.

Each section in NetworkManager keyfiles corresponds to a NetworkManager setting name as described in the nm-settings and nm-settings-keyfile man pages. Each key-value-pair in a section is one of the properties listed in the settings specification of the man page.

If you still use network profiles in ifcfg format, consider migrating them to keyfile format. To migrate all profiles at once, enter:

# nmcli connection migrate

This command migrates all profiles from ifcfg format to keyfile format and stores them in /etc/NetworkManager/system-connections/ as shown in the figure below.

!! Note !!
Typos or incorrect placements of parameters can lead to unexpected behavior. Therefore, do not manually edit or create NetworkManager profiles.


Alternatively, to migrate only a specific profile, enter:

# nmcli connection migrate <profile_name|UUID|D-Bus_path>





Links

NetworkManager
https://networkmanager.dev/

Configuring IP Networking with nmcli
https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/7/html/networking_guide/sec-configuring_ip_networking_with_nmcli#sec-Configuring_IP_Networking_with_nmcli

Configuring Host Names Using nmcli
https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/7/html/networking_guide/sec-configuring_host_names_using_nmcli

Get started with NetworkManager on Linux
https://opensource.com/article/22/4/networkmanager-linux

Becoming friends with NetworkManager
https://www.redhat.com/sysadmin/becoming-friends-networkmanager