Jack Wallen shows how easy it is to set a static IP address in Rocky Linux 9 from the terminal.
Rocky Linux 9 is a brilliant server operating system that comes from the man who created CentOS. This operating system offers many features that are well suited to the needs of enterprises. Since most administrators are already familiar with Red Hat Enterprise Linux and CentOS, getting started with Rocky Linux shouldn’t be a problem either.
TO SEE: 40+ Open Source and Linux Terms You Need to Know (Tech Republic Premium)
However, there is one problem that you should solve almost immediately: the IP address. Out of the box, Rocky Linux uses DHCP for its IP address by default. Yes, you can configure a static IP address during installation, but that step is usually bypassed for administrators who want to get the operating system up and running quickly. Even I have found myself guilty of forgetting to set the IP address to manual in the name of speed.
If that happens, what do you do? You do what all good administrators do: put on your best geek hat and dive into the configuration. Let me show you how.
What you need to set up a static IP address in Rocky Linux
All you need is a running copy of Rocky Linux 9 and a user with sudo privileges.
I’m assuming you didn’t install Rocky Linux with a GUI, as configuring a static IP address through the network administrator user interface is very easy (Wired Settings | IPv4 | Manual). Instead, we’re going to do this from the command line.
Good times! Let’s get started.
Set a static IP address
Log into your Rocky Linux instance and you should be at the terminal. You should not do this via SSH, as at some point you will no longer be able to reach the server. Therefore, make sure you are physically at the Rocky Linux server terminal.
The first thing you will do is find the name of the network interface to use, which you do via the command:
ip a
You are looking for a name such as enp0s3, which already has an IP address assigned via DHCP.
For example, mine looks like this:
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:e1:01:43 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.190/24 brd 192.168.1.255 scope global dynamic noprefixroute enp0s3
Now that you know the name of the interface, let’s use an ncurses tool called nmtui to set the address. Give the command:
sudo nmtui
In the resulting window (Image A), select Edit a connection and press Enter on your keyboard.
Image A

In the next window, select the name of the interface you want to edit with your arrow keys, tab to the right pane, select Edit and press Enter on your keyboard.
In the resulting window (Figure B), tab down to IPv4 CONFIGURATION
Figure B

A pop-up will appear where you need to select Manual with your arrow keys and then press Enter on your keyboard. Tab to
Figure C

Go to each section and configure at least address, gateway and DNS servers. Note that the DNS server configuration requires you to add one per line – no comma separated values.
Once you have those bits configured, go to OK and press Enter on your keyboard. You must then exit the Edit window and go to Activate a connection. Deactivate the interface and then reactivate it by tapping Deactivate (Figure D) and press Enter on your keyboard.
Figure D

Once you’ve activated the interface, the new static IP will take effect and you’re good to go.
And that’s all there is to setting a static IP address on Rocky Linux. If you pay close attention during the installation process, you can complete this task before the operating system is deployed. But if you’re like me and you frequently overlook that step, you now have the knowledge to fix that oversight.
Subscribe to TechRepublic’s How to make technology work on YouTube for all the latest technical advice for business professionals from Jack Wallen.