How to set a static IP in Rocky Linux

Jack Wallen shows you how easy it is to set a static IP in Rocky Linux 9 from the terminal.

IP address
Image: alexskopje/Adobe Stock

Rocky Linux 9 is a brilliant server operating system that comes from the man who developed CentOS. This operating system offers numerous functions that meet the needs of companies. Since most administrators are already familiar with Red Hat Enterprise Linux and CentOS, they shouldn’t have any trouble getting to grips with Rocky Linux.

SEE: 40+ Open Source and Linux Terms You Need to Know (TechRepublic Premium)

However, there is one issue that you need to deal with almost immediately: the IP address. By default, Rocky Linux uses DHCP for its IP address. Yes, you can configure a static IP address during installation, but this step often eludes administrators who want to get the operating system up and running quickly. Even I was guilty of forgetting to set the IP address to manual in the name of speed.

When that happens, what do you do? You do what all good admins do: put on your best geek hat and dive into configuration. Let me show you how it’s done.

What you need to set a static IP address in Rocky Linux

The only things you need for this is a running instance of Rocky Linux 9 and a user with sudo privileges.

I’m assuming you didn’t install Rocky Linux with a GUI, since configuring a static IP is very easy via the network manager UI (Wired Settings | IPv4 | Manual). Instead we will do this from the command line.

Read  A COVID Surge is Coming and Here's How to Stay Safe — Eat This Not That

Funny times! let’s go to work

How to set a static IP address

Login to your Rocky Linux instance and you should find yourself at the terminal. You must not do this via SSH because at some point you will not be able to reach the server. So make sure you are physically at the Rocky Linux server terminal.

First, find the name of the network interface to use, which is done with the following command:

ip a

You’re looking for a name like enp0s3 that 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. Issue the command:

sudo nmtui

In the resulting window (Figure A), select Edit Connection and press Enter on your keyboard.

Figure A

The first nmtui screen gives you access to editing and activating a connection.

In the next window, use the arrow keys to select the name of the interface you want to edit, tab to the right pane, select Edit and press Enter on your keyboard.

In the resulting window (Figure B), tab down to IPv4 CONFIGURATION and press Enter on your keyboard.

Figure B

The nmtui Edit Connection window.

A popup will appear where you need to use the arrow keys to select Manual and then press Enter on your keyboard. Tab to and press Enter to display the static IP address configuration (Figure C).

Read  Why So Few Young Kids Are Vaccinated against COVID--And How to Change That

Figure C

The nmtui static IPv4 IP address configuration window.

Navigate to each section and configure at least Address, Gateway and DNS Server. Note that DNS server configuration requires you to add one per line – no comma separated values.

Once you have configured these bits, tab down to OK and press Enter on your keyboard. You then need to exit the edit window and go to Activate A Connection. Disable the interface and then re-enable it by tabbing to Disable (Figure D) and press Enter on your keyboard.

Figure D

Disable and re-enable an interface for the changes to take effect.

Once you activate the interface, the new static IP address will take effect and you can start working.

And that’s all you have to do to set a static IP address on Rocky Linux. If you pay attention during the installation process, you can take care of this task before the operating system is deployed. But if, like me, you regularly overlook this step, now you have the knowledge to fix that oversight.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for the latest tech advice for business professionals from Jack Wallen.

Leave a Comment

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