Monday, October 3, 2022

How To Configure Networking on Rocky Linux

This tutorial intends to teach you How To Configure Networking on Rocky Linux by using the nmcli command.

The nmcli (NetworkManager Command Line Interface) command-line utility is used for controlling NetworkManager and reporting network status.

nmcli is used to create, display, edit, delete, activate, and deactivate network connections, as well as control and display network device status.

The nmcli utility can be used by both users and scripts for controlling NetworkManager:

  • For servers, headless machines, and terminals, nmcli can be used to control NetworkManager directly, without GUI, including creating, editing, starting, and stopping network connections, and viewing network status.
  • For scripts, nmcli supports a terse output format which is better suited for script processing. It is a way to integrate network configuration instead of managing network connections manually.

Configure Networking on Rocky Linux with nmcli command

If you plan to control your network connections and restart your network on Rocky Linux, follow the steps below to see how it works.

Check Network Status on Rocky Linux

The NetworkManager daemon attempts to make networking configuration and operation as painless and automatic as possible by managing the primary network connection and other network interfaces, like Ethernet, WiFi, and Mobile Broadband devices.

You can use the nmcli command to check whether the Network Manager is running or not on your server. To do this, you can run the following command:

nmcli -t -f RUNNING general

In your output you will see:

Output
running

Also, you can get a general status by running the command below:

nmcli general
Output
STATE      CONNECTIVITY  WIFI-HW  WIFI     WWAN-HW  WWAN    
connected  full          enabled  enabled  enabled  enabled 

Display Available Devices on Rocky Linux

At this point, you can use the nmcli command to display your all available devices on Rocky Linux:

nmcli dev status

In my case, I get the following output:

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

Display Active Connections on Rocky Linux

One of the uses of the nmcli command is to list your active connections. To do this, run the following command:

nmcli con show

In my case, I get the following output:

Output
NAME             UUID                                                        TYPE          DEVICE
System eth0   5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03     ethernet       eth0
ens3              0e50b731-0de2-4c9f-906c-6c2f3d8129d1    ethernet         --

Also, you can display the brief information about the ethernet connection by running the command below:

nmcli con show "System eth0"

In your output, you will see something similar to this:

Output
connection.id: System eth0
connection.uuid: 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
connection.stable-id: --
connection.type: 802-3-ethernet
connection.interface-name: eth0
connection.autoconnect: yes
connection.autoconnect-priority: 0
connection.autoconnect-retries: -1 (default)
connection.multi-connect: 0 (default)
connection.auth-retries: -1
....

Change Hostname on Rocky Linux

You can easily use the nmcli command to find your current hostname and change it.

nmcli general hostname
Output
RockyLinux

To change the hostname from RockyLinux to Linux for example, run the command below:

nmcli general hostname linux

Restart Ethernet Connection on Rocky Linux

You can restart or reload your ethernet connection with the following command:

nmcli con reload

Restart Network on Rocky Linux

To turn networking completely off and back on in Rocky Linux, we can use the following nmcli command, which effectively restarts the network for the operating system.

# nmcli networking off
# nmcli networking on

Reset a Network Interface on Rocky Linux

To activate an ethernet connection, run the following command:

nmcli con up ens3

You should see the following output:

Output
Connection successfully activated

You can now verify the active connection with the following command:

nmcli con show --active

To deactivate the connection, run the following command:

nmcli con down ens3

Also, there is another way to reset a network interface in Rocky Linux is with the ip link commands, which work through networkd.

#ip link set ens3 down
#ip link set ens3 up

Delete an Ethernet Connection on Rocky Linux

You can also delete a specific ethernet connection with nmcli.

For example, to delete a connection ens3, run the following command:

nmcli con del ens3

You should see the following output:

Output
Connection 'ens3' (cefb3f7d-424c-42f8-b4e8-ed54e7dcb880) successfully deleted.

To get more information about the nmcli command, you can run the following command:

nmcli --help
Output
Usage: nmcli [OPTIONS] OBJECT { COMMAND | help }

OPTIONS
  -a, --ask                                ask for missing parameters
  -c, --colors auto|yes|no                 whether to use colors in output
  -e, --escape yes|no                      escape columns separators in values
  -f, --fields <field,...>|all|common      specify fields to output
  -g, --get-values <field,...>|all|common  shortcut for -m tabular -t -f
  -h, --help                               print this help
  -m, --mode tabular|multiline             output mode
  -o, --overview                           overview mode
  -p, --pretty                             pretty output
  -s, --show-secrets                       allow displaying passwords
  -t, --terse                              terse output
  -v, --version                            show program version
  -w, --wait                      set timeout waiting for finishing operations

OBJECT
  g[eneral]       NetworkManager's general status and operations
  n[etworking]    overall networking control
  r[adio]         NetworkManager radio switches
  c[onnection]    NetworkManager's connections
  d[evice]        devices managed by NetworkManager
  a[gent]         NetworkManager secret agent or polkit agent
  m[onitor]       monitor NetworkManager changes

Conclusion

At this point, you learn how to use the nmcli command to control your networking on Rocky Linux.

Hope you enjoy it.

You may be interested in these articles:

Install and Use PostgreSQL on Rocky Linux 8

Install and Configure Django on Rocky Linux 8

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles