What this is
This guide explains how to set the Linux hostname and edit /etc/hosts for local name resolution.
What it is for
- Give your VPS a clean, recognizable name
- Fix issues where services require a resolvable hostname
- Map internal names to IPs for convenience
Prerequisites
- SSH access + sudo
Step-by-step
Step 1) Check current hostname
hostname
hostnamectl
Step 2) Set a new hostname (recommended way)
sudo hostnamectl set-hostname vps-01
Expected output: Usually silent.
Step 3) Edit /etc/hosts
sudo nano /etc/hosts
Add or adjust a line like:
127.0.1.1 vps-01
Why: Prevents local resolution problems on some distributions.
Step 4) Verify
hostnamectl
getent hosts vps-01
Warnings & notes
/etc/hostsdoes not change public DNS; it only affects the local machine.- Pick a hostname using letters, numbers, and hyphens (no spaces).
Conclusion
Your server now has a consistent hostname and local mapping. This helps with administration and avoids some service warnings.