How to Set Static IP Address on Rocky Linux 9 / Alma Linux 9 / RHEL 9

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Hello, friends. In this post, you will learn how to quickly set a static IP address in Rocky Linux 9 / Alma Linux 9 / RHEL 9.

In private networks, it is common to use static IP addresses to identify a computer within the network. Moreover, it is easier to administer and therefore manage than dynamic addressing. Although it all depends on the equipment, system and needs you have.

This task is basic when it comes to servers and although doing it on a GUI system is easy, on servers you have to do a bit more work. For this post, we will use two important tools, such as nmcli and nmtui.

Setting Static IP Address using nmcli on Rocky Linux 9 / Alma Linux 9

nmcli is a command-line tool for controlling NetworkManager and reporting network status. It can be used as a replacement for nm-applet or other graphical clients.

Thanks to nmcli you can create, display, edit, delete, activate, and deactivate network connections, as well as control and display network device network status.

That is why many Linux professionals have nmcli as an essential tool.

Since it is already installed, we don’t have to do anything. First, we’ll use it to check what the active network interface is called

 nmcli device

You will get a screen output similar to this

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

Now with root privileges, use it to change at least the following parameters

  • IP address
  • DNS server
  • Gateway
  • netmask

To achieve this, just run this command

sudo nmcli con modify '[interface]' ifname [interface-name] ipv4.method manual ipv4.addresses [Ip-address] gw4 [gateway]

For example,

sudo nmcli with modify 'eth0' ifname eth0 ipv4.method manual ipv4.addresses 192.168.1.100/24 gw4 192.168.1.1.1

Now all that’s left to do is to do the same with the DNS.

sudo nmcli with modify '[interface]' ipv4.dns [DNS-ip]

For example:

sudo nmcli with modify 'eth0' ipv4.dns 5.4.3.2

To apply the changes, the interface must be restarted. To do this, simply disable and enable it.

sudo nmcli with down 'eth0'
sudo nmcli with up 'eth0'

This way, the static IP address is already set.

nmtui can also be used to set a static IP address.

Another option is to use the nmtui command. Nmtui is a terminal application that allows you to manage your Wi-Fi or wired connections on Linux distributions using NetworkManager.

You could say that nmtui and nmcli are equivalent, but each has its features to achieve its goal.

For example, nmtui is a bit more intuitive to use and provides an interface more suitable for novice users but also comfortable for professional users.

So to use it, you just have to run it with root privileges

sudo nmtui

There you will get a menu like this one

Using nmtui
Using nmtui

You should select the Edit to connection option using the mouse arrows.

When you do this, you will see a screen with a list of all possible connections.

Just click on the one you want to modify and click Edit.

Edit a connection using nmtui
Edit a connection using nmtui

Next, you have to change the setting from Automatic to Manual so that you can manually enter the required values for the static IP

Manual connection settings
Manual connection settings
Set Static IP Address on Rocky Linux 9 / Alma Linux 9 / RHEL 9
Set Static IP Address on Rocky Linux 9 / Alma Linux 9 / RHEL 9

When you are done, press OK.

To apply the changes, in the main menu choose the option Activate to Connection select the connection and deactivate and re-activate it.

Applying the changes
Applying the changes

Then exit the tool.

Conclusion

Setting up a connection with a static IP address is a snap, thanks to these tools that quickly get the job done.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Angelo
Angelo
I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook