For various reasons we may need to change the hostname of an AlmaLinux host. For example, to join the host to an Active Directory domain which follows a certain naming convention for computer objects. Let’s dive into how to change AlmaLinux hostname.
Verify Current Hostname
Let’s first verify the current hostname of our AlmaLinux host.
hostname
This command will return the current hostname of our AlmaLinux. In our case, it is oldname.
Change Hostname
Now that we know the current hostname of our AlmaLinux host, let’s rename it to our desired name.
sudo hostnamectl set-hostname newname
Update Hosts File
After changing the name of our AlmaLinux host, we should also update the hosts file mappings of the IPv4 and IPv6 loopback addresses (127.0.0.1, ::1) from the old name to the new name.
Open /etc/hosts with your favorite text editor:
vi /etc/hosts
or
nano /etc/hosts
Change from old name:
127.0.0.1 oldname ... ...
to new name:
127.0.0.1 newname newname.itomation.ca
Restart the hostnamed service
To ensure the changes are applied, we need to restart the hostnamed service.
sudo systemctl restart systemd-hostnamed
Alternatively, for those from the Windows world, we can reboot the AlmaLinux host although it should not be required.
sudo reboot
How to Change AlmaLinux Hostname using the nmtui tool
We can also change hostname in AlmaLinux using the NetworkManager Text User Interface (nmtui) tool.
1. Open the nmtui text user interface tool: sudo nmtui
2. Using the arrow keys, select Set system hostname and hit Enter.
3. Replace the old hostname with the new hostname and press Enter.
Press Enter a second time.
4. Select Quit to exit the nmtui tool.
5. Verify the hostname was changed: hostname
Found this helpful? Comment below! ↓