The hostname identifies your server on a network and appears in shell prompts, log files, and monitoring dashboards. Ubuntu 26.04 LTS uses hostnamectl — a systemd utility — to view and change the hostname persistently without a reboot.
Tested and valid on:
- Ubuntu 26.04 LTS
Prerequisites
- Ubuntu 26.04 LTS server
- A user with sudo privileges
Step 1 – Check the Current Hostname
Display the full hostname configuration:
hostnamectl
Step 2 – Set a New Static Hostname
Replace new-hostname with your desired name (lowercase letters, digits, and hyphens only):
sudo hostnamectl set-hostname new-hostname
Step 3 – Update /etc/hosts
Ensure the new hostname resolves locally to prevent sudo delays:
sudo nano /etc/hosts
Update the line with 127.0.1.1 to match the new hostname:
127.0.1.1 new-hostname
Step 4 – Set a Pretty Hostname (optional)
A pretty hostname can include spaces and special characters for display purposes:
sudo hostnamectl set-hostname "My Production Server" --pretty
Step 5 – Verify the Change
Confirm the new hostname is set:
hostnamectl
hostname
uname -n
Open a new shell session to see the updated prompt.
Step 6 – Set Hostname in Cloud Environments
On cloud instances (AWS, GCP, Azure), cloud-init may reset the hostname on reboot. Disable this behaviour:
sudo nano /etc/cloud/cloud.cfg
Set or confirm:
preserve_hostname: true
Conclusion
Your Ubuntu 26.04 LTS server now has a persistent hostname that survives reboots. Update DNS records if this server is addressed by a domain name, and inform any monitoring systems of the change.