Hostxpeed
Login Get Started →
Server Management

How to Set Up Hostname Correctly

4 min read
23 views
Jun 10, 2026

Prerequisites

Before setting hostname, make sure you have:

  • SSH access to your VPS
  • Root or sudo privileges
  • A domain name you own (or a valid FQDN)

Step 1: Choose a Proper Hostname

Best practice: use a subdomain of a domain you control, e.g., web01.yourdomain.com or vps.yourdomain.com.

Avoid generic names like localhost, ubuntu-server, or myvps.

Step 2: Set Hostname Using hostnamectl (Recommended)

Connect to your VPS:

ssh hxroot@YOUR_SERVER_IP -p 22
sudo hostnamectl set-hostname web01.yourdomain.com

Verify:

hostnamectl

Step 3: Edit /etc/hosts File

sudo nano /etc/hosts

Add or modify the line for your server's IP:

YOUR_IP web01.yourdomain.com web01

Also ensure localhost line is present:

127.0.0.1 localhost localhost.localdomain

Step 4: Verify FQDN Resolution

hostname -f

Should output full hostname (e.g., web01.yourdomain.com).

hostname -s

Should output short hostname (e.g., web01).

Step 5: Test Hostname Resolution

ping -c 2 web01.yourdomain.com

Should ping your VPS IP.

Why Correct Hostname Matters

  • Email headers and deliverability
  • Log files and error messages
  • SSL certificate generation (some tools check hostname)
  • Control panels (HestiaCP, cPanel)
  • Server monitoring and identification

Change Hostname Permanently (Alternative Method)

echo "web01.yourdomain.com" | sudo tee /etc/hostname

Then reboot or run:

sudo systemctl restart systemd-hostnamed

✅ Hostname is now correctly configured. Your server will identify itself properly on the network.

Was this article helpful?