How to Configure a Static IP Address on AlmaLinux 10

How to configure a static IP address on AlmaLinux 10

When managing IP addresses on Linux machines, we have two primary options for configuring network interfaces. We can either opt for DHCP for dynamic IP address assignment or set up a static IP address that remains unchanged. Static IP addresses are used for devices that require consistent, dependable access, such as servers, printers, and other network devices, as they ensure that other devices can consistently locate and connect to them. In this article, we will show you how to configure a static IP address on AlmaLinux 10.

Prerequisites

  • An AlmaLinux 10 VPS
  • SSH root access or a regular system user with sudo privileges

Conventions

# – given commands should be executed with root privileges either directly as a root user or by use of sudo command
$ – given commands should be executed as a regular user

Step 1: Update the System

First, you will need to log in to your AlmaLinux 8 VPS via SSH as the root user:

ssh root@IP_Address -p Port_number

You will need to substitute ‘IP_Address’ and ‘Port_number’ with your server’s corresponding IP address and SSH port number. Furthermore, substitute ‘root’ with the username of the system user with sudo privileges.

You can verify whether you have the correct AlmaLinux version installed on your server with the following command:

# cat /etc/almalinux-release 

You will see this message:

AlmaLinux release 10.0 (Purple Lion)

In this article, we are using ‘root’ to execute the shell commands. If you want to use your regular user with sudo privileges to run the commands, make sure to append ‘sudo’ in front of the commands. Running these commands is crucial to setting up a static IP address on AlmaLinux 10.

Step 2: Identify The Network Interface

Use the following command to find your network interface name.

# ip a

The command will print you something like this:

1: lo: <LOOPBACK,UP,LOWER_UP> 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: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:92:81:a0 brd ff:ff:ff:ff:ff:ff
    altname enp3s0
    altname enx000c299281a0
    inet 192.168.141.131/24 brd 192.168.141.255 scope global dynamic noprefixroute ens160
       valid_lft 1397sec preferred_lft 1397sec
    inet6 fe80::20c:29ff:fe92:81a0/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

Look for interfaces like enp3s0, eth0, or similar. For example, in this article we will change the IP address 192.168.141.131, which is part of the process of configuring a static IP address on AlmaLinux 10.

Step 3. Configure Static IP Address

Method 1: Using Network Manager

Determine the name of your network interface, common names for interface include ens3, eth0, enp3s0 and many more. As in the article our network interface is ens160. When navigating to /etc/NetworkManager/system-connections/ directory, we will see the configuration file for our network interface. The filename is ens160.nmconnection. You will see more configuration files in this directory if you have other network interfaces.

Now, let’s modify our ens160.nmconnection file for your network interface to set a static IP address on AlmaLinux 10.

# cd /etc/NetworkManager/system-connections/
# nano ens160.nmconnection

In this file, you will see:

[connection]
id=ens160
uuid=7ba60ae9-3ce6-341c-b7f3-163cf0ab4e90
type=ethernet
autoconnect-priority=-999
interface-name=ens160
timestamp=1762703171

[ethernet]

[ipv4]
method=auto

[ipv6]
addr-gen-mode=eui64
method=auto

[proxy]

We need to make changes under the [ipv4] section. For example, we want to change the IP address from 192.168.141.131 to 192.168.141.22, it should look like this:

[ipv4]
#method=auto
address=192.168.141.22/24
dns=8.8.8.8,1.1.1.1;
gateway=192.168.141.1
method=manual

Save the file then exit. Now, you can restart Network Manager.

# systemctl restart NetworkManager

Method 2: Using NMCLI

To check our network interface, we can also run this command below:

# nmcli device status

You will see the following interface name information will be displayed.

DEVICE  TYPE      STATE                   CONNECTION 
ens160  ethernet  connected               ens160     
lo      loopback  connected (externally)  lo    

From the information above, it is known that ens160 and lo are connected.

Configuring a Static IP with nmcli

To configure the interface, you can select which interface you want to configure using the nmcli tool. Use the following command line to set up a static IP address on AlmaLinux 10.

# nmcli connection modify ens160 IPv4.address 192.168.141.33/24
# nmcli connection modify ens160 IPv4.gateway 192.168.141.1
# nmcli connection modify ens160 IPv4.dns 1.1.1.1
# nmcli connection modify ens160 IPv4.method manual

To apply the changes, we need to restart the network connection.

Let’s bring the network down and bring it back online again by running the commands below:

# nmcli con down ens160

Be informed that you will be disconnected if you configure the IP address and run the command above through an SSH connection, make sure to run the commands above when you have a console or direct/physical access to your server.

To bring it up again, run this command:

# nmcli con up ens160

Once restarted, you should be able to use the new IP address, confirming the successful configuration of the static IP on AlmaLinux 10.

Congratulations! You have learned how to configure a static IP address on AlmaLinux 10.

PS. If you liked this post please share it with your friends or leave a comment below. Thanks.

Leave a Comment