When managing an AlmaLinux server, setting the hostname correctly helps keep DNS, email services, SSL certificates, and server identification consistent.
The hostname should normally be a Fully Qualified Domain Name (FQDN) such as:
host.domain.com
1. Check the Current Hostname
Log in to the server through SSH as root:
ssh root@your-server-ip
Check the current hostname:
hostname
For more detailed information, use:
hostnamectl
Example:
Static hostname: host.domain.com
Operating System: AlmaLinux
The hostname should normally resolve through DNS to the server's primary public IP address.
2. Set the New Hostname
Use hostnamectl to change the hostname:
hostnamectl set-hostname host.domain.com
Replace host.domain.com with the hostname you want to use.
This change takes effect immediately and is persistent across reboots.
Verify it with:
hostnamectl
or:
hostname
3. Update /etc/hosts
Next, make sure the server can resolve its own hostname locally.
Open:
nano /etc/hosts
You may see something similar to:
127.0.0.1 localhost localhost.localdomain
::1 localhost localhost.localdomain
Add a separate line using the server's primary IP address and hostname:
192.0.2.10 host.domain.com host
For example, if the server IP is 104.223.9.14:
104.223.9.14 host.domain.com host
Do not remove the existing localhost entries.
Save the file and exit.
4. Configure DNS
Create an A record for the hostname pointing to the server's primary public IP address.
For example:
host.domain.com → 104.223.9.14
You can verify DNS resolution with:
dig host.domain.com +short
or:
host host.domain.com
The result should return the server's correct public IP address.
5. Verify the Configuration
Run:
hostnamectl
Then verify that the hostname resolves locally:
getent hosts host.domain.com
You can also reboot the server if desired:
reboot
A reboot is normally not required just to change the hostname with hostnamectl.
Best Practices
Use a dedicated FQDN for the server, such as:
host.domain.com
Avoid using:
-
A hostname without a domain, such as
server1 -
A domain used for a customer website
-
A hostname that does not resolve through DNS
-
An IP address as the hostname
The hostname should have a valid DNS record pointing to the server and should remain stable.
For servers that send email, proper hostname and DNS configuration is especially important for mail identification, SSL certificates, and email deliverability.