How to Install and Use NetworkManager (NMCLI) on Ubuntu

Ubuntu network manager nmcli command

NetworkManager is a software application that manages network connections and network settings in Ubuntu Linux. An instance of NetworkManager runs for each network connection managed, which includes Wi-Fi and Ethernet connections, mobile broadband (GSM/3G), and others; NetworkManager will attempt to always maintain at least one active network connection available.

If you are a system administrator and manage Ubuntu servers, you probably know the Network manager already NetworkManager. In this tutorial, we will show you how to install and use basic NMCLI commands on Ubuntu 22.04 and Ubuntu 20.04.

Prerequisites

In order to follow this tutorial, you will need:

  • A SuperUser privilege.
  • Network connectivity (either a wireless, wired, or VPN network connection)

Updating Ubuntu

Before installing anything, you need to update your system’s package list by running the following command. This will download the newest versions of all packages available on your Ubuntu Server or Desktop (yes, this command is safe to run even if you already did it before). Updating your system’s package list should be the very first thing that you do after a new install or upgrade.

sudo apt update -y

Install NetworkManager Using APT

Now that your system’s package list is updated, you can use APT (Ubuntu Package Tool) to install NetworkManager.

APT, which stands for Advanced Packaging Tool, is a set of tools to work with Debian/Ubuntu-based Linux distributions. APT simplifies the process of managing software on your system; you can use it to install new packages, remove existing ones and keep track of all of them, among other things.

Installing NetworkManager using APT is safer and more reliable compared to directly installing it from source. However, you might not get the latest version of NetworkManager if you install it from the package repository.

The following command will install NetworkManager without any extra flag or options.

sudo apt install -y network-manager

Install NetworkManager

Once the installation process is complete, you can use the following command to start NetworkManager. The above command will connect to your wireless or wired network connection and activate it.

sudo systemctl start NetworkManager.service

Finally, run the following command to check the NetworkManager status.

Start NetworkManager service

Install NetworkManager using Snap

You can also use Snap to install NetworkManager. Snap is a new package format that was designed to work natively on different distributions.

It has many benefits compared with the traditional way of using .deb packages for installation. The snap packages are isolated from your operating system and they will never conflict with any files from your existing operating system.

In order to install NetworkManager using snap, you need to first install snap on your Ubuntu Server. You can easily do that by running the following command:

sudo apt install snapd -y

Install snapd

Run the following command to enable the snapd.socket. This command actually enables the snapd.socket unit, which means that Snapd will be running as a service. After this service has started, your system will be able to work with snaps. The –now flag makes sure that NetworkManager starts immediately after you issue this command.

sudo systemctl enable --now snapd.socket

Run the following command to create a symbolic link to the snap path found at /var/lib/snapd/snap. This command creates a symbolic link to the snap path found at /var/lib/snapd/snap. The full path name of the created symbolic link is /var/lib/snapd/snapname. Think of this as another way to refer to a file or directory. With ln -s, you can tell Linux that instead of referring to a file or directory by its actual name, you want it to refer to that object by the path that is symbolic of its true location. This way, Ubuntu will be able to create this link and use it.

sudo ln -s /var/lib/snapd/snap /snap

Finally, run the following command to install NetworkManager using Snap.

Install Network Manager using Snap

The snap connections network-manager command returns information about the different network connection settings that are available on your system. snap connections network-manager can help you configure some of its properties by manually editing the NetworkManager configuration file /etc/NetworkManager/NetworkManager.conf

Now, let’s run snap connections network-manager to see what it’s all about.

snap connections network-manager

This command will output something like this.

Show connections

Understanding and Using NetworkManager NMCLI

The nmcli command is used to configure NetworkManager, which is the network connection manager that was created by Red Hat. NetworkManager’s aim is to simplify networking and make it easy for users to connect to a network.

You are managing your server network setting by using the GUI, right? Well, the nmcli command makes this easier. It is more powerful compared to the NetworkManager GUI and it works directly with your system’s networking configuration files.

This means that you don’t have to manually write a bunch of configurations or scripts in order to make a certain change happen via the command line. Just use a few nmcli keywords and you’re all set.

The nmcli general status command will return information about your currently active connections.

To simplify things, we will show you how to use the nmcli general status in order to get NetworkManager information about the different connections available on your system. The connection is an object that contains all network-related information for a specific connection type.

Let’s see what happens when we run this command:

nmcli general status

This will output something like this.

Check network status

The nmcli general hostname command will return hostname information about the system. A hostname is a unique name assigned to each machine so that an operating system can identify it.

Let’s see what happens when we run this command:

nmcli general hostname

This will output something like this.

Show hostname

The nmcli monitor command will monitor NetworkManager’s status. Use this command if you want to quickly check NetworkManager’s connectivity information. When you use the nmcli monitor command, NetworkManager will start actively monitoring all your network connections and bring you a list of interfaces.

nmcli monitor

The man nmcli command can provide you with more information and examples about the nmcli command. Type man nmcli inside a terminal window in order to learn more about this command.

man nmcli

nmcli command

Conclusion

In this tutorial, you learned how to install NetworkManager using the APT and Snap in Ubuntu Linux. You also learned about the different NetworkManager commands that you can use in order to manage your network connections.

Published
Categorized as Ubuntu