Managing and Changing the Hostname on AlmaLinux Servers Print

  • hostname, vps, server, change hostname, host name, ssh, dedicated server, fqdn, almalinux, hosts
  • 20029

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

  1. Log in to your server using SSH as the root user:

     
    ssh root@your-server-ip
  2. Once logged in, run the following command:

     
    hostname

    Example output:

     
    [root@server ~]# hostname host.domain.com [root@server ~]#

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:

nano /etc/hosts

You will see entries similar to:

127.0.0.1 localhost.localdomain localhost 10.10.10.10 server.mydomain.com server

Replace the second line with your server’s main IP address and new hostname. For example:

127.0.0.1 localhost.localdomain localhost 192.168.1.100 host.domain.com host

Step B: Set the Hostname Temporarily

Use the following command to immediately change the hostname (this will last until reboot):

hostnamectl set-hostname host.domain.com

You can verify the change with:

hostnamectl status

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:

nano /etc/hostname

Replace the contents with your desired hostname:

host.domain.com

Save and exit. This ensures the hostname persists across reboots.


3. Confirming the Change

Reboot the server or reload the system configuration:

reboot

After the reboot, reconnect via SSH and run:

hostnamectl

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.


Was this answer helpful?

« Back