When managing an AlmaLinux server, properly setting the hostname ensures consistency with DNS records, mail server configurations, and security certificates. Below is a step-by-step procedure to view and update the server’s hostname.
1. Checking the Current Hostname
-
Log in to your server using SSH as the root user:
-
Once logged in, run the following command:
Example output:
This will display the server’s current hostname. Ideally, this should be a Fully Qualified Domain Name (FQDN) that resolves to your server’s primary public IP address.
2. Updating the Hostname
Step A: Configure /etc/hosts
Edit the /etc/hosts
file to ensure your hostname resolves locally. Use your preferred text editor, for example:
You will see entries similar to:
Replace the second line with your server’s main IP address and new hostname. For example:
Step B: Set the Hostname Temporarily
Use the following command to immediately change the hostname (this will last until reboot):
You can verify the change with:
Step C: Make the Hostname Persistent
On AlmaLinux (a RHEL/CentOS derivative), the persistent hostname is controlled by the /etc/hostname
file. Open it with:
Replace the contents with your desired hostname:
Save and exit. This ensures the hostname persists across reboots.
3. Confirming the Change
Reboot the server or reload the system configuration:
After the reboot, reconnect via SSH and run:
The output should reflect your new fully qualified hostname.
✅ Best Practice: Always ensure your hostname matches an FQDN that resolves correctly to your server’s IP address in DNS. This is critical for email deliverability, SSL certificates, and seamless server identification.