Using nmcli command to configure the network interface


nmcli is a command-line tool for controlling NetworkManager and getting its status. It can be utilized as a replacement for nm-applet or other graphical clients. nmcli is used to create, display, edit, delete, activate, and deactivate network connections, as well as control and display network device status.

Some of the things you can do with nmcli include:

  • List all network connections
  • Create a new network connection
  • Edit an existing network connection
  • Delete a network connection
  • Connect to a network
  • Disconnect from a network
  • Get the status of a network connection
  • Get the status of a network device

To learn more about nmcli, you can read the man page:

man nmcli

Here are some examples of how to use nmcli:

To list all network connections:

nmcli con list

To create a new network connection:

nmcli con add type <type> [name <name>] [ifname <ifname>] [...options...]

For example, to create a new wired connection called “My Wired Connection” on interface eth0:

nmcli con add type gsm name "My Wired Connection" ifname eth0

To edit an existing network connection:

nmcli con edit <connection>

For example, to change the name of the “My Wired Connection” connection to “My Home Network”:

nmcli con edit My Wired Connection name "My Home Network"

To delete a network connection:

nmcli con del <connection>

For example, to delete the “My Home Network” connection:

nmcli con del My Home Network

To connect to a network:

nmcli con up <connection>

For example, to connect to the “My Home Network” connection:

nmcli con up My Home Network

To disconnect from a network:

nmcli con down <connection>

For example, to disconnect from the “My Home Network” connection:

nmcli con down My Home Network

To get the status of a network connection:

nmcli con status <connection>

For example, to get the status of the “My Home Network” connection:

nmcli con status My Home Network

To get the status of a network device:

nmcli dev status <device>

For example, to get the status of the eth0 network device:

nmcli dev status eth0

Source: developer-old.gnome.org/NetworkManager/unstable/nmcli.html

How to Set a Static IP Address on Linux using nmcli

Setting a static IP address on a Linux system can be useful for many reasons, such as improving network stability and security. In this post, we will show you how to set a static IP address, gateway, and DNS server on a Linux system using the nmcli command.

Step 1: Identify the network connection name or UUID

Use the following command to list all available connections and their details:

sudo nmcli connection show

Note down the name or UUID of the connection that you want to modify.

Step 2: Modify the network connection settings

Use the following command to modify the connection settings:

sudo nmcli connection modify CONNECTION-NAME-OR-UUID ipv4.method manual ipv4.addresses IP-ADDRESS/SUBNET-MASK ipv4.gateway GATEWAY-ADDRESS ipv4.dns "DNS-SERVER-1 DNS-SERVER-2 ..."

Replace CONNECTION-NAME-OR-UUID with the name or UUID of the connection that you want to modify, IP-ADDRESS/SUBNET-MASK with the desired IP address and subnet mask, GATEWAY-ADDRESS with the desired gateway address, and DNS-SERVER-1 DNS-SERVER-2 … with the desired DNS server addresses. Note that the DNS server addresses should be enclosed in quotes and separated by spaces.

Step 3: Bring up the connection with the new settings

Use the following command to bring up the connection with the new settings:

sudo nmcli connection up CONNECTION-NAME-OR-UUID

Replace CONNECTION-NAME-OR-UUID with the name or UUID of the connection that you modified in step 2.

That’s it! These changes will be persistent across reboots, as they are saved to the appropriate configuration file in the /etc/NetworkManager/system-connections directory.

Leave a Comment

Your email address will not be published. Required fields are marked *