Linux Network Management: Installing and Using ‘nmcli’

Visual depiction of a Linux terminal with the process of installing the nmcli command used for controlling NetworkManager

Are you trying to manage network connections in Linux? If so, you might be feeling a bit overwhelmed, especially if you’re relatively new to Linux. But don’t worry, the ‘nmcli’ command is here to help you navigate your network like a seasoned traffic controller. It’s also available on most package management systems, making the installation process straightforward once you understand the steps.

In this guide, we will walk you through the process of installing and using the ‘nmcli’ command in Linux. We will provide instructions for both APT-based distributions like Debian and Ubuntu, and YUM-based distributions like CentOS and AlmaLinux. We’ll also delve into more advanced topics like compiling from source and installing a specific version of the ‘nmcli’ command. Finally, we’ll wrap up with guidance on how to use the ‘nmcli’ command and verify that the correct version is installed.

So, let’s get started and master network management in Linux with the ‘nmcli’ command!

TL;DR: How Do I Install and Use the ‘nmcli’ Command in Linux?

In most Linux distributions, the 'nmcli' command comes pre-installed. However, if it’s not available, you can install it in Debian based distributions like Ubuntu by running the command sudo apt-get install network-manager. For distributions like CentOS that use RPM package manager yum, you would run the command sudo yum install NetworkManager.

# For Debian based distributions like Ubuntu
sudo apt-get install network-manager

# For RPM based distributions like CentOS
sudo yum install NetworkManager

# Output:
# Reading package lists... Done
# Building dependency tree
# Reading state information... Done
# network-manager is already the newest version (1.10.6-2ubuntu1.4).
# 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

This is a basic way to install the ‘nmcli’ command in Linux, but there’s much more to learn about installing and using ‘nmcli’. Continue reading for more detailed information and advanced usage scenarios.

Understanding and Installing the ‘nmcli’ Command

The ‘nmcli’ command is a network management command-line tool available for Unix-like operating systems. It is a part of the NetworkManager software utility aimed at simplifying the use of networking on Linux and other Unix-like systems. ‘nmcli’ allows you to create, display, edit, delete, activate, and deactivate network connections, as well as control and display network device status.

Installing ‘nmcli’ with APT

If you’re using a Debian-based distribution like Ubuntu, ‘nmcli’ can be installed using the Advanced Packaging Tool (APT). Here’s how you can do it:

sudo apt update
sudo apt install network-manager

# Output:
# [sudo] password for user: 
# Reading package lists... Done
# Building dependency tree
# Reading state information... Done
# network-manager is already the newest version (1.10.6-2ubuntu1.4).
# 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

The above commands first update the package lists for upgrades and new package installations. Then, the ‘network-manager’ package, which includes ‘nmcli’, is installed.

Installing ‘nmcli’ with YUM

If you’re using an RPM-based distribution like CentOS, you can use the Yellowdog Updater, Modified (YUM) to install ‘nmcli’. Here’s how:

sudo yum check-update
sudo yum install NetworkManager

# Output:
# Loaded plugins: fastestmirror, langpacks
# Loading mirror speeds from cached hostfile
# NetworkManager.x86_64 1:1.18.8-2.el7_9 base
# Complete!

Similar to the APT commands, these commands first check for package updates. Then, the ‘NetworkManager’ package, which includes ‘nmcli’, is installed.

Installing ‘nmcli’ with DNF

For newer Fedora distributions and other similar Linux distributions, you can use the Dandified YUM (DNF) package manager to install ‘nmcli’. Here’s how:

sudo dnf check-update
sudo dnf install NetworkManager

# Output:
# Last metadata expiration check: 0:15:34 ago on Mon 21 Feb 2022 08:07:12 PM EST.
# Dependencies resolved.
# Complete!

These commands are similar to the APT and YUM commands. They first check for package updates, and then the ‘NetworkManager’ package, which includes ‘nmcli’, is installed.

Installing ‘nmcli’ from Source Code

While package managers make it easy to install ‘nmcli’, you may prefer to compile and install it from source code. This could be due to the need for a specific version, or to incorporate custom modifications.

Here’s how to install ‘nmcli’ from source:

# Download the source code
wget https://download.gnome.org/sources/NetworkManager/1.32/NetworkManager-1.32.10.tar.xz

