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
|Category||Requirements, Conventions or Software Version Used|
|Other||Privileged access to your Linux system as root or via the |
|Conventions|| # - requires given linux commands to be executed with root privileges either directly as a root user or by use of |
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
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
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
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 your network adapter's configuration menu, and enable the setting for "Connect automatically."
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.