Wednesday, July 3, 2024
HomeOperating SystemsRocky linuxConfigure Static IP Address on Rocky Linux 9 / AlmaLinux 9

Configure Static IP Address on Rocky Linux 9 / AlmaLinux 9

Networking is a fundamental aspect of all operating systems. It is used both in homes when connecting two computers to large enterprises with innumerable systems. It is also used to connect computers worldwide over the internet. In Linux systems, there are strong networking instruments that manage and monitor routing, bridging, virtual networks e.t.c

RedHat provides a consistent method of naming the network interfaces that helps to locate and differentiate the interfaces. Normally, the Kernel assigns these names using a fixed prefix and number when it initializes the networks. This is achieved using the udev device manager that supports a number of naming schemes. It assigns these names based on the firmware, topology, and location. This offers several advantages such that:

  • Device names are fully predictable.
  • The names stay fixed even if you add or remove hardware since no re-enumeration happens
  • Faulty hardware can be seamlessly replaced

The consistent naming method is enabled by default on RedHat. This allows udev to generate device names using the below hierarchy:

Scheme Description Example
1 These are the device names for firmware or BIOS-provided index numbers for onboard devices. If this is not available, scheme 2 is used. eno1
2 Devices names for firmware or BIOS-provided PCI Express(PCIe) hot plug slot index numbers. If not available, scheme 3 is used ens1
3 Device names for the physical location of the connector of the hardware. If not available scheme 4 is used. enp6s0
4 Device names for the MAC address. This is not enabled by default but admins can optionally use it enx525400d5e0fb
5 The traditional unpredictable kernel naming scheme. This is used when udev cannot apply all the above schemes eth0

On Rhel systems, there are three ways how to configure a network. There are:

  • During installation.
  • Using network-scripts
  • Using Network Manager.

Network Manager is a default tool on Rhel-based systems designed to manage networks. It provides several Network managing tools that include:

  • Nmtui: this is a command line, text-based tool network manager tool where changes can be made on a network by entering data and menu selections. It offers limited features provided by the Network Manager
  • Gnome Setting: this tool is provided on the Gnome desktop. It allows one to manage the network by using a Gnome network application. It provides basic network management and is easy to perform configurations.
  • nm-connection-editor: a graphical-based tool that allows one to make the Network Manager configurations.
  • NMCLI: also known as Network Command-Line Interface is a networking tool used to manage the NetworkManager and also show the status of a network connection. It is useful when one is unable to access the GUI or when running a server edition and they want to do network configuration changes.

Network Manager is highly preferred due to the following reasons:

  • It is easier to manage the network interfaces.
  • Supports configuration flexibility.
  • Maintains the state of devices after the reboot process and takes over interfaces that are set into a managed mode during restart.
  • Offers an API through D-Bus which allows to query and control network configuration and state
  • Handles devices that are not explicitly set unmanaged but controlled manually by the user or another network service.
  • Multiple integration options
  • The built-in root cause analysis capabilities

In this guide, we will learn how to configure Static IP Address on Rocky Linux 9 / AlmaLinux 9 using NMCLI, NMTUI and Network scripts.

1. Set Static IP Address using NMTUI

This is the easiest method to set a static IP Address on Rocky Linux 9 / AlmaLinux 9. Since Network Manager is already installed, we will launch NMTUI using the command;

# nmtui

The utility will begin as shown.

Static IP Address on Rocky Linux

There are several options provided on the menu above. To add a new connection profile, click on Edit a connection

Static IP Address on Rocky Linux AlmaLinux 1

Select if you want to edit the connection or create a new connection. For this case, we will add a new connection with a second interface attached.

Select the type of connection to create.

Static IP Address on Rocky Linux AlmaLinux 2

The following step allows you to configure/edit the interface and set the static IP. For a new interface, you need to provide the interface name IP address, netmask, gateway, and DNS as shown.

Static IP Address on Rocky Linux AlmaLinux 3

Once the desired changes have been made, scroll down and ensure that “automatically connect” and “available for others” are enabled. To enable these, use the space bar. Save the made changes.

Static IP Address on Rocky Linux AlmaLinux 4

Once created/edited, the interface will be available as shown.

Static IP Address on Rocky Linux AlmaLinux 5

Use the ESC key to get back to the main page and select activate connection.

Static IP Address on Rocky Linux AlmaLinux 6

Now deactivate and activate the connection by pressing Enter to apply the made changes.

Static IP Address on Rocky Linux AlmaLinux 7

Now exit Nmtui using the ESC key and verify the made changes:

Static IP Address on Rocky Linux AlmaLinux 8

It is that easy to edit/create a connection profile with a static IP address using NMTUI.

2. Set Static IP Address using NMCLI

NMCLI can also be used from the Rocky Linux 9 / AlmaLinux 9 terminal to create or edit a connection.

First, identify the available connections using the command:

# nmcli device
DEVICE   TYPE      STATE         CONNECTION 
enp6s18  ethernet  connected     enp6s18    
enp6s19  ethernet  disconnected  --         
lo       loopback  unmanaged     --         

A. Add Network Connections using NMCLI

You can now add a connection using the syntax:

sudo nmcli connection add type <network-type> ifname <connection-name>

For example, in this case, using the device enp6s19, we will add a new connection as shown:

