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
-
Login into SSH or console.
-
Make sure you are sudo.
-
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}
-
If you just deployed a new VPS, before starting the configuration, you need to restart NetworkManager with the following command:
systemctl restart NetworkManager
-
You have to identify the network interface:
nmcli d
-
and the current assigned DHCP IP:
ip a
-
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]
-
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]
-
Assign the DNS server
nmcli con mod [network interface] ipv4.dns '8.8.8.8, 1.1.1.1'
-
To apply the settings, we have to restart the internet connection:
nmcli con down [network interface] nmcli con up [network interface]
-
You can check the configuration using:
ip a
Note: If the
AUTOCONNECT_PRIORITY
value in your configuration is lower than theifcfg-[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:In nmcli configuration the value of AUTOCONNECT_PRIORITY by default is 0.AUTOCONNECT_PRIORITY=-1
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.
-
Assign the second IP:
nmcli con mod [network interface] +ipv4.addresses [your second ip]/[netmask]
-
Assign the second gateway:
nmcli con mod [network interface] +ipv4.gateway [gateway second ip]
-
To apply the settings, we have to restart the internet connection:
nmcli con down [network interface] nmcli con up [network interface]
-
You can check the configuration using:
ip a