# Extract the source code
tar -xf NetworkManager-1.32.10.tar.xz

# Navigate into the directory
cd NetworkManager-1.32.10/

# Configure the build environment
./configure

# Compile the source code
make

# Install 'nmcli'
sudo make install

# Output:
# Making install in src
# make[1]: Entering directory '/home/user/NetworkManager-1.32.10/src'
# make[2]: Entering directory '/home/user/NetworkManager-1.32.10/src'
# make[2]: Nothing to be done for 'install-exec-am'.
# make[2]: Nothing to be done for 'install-data-am'.
# make[2]: Leaving directory '/home/user/NetworkManager-1.32.10/src'
# make[1]: Leaving directory '/home/user/NetworkManager-1.32.10/src'

This sequence of commands downloads the source code, extracts it, navigates into the directory, configures the build environment, compiles the source code, and installs ‘nmcli’.

Installing Different Versions of ‘nmcli’

Different versions of ‘nmcli’ may have different features, bug fixes, or compatibility with different Linux distributions. Here’s how to install a specific version of ‘nmcli’ from source, and using the APT and YUM package managers.

Installing a Specific Version from Source

Installing a specific version from source is similar to the standard installation from source. The only difference is that you need to download the specific version you want. Here’s how:

# Download the source code for a specific version
wget https://download.gnome.org/sources/NetworkManager/1.30/NetworkManager-1.30.0.tar.xz

# Follow the same steps as the standard installation from source

Installing a Specific Version with APT

With APT, you can install a specific version of a package using the ‘=version’ syntax. Here’s how:

# Install a specific version of 'network-manager'
sudo apt install network-manager=1.10.6-2ubuntu1.4

Installing a Specific Version with YUM

With YUM, you can install a specific version of a package using the ‘-version’ syntax. Here’s how:

# Install a specific version of 'NetworkManager'
sudo yum install NetworkManager-1.18.8-2.el7_9

Here’s a comparison of the features of different versions of ‘nmcli’:

VersionFeaturesCompatibility
1.18.8Basic network management featuresCentOS 7
1.30.0Improved Wi-Fi support, bug fixesUbuntu 20.04
1.32.10IPv6 improvements, bug fixesUbuntu 21.04

Basic Usage of ‘nmcli’

Once you’ve installed ‘nmcli’, you can use it to manage network connections. Here’s how to list all network connections:

# List all network connections
nmcli con show

# Output:
# NAME UUID TYPE DEVICE
# Wired connection 1 44a5b272-8e2a-4c70-8e27-fd3e4bf8f67c ethernet eth0

This command shows all network connections, their names, UUIDs, types, and associated devices.

Verifying the Installation

To verify that ‘nmcli’ is installed correctly, you can use the ‘–version’ option. This will display the version of ‘nmcli’ that is currently installed:

# Display the version of 'nmcli'
nmcli --version

# Output:
# nmcli tool, version 1.32.10

This command shows the version of ‘nmcli’ that is currently installed, verifying that the installation was successful.

Alternative Methods for Linux Network Management

While ‘nmcli’ is a powerful tool for managing network connections, it’s not the only one available. There are other methods you can use to manage network connections in Linux, such as the ‘ifconfig’ command and manual network configuration.

Using ‘ifconfig’ for Network Management

The ‘ifconfig’ command is a traditional method for managing network interfaces in Unix-like operating systems. It can be used to configure, control, and query TCP/IP network interface parameters.

Here’s how you can use ‘ifconfig’ to display the status of all network interfaces:

# Display the status of all network interfaces
ifconfig -a

# Output:
# eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
#        inet 192.168.1.10  netmask 255.255.255.0  broadcast 192.168.1.255
#        inet6 fe80::20c:29ff:fe00:4c01  prefixlen 64  scopeid 0x20<link>
#        ether 00:0c:29:00:4c:01  txqueuelen 1000  (Ethernet)

This command shows the status of all network interfaces, including their IP addresses, netmasks, and MAC addresses.

Manual Network Configuration

For those who prefer a hands-on approach, you can manually configure network connections by editing configuration files. This method requires a good understanding of networking and the Linux file system.

Here’s how you can manually configure a static IP address for a network interface:

# Open the network interface configuration file
sudo nano /etc/network/interfaces