$ sudo nmcli connection add con-name My-New-Connection ifname enp6s19 type ethernet
Connection 'My-New-Connection' (e55288a8-9f0f-4b6a-9e8c-57d0ecee8ecf) successfully added.

Once the connection has been added, set the automatic start of the network connection:

sudo nmcli connection modify My-New-Connection connection.autoconnect yes

Verify the made changes:

$ nmcli -f DEVICE,STATE device
DEVICE   STATE     
enp6s18  connected 
enp6s19  connected 
lo       unmanaged 

B. Modify Network Connections using NMCLI

Now we will modify the connection and set a static IPv4 address with a /24 subnet mask as shown:

##For IPv4 address with a /24 subnet
sudo nmcli connection modify My-New-Connection ipv4.address 192.168.205.29/24

##For IPv6 address with a /64 subnet
sudo nmcli connection modify My-New-Connection ipv6.addresses 2001:db8:1::1/64

Once the IP Address has been configured, provide the gateway:

##For IPv4
sudo nmcli connection modify My-New-Connection ipv4.gateway 192.168.205.1

##For IPv6
sudo nmcli connection modify My-New-Connection ipv6.gateway 2001:db8:1::fffe

Set the DNS server for your connection.

##For IPv4
sudo nmcli connection modify My-New-Connection ipv4.dns "192.168.205.1"

##For IPv6
sudo nmcli connection modify My-New-Connection ipv6.dns "2001:db8:1::ffbb"

Finally set the IPv4 and IPv6 connection methods to automatic:

##For IPv4
sudo nmcli connection modify My-New-Connection ipv4.method auto

##For IPv6
sudo nmcli connection modify My-New-Connection ipv6.method auto

Activate the profile for the changes made to apply:

$ sudo nmcli connection up My-New-Connection
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)

Verify the made changes:

$ nmcli connection show --active
NAME               UUID                                  TYPE      DEVICE  
enp6s18            f546038c-74f7-359d-849b-c7be2f0bd125  ethernet  enp6s18 
My-New-Connection  e55288a8-9f0f-4b6a-9e8c-57d0ecee8ecf  ethernet  enp6s19 

Check the set IP Address:

$ hostname -I
192.168.205.12 192.168.205.29 

3. Set Static IP Address using network-scripts

There is also another method to configure a static Ip address on Rocky Linux 9 / AlmaLinux 9 using the network scripts. Normally, the Network Manager will load the scripts in the /etc/sysconfig/network-scripts/ifcfg-* directory. What you need to do is create a network script with the device name as shown:

sudo vim /etc/sysconfig/network-scripts/ifcfg-enp6s19

In the file, add the below line replacing appropriately:

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=sample_conn
DEVICE=enp6s19
ONBOOT=yes
        IPADDR=192.168.205.26
        NETMASK=255.255.255.0
        GATEWAY=192.168.205.1
        DNS1=192.168.205.1
        DNS2=8.8.8.8
        DOMAIN=neveropen.co.za

First, ensure that the connection on the device is deleted. For example, in this case, we will delete the connection above on the device enp6s19:

$ sudo nmcli connection delete My-New-Connection
Connection 'My-New-Connection' (e55288a8-9f0f-4b6a-9e8c-57d0ecee8ecf) successfully deleted.

Once the changes have been made in the file, restart the Network Manager:

sudo systemctl restart NetworkManager

Verify the made changes:

$ nmcli connection show
NAME         UUID                                  TYPE      DEVICE  
enp6s18      f546038c-74f7-359d-849b-c7be2f0bd125  ethernet  enp6s18 
sample_conn  281c08c7-70b1-9ad3-0006-38e553f01101  ethernet  enp6s19 

4. Delete, Deactivate and Unmanage NetworkManager Devices

To delete the connection, use the command:

nmcli connection delete connection_name

First, identify the connection name:

$ nmcli connection show
NAME         UUID                                  TYPE      DEVICE  
enp6s18      f546038c-74f7-359d-849b-c7be2f0bd125  ethernet  enp6s18 
sample_conn  281c08c7-70b1-9ad3-0006-38e553f01101  ethernet  enp6s19 

Delete the connection:

$ sudo nmcli connection delete sample_conn
Connection 'sample_conn' (281c08c7-70b1-9ad3-0006-38e553f01101) successfully deleted.

You can deactivate the connection using the command:

sudo nmcli connection down connection_name

To un-manage a device, use the command:

nmcli dev set device-name managed no

For example, to manage the enp6s19 device, use the command:

sudo nmcli dev set enp6s19 managed no

Verify the made changes:

$ nmcli -f DEVICE,STATE device
DEVICE   STATE     
enp6s18  connected 
enp6s19  unmanaged 
lo       unmanaged 

Final Thoughts

That marks the end of this guide on how to configure Static IP Address on Rocky Linux 9 / AlmaLinux 9. I hope this was important to you.

See related posts:

Install and Use NetworkManager (NMCLI) on Ubuntu / Debian

Configure Network NIC Teaming on Rocky Linux 8|AlmaLinux 8

Creating VM and Storage Logical Networks in oVirt/RHEV

Dominic Rubhabha Wardslaus
Dominic Rubhabha Wardslaushttps://neveropen.dev
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments