Skip to content

How to setup static IP on Almalinux 9

To set up static IP configuration on your VPS, you have to login into Fleio. After connecting to Fleio you can use the console to run commands

  1. Login into SSH or console.

  2. Make sure you are sudo.

  3. 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}
    

  4. If you just deployed a new VPS, before starting the configuration, you need to restart NetworkManager with the following command:

    systemctl restart NetworkManager
    

  5. You have to identify the network interface:

    nmcli d
    

  6. and the current assigned DHCP IP:

    ip a
    

  7. Assign the IP as static:

    Info To find out the subnet mask for the IPs, you can use the command ip r | grep [your ip].

    nmcli con mod [network interface] ipv4.addresses [your ip]/[subnet mask]
    

  8. Assign the gateway:

    Info To find out the gateway you can use the command ip r | grep default.

    nmcli con mod [network interface] ipv4.gateway [gateway ip]
    

  9. Assign the DNS server

    nmcli con mod [network interface] ipv4.dns '8.8.8.8, 1.1.1.1'
    

  10. To apply the settings, we have to restart the internet connection:

    nmcli con down [network interface]
    nmcli con up [network interface]
    

  11. You can check the configuration using:

    ip a
    

Note: If the AUTOCONNECT_PRIORITY value in your configuration is lower than the ifcfg-[network interface] configuration, after restarting the server, the settings will be deleted.

Be sure that AUTOCONNECT_PRIORITY from /etc/sysconfig/network-scripts/ifcfg-[network interface] looks like:

AUTOCONNECT_PRIORITY=-1
In nmcli configuration the value of AUTOCONNECT_PRIORITY by default is 0.

Configuration for more IPs in your instance.

If you configure multiple IPs in your instance all you have to do is execute the following command with the secondary IP.

  1. Assign the second IP:

    nmcli con mod [network interface] +ipv4.addresses [your second ip]/[netmask]
    

  2. Assign the second gateway:

    nmcli con mod [network interface] +ipv4.gateway [gateway second ip]
    

  3. To apply the settings, we have to restart the internet connection:

    nmcli con down [network interface]
    nmcli con up [network interface]
    

  4. You can check the configuration using:

    ip a