When you install AlmaLinux, you have two options when it comes to networking – use DHCP or set a static IP. In some cases, you may decide that you want to change from a DHCP to static IP. There are a few ways to do this, and I’ll show you the two I use the most.
Option 1: Modify Interface Configuration File
To find your interface name, run the command ip a
which will show you your interface IPs.
Now, run the following command as root:
vi /etc/sysconfig/network-scripts/ifcfg-ens18
Looking at the config, you can see BOOTPROTO is set to dhcp.
Change this line to “none”. Now we just need to add our IP details.
IPADDR=10.200.1.20 PREFIX=24 GATEWAY=10.200.1.1 DNS1=1.1.1.1
Prefix is our subnet mask represented in bits.
Save the config and restart the network.
nmcli connection down ens18 && nmcli connection up ens18
Option 2: Using nmtui
Run the following command as root:
nmtui
Select Edit a connection.
Select the connection.
Modify the connection details.
Once you’ve modified the connection, restart it.
nmcli connection down ens18 && nmcli connection up ens18