Setting Up a Static IP on Rocky Linux

Rocky Linux logo

This guide walks through setting up an Ethernet connection with a static IP on Rocky Linux, step by step. Adjust the IP address and device name to match your own setup as you go, since the interface name in particular varies from one machine to the next.

Step 1: Check NetworkManager is Running

Rocky Linux manages networking through NetworkManager, so first confirm it’s active:

systemctl status NetworkManager

Step 2: Edit the Interface Configuration

The interface config files live in /etc/sysconfig/network-scripts, so change into that directory and open the file for your interface (replace the name with your own):

cd /etc/sysconfig/network-scripts
sudo nano ifcfg-ens18

Set it up for a static IP. Here’s an example configuration, where the important changes from the default are BOOTPROTO=none (so it stops asking DHCP for an address) and the fixed IPADDR, GATEWAY, and DNS lines:

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
NAME=ens18
UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
DEVICE=ens18
ONBOOT=yes
IPADDR=192.168.1.44
PREFIX=24
GATEWAY=192.168.1.1
DNS1=192.168.1.1
DNS2=1.1.1.1
IPV6_DISABLED=yes

Step 3: Reload the Connection

Bring the connection back up so it picks up the new settings, using your own interface name:

nmcli connection up ens18

Step 4: Confirm the Settings Took

Check the interface to make sure it now has the static address you set:

nmcli device show ens18

You can also list all your connections and their state with:

nmcli connection show

Handy Extra Commands

A few more commands worth keeping around. To see all interfaces and their current addresses:

ip a

To assign an address to an interface on the fly, without editing the config file (note that this kind of change is temporary and won’t survive a reboot):

ip addr add 192.168.1.44/24 dev ens18

And to check the interface again afterwards:

ip a show ens18

Finally, if you want to check the public IP the server is going out on, rather than its local address, you can use:

curl http://checkip.amazonaws.com

Related guides


Comments

Leave a Reply

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