A Hostname is the unique identifier or label assigned to your Linux Virtual Private Server (VPS) on a network. By default, newly provisioned servers often come with generic hostnames (such as localhost, vps-12345, or ubuntu). Setting a proper Fully Qualified Domain Name (FQDN) – such as vps.domain.com, server1.domain.com, or mail.domain.com – is crucial for server identification, system logging, SSL certificate generation, and email deliverability (matching Reverse DNS / PTR records).
In modern Linux distributions powered by systemd, configuring your server hostname is fast, standardized, and applies immediately without requiring a full server reboot.
In this step-by-step tutorial, you will learn how to check your current hostname, set a static FQDN hostname across Ubuntu, Debian, AlmaLinux, Rocky Linux, RHEL, and CentOS, configure the /etc/hosts resolution file, and prevent cloud-init from resetting your hostname upon reboot.
Prerequisites
- An active Linux VPS running Ubuntu, Debian, AlmaLinux, Rocky Linux, RHEL, or CentOS.
- SSH access with
sudoor root privileges (see How to Log in and Access Linux VPS via SSH). - A domain name with an A Record pointing your desired hostname subdomain (e.g.
vps.domain.com) to your server’s public IP address (see How to Point Your Domain to a VPS IP Address).
Step 1: Check Current Hostname
To inspect your server’s current hostname and system details, run:
hostnamectl status
You will see output detailing the current Static hostname, Operating System, Kernel, and Architecture:
Static hostname: localhost.localdomain
Icon name: computer-vm
Chassis: vm
Operating System: Ubuntu 26.04 LTS (or AlmaLinux 9)
Kernel: Linux 6.8.0-generic
Architecture: x86-64
Step 2: Set the New Hostname Using hostnamectl
The hostnamectl utility is part of systemd and works identically across all modern Linux distributions. Set your new Fully Qualified Domain Name (FQDN):
# Replace 'vps.domain.com' with your actual FQDN hostname
sudo hostnamectl set-hostname vps.domain.com
This command automatically updates the kernel hostname and writes the change to the /etc/hostname configuration file.
Step 3: Update the /etc/hosts File (CRITICAL STEP)
To prevent system delays, sudo latency, and mail routing errors, your Linux server must be able to resolve its own hostname locally.
- Open the hosts file in a text editor:
sudo nano /etc/hosts - Add or update the lines mapping
127.0.0.1and your Server Public IP to your new FQDN hostname and short hostname:127.0.0.1 localhost localhost.localdomain 107.178.111.179 vps.domain.com vps # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback(Replace
107.178.111.179with your VPS public IP,vps.domain.comwith your FQDN, andvpswith your short server name). - Save and exit (
CTRL + O,ENTER,CTRL + X).
Step 4: Verify Hostname and FQDN Resolution
Run the verification commands to confirm both short hostname and FQDN resolution:
# Check short hostname
hostname
# Check Fully Qualified Domain Name (FQDN)
hostname -f
# Check domain part
dnsdomainname
Output should accurately return vps.domain.com for hostname -f and domain.com for dnsdomainname.
Step 5: Prevent Cloud-Init from Overwriting Hostname (If Applicable)
Some cloud images utilize the cloud-init utility, which can revert hostnames to provider defaults after a server reboot. To ensure your custom hostname remains permanent:
- Check if cloud-init configuration exists:
sudo nano /etc/cloud/cloud.cfg - If the file exists, locate
preserve_hostnameand set it totrue:preserve_hostname: true - Save and exit (
CTRL + O,ENTER,CTRL + X).
Step 6: Configure Reverse DNS (PTR Record)
If you plan to send emails (Postfix, Exim, cPanel, DirectAdmin) or run high-reputation web services, your server’s Reverse DNS (rDNS / PTR) record must match your hostname (vps.domain.com).
To set or verify your PTR record, check your VPS network settings in the Aveshost Client Area or submit a support ticket to our network engineering team.
Frequently Asked Questions & Troubleshooting
Q: Why does sudo display "sudo: unable to resolve host vps: Name or service not known"?
A: This warning happens when the new hostname set with hostnamectl is not listed in the /etc/hosts file. Add 127.0.0.1 vps.domain.com vps to /etc/hosts to resolve the warning immediately.
Q: Do I need to restart my VPS after changing the hostname?
A: No. hostnamectl applies the hostname immediately. However, logging out and logging back in via SSH will refresh your terminal prompt to display the new hostname (e.g. root@vps:~#).
Need Further Assistance?
If you need assistance configuring hostnames, setting up Reverse DNS (PTR) records, or troubleshooting network domain resolution on your Linux VPS, our technical support team is available 24/7. Feel free to submit a support ticket through your client area for expert assistance.