Skip to content

How to setup static IP on Rocky Linux 9

To set up static IP configuration on VPS that runs on RockyLinux 9, 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 188.241.112.50/21 brd 188.241.119.255 scope global noprefixroute eth0   
           valid_lft forever preferred_lft forever
        inet6 2a06:cd40:100:2::2a2/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 188.241.112.1 dev eth0 proto dhcp src 188.241.112.50 metric 100 
    
    default via 2a06:cd40:100:2::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.
    System eth0  5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  ethernet  eth0
    lo           777208b1-4ade-4788-8584-9d549959b569  loopback  lo
    ens3         01b94420-c44e-43a6-8900-0de8fcaf975d  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.address
    Enter 'addresses' value: 188.241.112.50/21
    Do you also want to set 'ipv4.method' to 'manual'? [yes]: yes
    
    Note We run this command to set ipv4 and the netmask. If you want to configure multiple IPs, you can separate them by , (Ex: ipv4.addresses: 192.168.4.4/24, 192.168.1.44/24).
    nmcli> set ipv4.gateway
    Enter 'gateway' value: 188.241.112.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 188.241.112.50 (188.241.112.50) 56(84) bytes of data.
64 bytes from 188.241.112.50: icmp_seq=1 ttl=64 time=0.406 ms
64 bytes from 188.241.112.50: icmp_seq=2 ttl=64 time=0.206 ms
64 bytes from 188.241.112.50: icmp_seq=3 ttl=64 time=0.258 ms
64 bytes from 188.241.112.50: icmp_seq=4 ttl=64 time=0.202 ms