nmcli Command in Linux

Introduction to nmcli for Linux Network Management

This guide explores the nmcli command-line utility, a vital tool for systemadmin professionals managing network connections in Linux environments. As an integral component of the NetworkManager service, nmcli offers extensive capabilities. These include configuring network interfaces, establishing and terminating network connections, and resolving network-related problems. This tutorial begins with an introduction to the nmcli command and version verification. Then, we'll proceed to network interface configuration using nmcli commands. Finally, you'll learn how to leverage nmcli for effective network troubleshooting.

Understanding the nmcli Command

This section introduces the nmcli command, a robust command-line tool for network connection management within Linux systems. nmcli, short for "NetworkManager Command Line Interface," is part of the NetworkManager service. This service is responsible for handling network connections in modern Linux distributions.

First, let's determine the nmcli version installed on your system:

nmcli --version

Example output:

nmcli tool, version 1.36.0

The nmcli command provides a broad spectrum of features designed for managing network interfaces, connections, and related configurations. Key capabilities of nmcli include:

  • Network connection viewing and management
  • Network interface configuration
  • Network connection and disconnection
  • Network status monitoring and troubleshooting
  • Interaction with the NetworkManager service

The following sections detail the utilization of nmcli for diverse network management operations.

nmcli Configuration of Network Interfaces

This section demonstrates how to utilize the nmcli command to configure network interfaces on a Linux system.

To begin, list all available network interfaces:

nmcli device status

Example output:

DEVICE  TYPE      STATE      CONNECTION
eth0    ethernet  connected  eth0
lo      loopback  unmanaged  --

The example shows an Ethernet interface (eth0) in a connected state and a loopback interface (lo) which is unmanaged.

The following command creates a new Ethernet connection using nmcli:

sudo nmcli connection add type ethernet con-name my-ethernet ifname eth0 ip4 192.168.1.100/24 gw4 192.168.1.1

This command generates a new Ethernet connection named my-ethernet, associated with the eth0 interface. The IPv4 address is set to 192.168.1.100/24 and the gateway to 192.168.1.1.

Activate the connection with the following command:

sudo nmcli connection up my-ethernet

The connection status should update to "connected".

Verification can be achieved with these commands:

nmcli device status
nmcli connection show my-ethernet

The output confirms that the eth0 interface is "connected" and displays the details of the my-ethernet connection.

Network Troubleshooting with nmcli

This section describes how to use nmcli to diagnose and resolve network issues within a Linux environment.

Begin by simulating a network problem by disconnecting the my-ethernet connection previously created:

sudo nmcli connection down my-ethernet

Next, check the network status:

nmcli device status

The eth0 interface should now report a "disconnected" state.

For detailed information, use nmcli to inspect the connection configuration:

nmcli connection show my-ethernet

This command displays the configuration settings for my-ethernet, revealing potential errors that prevent connection establishment.

For real-time log messages related to the network connection, monitor the NetworkManager service using nmcli:

sudo nmcli monitor

This starts monitoring the NetworkManager service and displays log messages. Press Ctrl+C to stop the monitoring process.

To restore the my-ethernet connection, use the following command:

sudo nmcli connection up my-ethernet

This command should return the eth0 interface to the "connected" state.

Conclusion

This tutorial introduced the nmcli command, a command-line interface essential for managing network connections in Linux. We demonstrated how to verify the nmcli version and examined its features. Including network connection management, interface configuration, connecting/disconnecting from networks, and troubleshooting. This guide provides Linux systemadmin with a strong foundation for network management.

This tutorial covered the configuration of network interfaces using nmcli. Users now understand how to list interfaces, create Ethernet connections, and activate those connections. These capabilities are necessary for the effective management of Linux network configurations, particularly within a professional systemadmin context involving root access and Linux server management.

400+ Linux Commands