How to connect to network automatically on AlmaLinux

Most Linux distributions, especially the user friendly ones, connect to your network and internet right away, when they first boot up.

This is thanks to DHCP, a protocol that the system uses to lease a local IP address from your router. However, some RHEL based distros, including AlmaLinux, don’t have this feature enabled out of the box.

In this guide, we’ll show you the step by step instructions for a couple different methods of connecting to a network automatically in AlmaLinux. Specifically, this will enable DHCP on a network interface, either temporarily or persistently.

In this tutorial you will learn:

  • How to connect to network via DHCP temporarily
  • How to configure persistent DHCP network configuration via command line and GUI
Configuring automatic connection to a network on AlmaLinux

Configuring automatic connection to a network on AlmaLinux

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System AlmaLinux
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to connect to network (DHCP) the quick way



To prompt your network adapter to fetch an IP address via DHCP, you can execute the following command in terminal.

# dhclient -v
Use dhclient command to retrieve new IP address via DHCP

Use dhclient command to retrieve new IP address via DHCP

Note that the -v option is for verbose and just shows us the DHCP retrieval process. You can then use a ping command to test your internet connection so you know the command worked.

If you have multiple network adapters and want to specify which one should be using DHCP, you can specify the adapter name in your dhclient command. For example, on our system we have an interface called ens160, which we can see with the ip a command. Let’s retrieve an IP address via DHCP on this interface.

# ip a
# dhclient ens160
Specify the adapter for which you want to receive a new DHCP address

Specify the adapter for which you want to receive a new DHCP address



How to configure persistent DHCP network configuration

Rather than needing to type a dhclient command every time you boot into AlmaLinux, we can configure our network interface to use DHCP every time.

This can be done by editing the network interface file. In our example, the adapter we need to configure is ens160 (seen with the ip a command). The file we need to edit is located in the following location.

# vi /etc/sysconfig/network-scripts/ifcfg-ens160

Edit the last line, ONBOOT and change it to yes.

Configure the ONBOOT setting to make this adapter retrieve an IP address automatically upon boot

Configure the ONBOOT setting to make this adapter retrieve an IP address automatically upon boot

Save your changes and exit this file. Now, when loading into AlmaLinux in the future, the adapter will retrieve an IP address via DHCP automatically.



This behavior can also be configured via GUI, by navigating to the system’s network settings menu.

Open the network settings of your adapter

Open the network settings of your adapter

Open your network adapter’s configuration menu, and enable the setting for “Connect automatically.”

Configure the interface to connect automatically

Configure the interface to connect automatically

Closing Thoughts

In this guide, we saw how to connect to a network automatically in AlmaLinux. This can be done either on a temporary or persistent basis, and we learned the command line and GUI method for both.

Another option we have is to configure a static IP address, which will also allow you to connect to the network automatically, while avoiding DHCP. Of course, this will only be ideal on certain network environments.