How to configure a Static IP Address on AlmaLinux 10

In this tutorial we are going to explain how to configure a static IP address on AlmaLinux 10 OS. A static IP address is a unique numerical identifier assigned to a server that remains constant over time. A machine uses an IP address to locate and communicate with other machines (servers or computers) over the Internet. IP addresses are numerical identifiers that enable packets to be sent and received between one network device and another. The tutorial will cover identifying the network interface on your server, editing, and restarting the network service. Configuring a static IP Address on AlmaLinux 10 is a straightforward process that takes a couple of minutes. Let’s get started!

Prerequisites

Update the system

Before we start with the configuration process of the static IP address, it is recommended to update the system packages to their latest available versions. To do that, execute the following command:

sudo dnf update -y && sudo dnf upgrade -y

Identify the Network Interface

A network interface is the connection between the device (server in this case) and a network. The network interface can be a physical hardware component or a software-based interface. The common names for network interface are eth0, eth1, ens3, enp3s0 etc.

To detect the network interface execute the following command:

ip a

The output on the server we were using for this blog post was the following one:

[root@host ~]# ip a
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host noprefixroute 
       valid_lft forever preferred_lft forever
2: eth0:  mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:16:3e:79:35:ec brd ff:ff:ff:ff:ff:ff
    altname enp0s3
    altname ens3
    inet 192.168.0.26/21 brd 192.168.0.255 scope global dynamic noprefixroute eth0
       valid_lft 21556665sec preferred_lft 21556665sec
    inet6 fe80::69e9:637a:c215:f5d2/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

As we can see from the output above, the network interface is eth0 on our system. The IPv4 address is 192.168.0.26. Save your interface name, as you’ll need to know it when following the steps below.

Now, let’s check for the gateway:

route -n

You should get output similar to this:

[root@host etc]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.0.1     0.0.0.0         UG    100    0        0 eth0
192.168.0.0   0.0.0.0         255.255.255.0   U     100    0        0 eth0

The gateway is 192.168.0.1.

Last is to check the DNS servers:

cat /etc/resolv.conf

You should get the following output:

[root@host etc]# cat /etc/resolv.conf 
# Generated by NetworkManager
search test.vps
nameserver 1.1.1.1
nameserver 8.8.8.8

So we have all the data we need, and now we can proceed to the next paragraph on how to configure a static IP Address on AlmaLinux 10.

Configure static IP address

From the previous paragraph we have the following information:

Network Interface: eth0
IPv4 Address: 192.168.0.26/21
Gateway: 192.168.0.1
Preferred DNS: 1.1.1.1, 8.8.8.8

Now, let’s make the following IP address static using the nmcli. Nmcli is a command line tool used to control NetworkManager used to change network settings for a specific interface. In the following commands, we use the nmcli utility to set an IP address, default gateway, and DNS server on our eth0 interface.

To set up the IP address use the following command:

nmcli connection modify eth0 IPv4.address 192.168.0.26/21

You might get the following output about the eth0 connection not know.

[root@host ~]# nmcli connection modify eth0 IPv4.address 192.168.0.26/21
Error: unknown connection 'eth0'.

Do not worry about that, because the eth0 is still the network interface, just the name is different and in the nmcli command, we must specify the name of the connection. To check the name of the connection execute the following command:

nmcli conn show

You should get output similar to this:

NAME                UUID                                  TYPE      DEVICE 
Wired connection 1 a6eeb5f0-c075-3ff3-82fb-db1bc39e092e ethernet eth0
lo cb71db2a-9ecc-419b-86de-d051d81f4e74 loopback lo
ens3 27196f18-07c8-3029-9af8-e083aada8a3b ethernet -

So the name of the eth0 network interface is Wired connection 1 and that is the name we should use in the nmcli command:

nmcli connection modify "Wired connection 1" IPv4.address 192.168.0.26/21

With this command we set the IPv4 address to be 192.168.0.26/21. Now, let’s setup the gateway:

nmcli connection modify "Wired connection 1" IPv4.gateway 192.168.0.1

After this we need to set the preffered DNS:

nmcli connection modify "Wired connection 1" IPv4.dns "1.1.1.1 8.8.8.8"

And finally we set the method to manual to avoid using any other boot protocol for the interface. The command sets the BOOTPROTO option to none in the interface configuration file.

nmcli connection modify "Wired connection 1" IPv4.method manual

For the changes to take effect we need to restart the network using the device name eth0 now:

nmcli device disconnect eth0 && nmcli device connect eth0

If everything is OK, we can check the network configuration again with the nmcli command executed on the command line:

[root@host ~]# nmcli
eth0: connected to Wired connection 1
        "Red Hat Virtio"
        ethernet (virtio_net), 00:16:3E:79:35:EC, hw, mtu 1500
        ip4 default
        inet4 192.168.0.26/21
        route4 default via 192.168.0.1 metric 100
        route4 192.168.0.0/21 metric 100
        inet6 fe80::69e9:637a:c215:f5d2/64
        route6 fe80::/64 metric 1024

lo: connected (externally) to lo
        "lo"
        loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536
        inet4 127.0.0.1/8
        inet6 ::1/128

DNS configuration:
        servers: 1.1.1.1 8.8.8.8
        interface: eth0

That’s it. You successfully configured a static IP address on AlmaLinux 10 OS.

If you liked this post about configuring a static IP address on AlmaLinux 10, please share it with your friends or leave a comment down below.

Leave a Comment