Skip to content

How to setup static IP on Rocky Linux 8

To set up static IP configuration on VPS that runs on Rocky Linux 8, we have to login into Fleio.
After connecting to Fleio we can use the console to run commands.

Before starting the configuration, if you just deployed a new VPS, you need to restart NetworkManager with the following command:

systemctl restart NetworkManager

After we have logged into the console, verify that we are a superuser (sudo) and then we proceed with these steps:

  1. First, we need to disable configuration rewriting for the network interface. To do this, we need to create the file /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg and add the following line of code:

    network: {config: disabled}
    

  2. The second step is to identify the IPs we want to configure and their subnets. To do this, we run ip a command. After running the command we can see the two IPs (IPV4 and IPV6) along with their subnet. For example:

    inet 185.125.109.116/24 brd 185.125.109.255 scope global noprefixroute eth0
           valid_lft forever preferred_lft forever
        inet6 2a06:cd40:400:1::1c/64 scope global noprefixroute
           valid_lft forever preferred_lft forever
    

  3. The third step is to find the gateway for both IPV4 and IPV6. To do this, we run the command ip r for IPV4 and ip -6 r for IPV6. For example:

    default via 185.125.109.1 dev eth0 proto static metric 100
    185.125.109.0/24 dev eth0 proto kernel scope link src 185.125.109.116 metric 100
    
    default via 2a06:cd40:400:1::1 dev eth0 proto static metric 100 pref medium
    

    Note As we can see, IPV6 is already configured as static. Therefore, we don't need to make any changes to it.

  4. The next step is to modify the network configuration using the command-line tool, nmcli. In order to do this we will run the following commands:

    Note You can view the documentation for more details: https://networkmanager.dev/docs/api/latest/nmcli.html

    nmcli connection show
    
    Note We run this command to list all network connections.
    NAME         UUID                                  TYPE      DEVICE
    System eth0  5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  ethernet  eth0
    ens3         db4d70df-2288-4da6-b38a-58756a5edff8  ethernet  --
    ens3         4d4838ac-a400-40af-9c00-dfad25c38d29  ethernet  --
    
    Note The connection we want to modify is System eth0
    nmcli connection edit "System eth0"
    
    Note We run this command to access the editing interface for the desired connection.
    nmcli> set ipv4.addresses
    Enter 'addresses' value: 185.125.109.116/24, 185.125.109.28/24
    
    Note If configuring multiple IPs for the same interface, ensure that each IP is correctly formatted with its CIDR netmask (e.g., 185.125.109.116/24, 185.125.109.28/24). Note In this example, 185.125.109.28 is the second IP address that we configure.
    nmcli> set ipv4.gateway
    Enter 'gateway' value: 185.125.109.1
    
    Note We run this command to set the gateway.
    nmcli> set ipv4.dns
    Enter 'dns' value: 8.8.8.8, 1.1.1.1
    
    Note We run this command to set DNS server.
    nmcli> save
    Connection 'System eth0' (5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03) successfully updated.
    nmcli> quit
    
    Note We run these commands to save the changes and exit the editing interface.
    nmcli connection show "System eth0"
    
    Note We run this command to check if the changes we have made are correct.

  5. After we've checked and everything is in order, we need to restart the Network Service. To do this we run this command:

    systemctl restart NetworkManager
    

After you have completed all these steps and the IP is responding to ping, you have successfully configured the static IP.

ping 185.125.109.116

Pinging 185.125.109.116 with 32 bytes of data:
Reply from 185.125.109.116: bytes=32 time=14ms TTL=56
Reply from 185.125.109.116: bytes=32 time=15ms TTL=56
ping 185.125.109.28

Pinging 185.125.109.28 with 32 bytes of data:
Reply from 185.125.109.28: bytes=32 time=15ms TTL=56
Reply from 185.125.109.28: bytes=32 time=14ms TTL=56