Install and use NetworkManager (NMCLI) on Ubuntu / Debian

For system administrators, their daily work revolves around the configuration (configuration), maintenance, troubleshooting, monitoring, protection, and management of servers in the data center. This guide answers questions about how to manage Ubuntu/Debian network interfaces using some default tools. Network administrator It is a tool designed to manage the network on the machine. It has many tools that can be used to manage the network configuration on all Linux distributions. This tool is the default network management tool on Ubuntu systems. It provides the following network management tools:

  1. Nmtui– This tool runs on a Linux terminal window. It is a text-based network manager tool that can be changed on the network by entering data and menu selections. It is used to perform basic network management tasks, and it has many missing features available in NMCLI.
  2. Gnome settings– From the Gnome desktop, you can use the Gnome web application to manage the network. It provides basic network management and is easy to perform configuration.
  3. Nano Connect Editor-This is a graph-based network manager tool that allows access to NetworkManager configuration options
  4. NMCLI– normally called as Network command line interface Is a network tool used to manage NetworkManager and display the status of network connections.It is useful when you cannot access a graphical environment or run a server version and make network configuration changes

The network manager is preferred due to the following features:

  • Flexible network visualization
  • Comprehensive network management
  • Built-in root cause analysis function
  • Fully customizable content
  • Built-in device and interface polling function
  • Click Network Troubleshooting
  • Extensive reporting functions
  • Multiple integration options
  • Growing network discovery

At the end of this guide, you should be able to install and use NetworkManager NMCLI On Ubuntu / Debian system.

prerequisites

For this guide, please make sure that your Ubuntu|Debian system is updated and upgraded as follows.

sudo apt-get update && sudo apt-get upgrade

Step 1-Install NetworkManager on Ubuntu|Debian system

By default, NetworkManager exists on the Ubuntu|Debian system, but if you need to install it, I will demonstrate two methods to install NetworkManager on your Ubuntu|Debian system.

  1. Use APT
  2. Use snap

1a) Use APT to install NetworkManager on Ubuntu|Debian system

NetworkManager is available in the APT repository of the default ubuntu|Debian system and can be installed as follows.

sudo apt-get install network-manager

Start and enable the network manager as shown below.

sudo systemctl start NetworkManager.service 
sudo systemctl enable NetworkManager.service

1b) Use Snap to install NetworkManager on Ubuntu|Debian system.

NetworkManager can also be found in the Snap store and can be installed on Ubuntu|Debian systems Break off Installation and activation are as follows.

sudo apt install snapd
sudo systemctl enable --now snapd.socket
sudo ln -s /var/lib/snapd/snap /snap

Then install NetworkManager using the following command:

snap install network-manager

After the installation is complete, all required plugs and sockets will be automatically connected, as verified below.

snap connections network-manager

Sample output:

Interface              Plug                                   Slot                     Notes
dbus                   network-manager:wpa                    -                        -
firewall-control       network-manager:firewall-control       :firewall-control        -
hardware-observe       network-manager:hardware-observe       :hardware-observe        -
login-session-observe  network-manager:login-session-observe  :login-session-observe   -
modem-manager          network-manager:modem-manager          :modem-manager           -
network                network-manager:network                :network                 -
network-manager        -                                      network-manager:service  -
network-manager        network-manager:nmcli                  -                        -
network-observe        network-manager:network-observe        :network-observe         -
network-setup-control  network-manager:network-setup-control  :network-setup-control   -
network-setup-observe  network-manager:network-setup-observe  :network-setup-observe   -
ppp                    network-manager:ppp                    :ppp                     -

After the installation is complete, the network manager will automatically start and run in the background, use the command to check its status:

$ sudo systemctl status NetworkManager.service
● NetworkManager.service - Network Manager
     Loaded: loaded (/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-09-28 14:50:00 EAT; 1min ago
       Docs: man:NetworkManager(8)
   Main PID: 423 (NetworkManager)
      Tasks: 3 (limit: 2404)
     Memory: 13.6M
        CPU: 303ms
     CGroup: /system.slice/NetworkManager.service
             └─423 /usr/sbin/NetworkManager --no-daemon

Sep 28 14:50:16 debian NetworkManager[423]: <info>  [1632829816.7357] manager: NetworkManager state is now CONNECTED_LOCAL
Sep 28 14:50:16 debian NetworkManager[423]: <info>  [1632829816.7434] manager: NetworkManager state is now CONNECTED_SITE
Sep 28 14:50:16 debian NetworkManager[423]: <info>  [1632829816.7468] policy: set 'Wired connection 1' (enp0s3) as default for IPv4 routing and DNS

Step 2-Use NetworkManager NMCLI on Ubuntu|Debian system.

NMCLI is a network utility tool that allows us to manage the network configuration. There are several commands that can be used to manage the network.

Modify network connection

Using NMCLI to modify the network connection requires us to start by listing the network connection, using the command:

nmcli connection show

Sample output:

AME                UUID                                  TYPE      DEVICE 
Wired connection 1  ac98eab7-1ad3-4cf0-93a0-210bfe3bb7e2  ethernet  enp0s3 

Show active connections

The above command shows all connections, but if you want to see active or upward connections, you will add --active Mark the above command;

nmcli connection show --active

Sample output:

NAME                UUID                                  TYPE      DEVICE 
Wired connection 1  ac98eab7-1ad3-4cf0-93a0-210bfe3bb7e2  ethernet  enp0s3

Using the connection profile name, you can view the following additional information.

nmcli connection show "Wired connection 1"

Sample output:

Use NMCLI to add and modify network connections

Use NMCLI to add a network connection

Using NMCLI, you can use the following syntax to add a new connection to the Ubuntu|Debian system.

sudo nmcli connection add type <network-type> ifname <connection-name>

Use NMCLI to modify an existing network connection

Using NMCLI, the following syntax can be used to adjust and configure existing network connections, such as switching between static and DHCP configuration.

sudo nmcli connection modify <connection-id> <parameter> <value>

Now let’s see what configuration we can do Add to with Adjustment Connect using NMCLI. We will first add a NetworkManager connection profile for our connection.For me, it is an Ethernet connection, I will add a connection profile named My new connection

nmcli connection add con-name My-New-Connection ifname enp0s3 type ethernet

Sample output:

Connection 'My-New-Connection' (a6b26540-4c06-4a80-a0fa-a2868e4006e5) successfully added.

After adding the connection profile, we will make the following adjustments. Please remember to use a syntax similar to the one I gave to set your own IP address, gateway, DNS server, etc.

To set up automatic startup of the network connection, use:

nmcli connection modify My-New-Connection connection.autoconnect yes

1. Set a static IPv4 address, the subnet mask is /24

for example, We modify the existing connection to a static IP_Address and change the subnet /twenty four Without this specification, it will assign an IP with a default mask, which may cause problems in the future.

sudo nmcli connection modify My-New-Connection ipv4.address 192.168.100.157/24

2. Use /64 subnet mask to set a static IPv6 address

nmcli connection modify My-New-Connection ipv6.addresses 2001:db8:1::1/64

3. Set IPv4/IPv6 default gateway

##For IPv4
nmcli connection modify My-New-Connection ipv4.gateway 192.168.100.1
##For IPv6
nmcli connection modify My-New-Connection ipv6.gateway 2001:db8:1::fffe

4. Set up IPv4/IPv6 DNS server

##For IPv4
nmcli connection modify My-New-Connection ipv4.dns "192.168.100.200"
##For IPv6
nmcli connection modify My-New-Connection ipv6.dns "2001:db8:1::ffbb"

5. Set the IPv4 and IPv6 connection mode to automatic

##For IPv4
nmcli connection modify My-New-Connection ipv4.method auto
##For IPv6
nmcli connection modify My-New-Connection ipv6.method auto

For the changes to take effect, you need to activate the configuration file.

$ nmcli connection up My-New-Connection
connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)

Now check the active connection.

nmcli connection show --active

Install and use NetworkManager NMCLI on Ubuntu Debian System 2

Verify the set IP_Address.

hostname -I
192.168.100.120 192.168.100.157 

From the output, I have two IP addresses, one primary IP and one Minor intellectual property Added by the new connection profile My-New-Connection.you can use it ip a The command is as follows.Install and use NetworkManager NMCLI on UbuntuDebian system 1

Use NMCLI to manage devices

The NMCLI utility can also be used to manage devices, such as:

Display device status

sudo nmcli -p dev status

Sample output:Install and use NetworkManager NMCLI on Ubuntu Debian system 1 1

Modify device configuration

Before modifying the device configuration, you first need to obtain the device information.

sudo nmcli device show

Sample output:Install and use NetworkManager NMCLI on Ubuntu Debian system 4

With the device information, you can use the following syntax to modify the device settings.

$ sudo nmcli device modify <interface-name> <parameter> <value>
###OR
$ sudo nmcli dev mod <interface-name> <parameter> <value>

Please keep in mind that the above changes are temporary and can be reset to the default settings with the following command:

sudo nmcli dev reapply interface-name

If you encounter problems when using NMCLI Device Manager, please use the following command to find help:

sudo nmcli device help

Install and use NetworkManager NMCLI on Ubuntu Debian system 5

in conclusion.

now it’s right! We have learned how to install and use NetworkManager NMCLI on Ubuntu / Debian systems. I hope this guide is important to you. I assume you can now use NetworkManager NMCLI to manage your network connections and network devices.

see more:

  • How to create an internal network in Xen | XCP-ng
  • Add secondary IP address to CentOS / RHEL network interface
  • Configure BIND slave DNS server on Debian