Table of Contents
NetworkManager Command Line Interface nmcli
Abbreviated as nmcli, the network manager command-line interface is a nifty and easy to use tool that saves you lots of time when you need to configure an IP address.
It’s strongly recommended to set static IP address on your Linux system specially on servers. The main benefit of static IP address is that it will be persistent across the reboots.
To display all the active network interfaces on your Linux system execute the command.
sudo nmcli connection show
sudo nmcli con show
# sudo nmcli con show
NAME UUID TYPE DEVICE
ens160 143be423-aa84-393f-87e2-9a1866acf705 ethernet ens160
Also, you can run the command below to display both active and inactive interfaces.
sudo nmcli dev status
# nmcli dev status
DEVICE TYPE STATE CONNECTION
ens160 ethernet connected ens160
lo loopback unmanaged --
Set Static IP Address Using nmcli Tool
Using nmcli tool, you can modify a network interface to use a static IP address. In this example, we will modify the network interface ens160 to use a static IP.
# sudo nmcli con show
NAME UUID TYPE DEVICE
ens160 143be423-aa84-393f-87e2-9a1866acf705 ethernet ens160
The current IP address is 192.168.1.104 with a CIDR of /24. We are going to configure a static IP with the following values:
# ip -br -4 a
lo UNKNOWN 127.0.0.1/8
ens160 UP 10.10.5.91/16
IP address: 192.168.1.10/24
Default gateway: 192.168.1.1
Preferred DNS: 8.8.8.8, 1.1.1.1
IP addressing: static
1. First, run the following commands below to set up the IP address, default gateway and DNS servers for the network interface named ens160.
sudo nmcli con modify 'ens160' ipv4.addresses 192.168.1.10/24
sudo nmcli con modify 'ens160' ipv4.gateway 192.168.1.1
sudo nmcli con modify 'ens160' ipv4.dns "1.1.1.1,8.8.8.8"
2. Next, change the addressing from DHCP to static.
sudo nmcli con modify 'ens160' ipv4.method manual
3. To save the changes and apply the configurations, run the following command:
sudo nmcli con up 'ens160'
4. To confirm the IP address was changed, once again run the command:
# ip -br -4 a
lo UNKNOWN 127.0.0.1/8
ens160 UP 10.10.5.92/16
And this concludes this guide on configuring network connection using nmcli command-line tool on Linux. We hope you found this guide helpful.