# Add the following lines
# iface eth0 inet static
# address 192.168.1.10
# netmask 255.255.255.0
# gateway 192.168.1.1
# dns-nameservers 8.8.8.8 8.8.4.4

# Save and exit

# Restart the network service
sudo service networking restart

# Output:
# [ ok ] Restarting networking (via systemctl): networking.service.

This sequence of commands opens the network interface configuration file, adds configuration lines for a static IP address, saves and exits the file, and restarts the network service. The configuration lines set a static IP address, netmask, gateway, and DNS servers for the ‘eth0’ network interface.

‘nmcli’ vs ‘ifconfig’ vs Manual Configuration

MethodAdvantagesDisadvantages
‘nmcli’Easy to use, supports modern network management featuresNot available on all Linux distributions
‘ifconfig’Available on most Unix-like operating systems, supports basic network management featuresDoes not support some modern network management features
Manual ConfigurationGives full control over network configurationRequires a good understanding of networking and the Linux file system

In conclusion, while ‘nmcli’ is a powerful and easy-to-use tool for managing network connections in Linux, there are other methods available. The ‘ifconfig’ command and manual network configuration are good alternatives, each with their own advantages and disadvantages. Depending on your needs and level of expertise, you may prefer one method over the others.

Troubleshooting Common ‘nmcli’ Issues

As with any command-line tool, you may encounter issues when using ‘nmcli’. Here are some common problems and their solutions.

‘nmcli’ Command Not Found

If you see a ‘command not found’ error when trying to run ‘nmcli’, it’s likely that ‘nmcli’ is not installed or not in your PATH.

nmcli

# Output:
# Command 'nmcli' not found, but can be installed with:
# sudo apt install network-manager

To resolve this, install ‘nmcli’ using your package manager, as discussed earlier in this guide. If ‘nmcli’ is installed but not in your PATH, you may need to add it. This can vary depending on your Linux distribution and how ‘nmcli’ was installed.

No Network Connections Displayed

If ‘nmcli con show’ does not display any network connections, your network interfaces may be down or not configured.

nmcli con show

# Output:
# NAME UUID TYPE DEVICE

To resolve this, you can manually bring up your network interfaces with ‘ifconfig’ or ‘ip’, or configure them to come up at boot.

# Bring up the 'eth0' network interface
sudo ifconfig eth0 up

# Output:
# [sudo] password for user: 

‘nmcli’ Version Mismatch

If you’re having compatibility issues or missing features, you may have an outdated version of ‘nmcli’.

nmcli --version

# Output:
# nmcli tool, version 1.18.8

To resolve this, you can update ‘nmcli’ using your package manager, or install a specific version as discussed earlier in this guide.

These are just a few of the common issues you may encounter when using ‘nmcli’. Always remember to check the man page (man nmcli) or use the ‘–help’ option (nmcli --help) for more information and troubleshooting tips.

Linux Network Management: The Basics

Before delving deeper into the ‘nmcli’ command, it’s crucial to understand the fundamentals of network management in Linux. Network management is a critical aspect of system administration that ensures seamless communication and data transfer between devices connected to a network.

Importance of Network Management in Linux

In a Linux environment, network management involves configuring network interfaces, setting up routing tables, and managing internet protocol (IP) addresses. It ensures that all devices in a network can communicate effectively, making it vital for the smooth operation of any Linux system.

# Displaying network interfaces
ip link show

# Output:
# 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
#     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
# 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
#     link/ether 08:00:27:56:8d:37 brd ff:ff:ff:ff:ff:ff

This command shows the network interfaces available on your Linux system. The ‘lo’ interface is the loopback interface, which is a special network interface that the system uses to communicate with itself. The ‘eth0’ interface is a physical network interface connected to the network.

Understanding the ‘nmcli’ Command

The ‘nmcli’ command is a command-line tool for managing network interfaces in Linux. It is part of the NetworkManager utility, which aims to simplify network configuration and operation in Linux. With ‘nmcli’, you can create, edit, start, and stop network connections, as well as display network device status.

# Checking the status of network interfaces with 'nmcli'
nmcli dev status

# Output:
# DEVICE  TYPE      STATE        CONNECTION 
# eth0    ethernet  connected    Wired connection 1 
# lo      loopback  unmanaged    -- 

This command displays the status of all network interfaces on your system. The ‘eth0’ interface is connected, and the ‘lo’ interface is unmanaged, which means it’s not controlled by NetworkManager.

