How to Set a Static IP Address in Rocky Linux

0

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

Image: alexskopje/Adobe Stock

Rocky Linux 9 is a brilliant server operating system that comes from the man who created CentOS. This operating system offers many features that meet the business needs well. Since most admins are already familiar with Red Hat Enterprise Linux and CentOS, they shouldn’t have a problem getting familiar with Rocky Linux either.

SEE: 40+ open source and Linux terms you need to know (TechRepublic Premium)

However, there is one problem that you will need to fix 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 this step tends to elude administrators who want the operating system up and running quickly. Even I found myself guilty for forgetting to set the IP address to manual in the name of speed.

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

What You’ll Need to Set a Static IP Address in Rocky Linux

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

I’m going to assume you haven’t installed Rocky Linux with a GUI, as setting up a static IP address through the Network Manager UI is very easy (Wired Settings | IPv4 | Manual). Instead, we’ll do it from the command line.

Fun times! Let’s get to work.

How to set a static IP address

Login to your Rocky Linux instance and you should end up at the terminal. You shouldn’t do this via SSH, as you’ll find yourself unable to reach the server at some point. For this reason, make sure you are physically at the Rocky Linux server terminal.

The first thing you will do is locate the name of the network interface to use, which is done via the command:

ip a

You’ll be looking for a name like enp0s3, which will already have an IP address assigned via DHCP.

For example, mine looks like this:

2: enp0s3: 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, we’ll use an ncurses tool, named 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, select the name of the interface you want to modify using the arrow keys, tab in the right pane, select Modify and press Enter on your keyboard.

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

Figure B

nmtui’s Edit Connection window.

A pop-up window will appear where you need to select Manual with the arrow keys and then press Enter on your keyboard. Tab up and press Enter to reveal with the static IP address configuration (Figure C).

Figure C

The nmtui IPv4 static IP address configuration window.

Tab to each section and configure the address, gateway, and DNS servers at a minimum. Note that with the DNS server setup you need to add one per line – no comma separated values.

Once you have these bits set, tab to OK and hit enter on your keyboard. You must then leave the editing window and access Activate a connection. Disable the interface and then re-enable it by tapping Disable (Figure D) and pressing Enter on your keyboard.

Figure D

Disable and re-enable an interface for changes to apply.

Once you activate the interface, the new static IP address takes effect and you are ready to work.

And that’s all there is to setting a static IP on Rocky Linux. If you are careful during the installation process, you can take care of this task before the operating system is deployed. But, if you’re like me and regularly overlook this step, you now have the knowledge to correct that oversight.

Subscribe to TechRepublic How to make technology work on YouTube for all the latest tech tips for professionals from Jack Wallen.

Share.

Comments are closed.