In conclusion, understanding network management in Linux is fundamental to using the ‘nmcli’ command effectively. Whether you’re a system administrator managing a large network or a casual Linux user trying to set up a home network, ‘nmcli’ can make your network management tasks easier.

Broadening Your Network Management Horizons

While mastering the ‘nmcli’ command is a significant step towards effective network management in Linux, it’s just the tip of the iceberg. Network management plays a vital role in system administration and security, and there are numerous related concepts that you could explore to further enhance your skills.

The Role of Network Management in System Administration

In system administration, network management is crucial for maintaining the smooth operation of a network. It involves monitoring and controlling network components, performing routine maintenance tasks, and troubleshooting network problems. By mastering tools like ‘nmcli’, system administrators can efficiently manage networks and ensure their reliable performance.

The Importance of Network Security

Network security is a critical aspect of network management. It involves protecting a network from threats and attacks, securing network traffic, and managing access to network resources. By understanding network security principles, you can use ‘nmcli’ and other tools to configure secure network connections and protect your Linux system.

# Displaying active network connections with 'nmcli' to monitor network activity
nmcli con show --active

# Output:
# NAME                UUID                                  TYPE      DEVICE
# Wired connection 1  44a5b272-8e2a-4c70-8e27-fd3e4bf8f67c  ethernet  eth0

This command displays the active network connections on your system, which can help you monitor network activity and detect any suspicious connections.

Exploring Firewall Management in Linux

Firewall management is another crucial aspect of network management and security in Linux. A firewall is a network security system that controls incoming and outgoing network traffic based on predetermined security rules. By understanding how to manage a firewall in Linux, you can further enhance your network security.

# Listing firewall rules with 'iptables'
sudo iptables -L

# Output:
# Chain INPUT (policy ACCEPT)
# target     prot opt source               destination

# Chain FORWARD (policy ACCEPT)
# target     prot opt source               destination

# Chain OUTPUT (policy ACCEPT)
# target     prot opt source               destination

This command lists the firewall rules on your system, which can help you manage your firewall and control network traffic.

Further Resources for Network Management Mastery

To deepen your understanding of network management in Linux, consider exploring the following resources:

  1. The Linux Documentation Project’s Networking Guide: This guide provides a comprehensive overview of networking in Linux, including network configuration, troubleshooting, and security.

  2. The Debian Administrator’s Handbook’s Network Configuration Chapter: This chapter discusses network configuration in Debian, a popular Linux distribution, with detailed explanations and examples.

  3. Red Hat’s System Administrator’s Guide: This guide provides in-depth information about network scripts, which are crucial for network configuration in Red Hat Enterprise Linux and other similar distributions.

Wrapping Up: Installing the ‘nmcli’ Command for Linux Network Management

In this comprehensive guide, we’ve navigated the world of network management in Linux using the ‘nmcli’ command. We’ve explored its installation process, basic usage, and even delved into advanced features, providing you with the tools to manage your network connections effectively.

We began with the basics, discussing how to install the ‘nmcli’ command on various Linux distributions. We then moved onto its usage, demonstrating how to manage network connections with ‘nmcli’, from displaying network interfaces to activating and deactivating connections.

We ventured further into more complex territories, exploring how to install ‘nmcli’ from source and handle different versions. We also discussed alternative approaches to network management, such as using the ‘ifconfig’ command or manual network configuration, providing you with a broader view of Linux network management.

Along the way, we tackled common challenges you might encounter when using ‘nmcli’, such as command not found errors, no network connections displayed, and version mismatch issues. We provided solutions and workarounds for these problems, equipping you with the knowledge to overcome these hurdles.

MethodProsCons
‘nmcli’Easy to use, supports modern network management featuresMay require troubleshooting for some programs
‘ifconfig’Available on most Unix-like operating systems, supports basic network management featuresDoes not support some modern network management features
Manual ConfigurationGives full control over network configurationRequires a good understanding of networking and the Linux file system

Whether you’re just starting out with ‘nmcli’ or you’re looking to level up your network management skills, we hope this guide has given you a deeper understanding of ‘nmcli’ and its capabilities.

With its balance of ease of use and support for modern network management features, ‘nmcli’ is a powerful tool for managing network connections in Linux. Now, you’re well equipped to navigate your network with ease. Happy networking!