Set the hostname and timezone
A clear hostname makes your server easy to recognize in logs and prompts, and the right timezone keeps log timestamps, scheduled jobs and backups accurate. Both settings take only a few minutes.
Before you begin
- A sudo-enabled user logged in over SSH.
- A name for your server. Use lowercase letters, numbers and hyphens, such as
web1ormc-survival. - If you plan to point a domain at this server, decide on the full name too, such as
web1.example.com. The DNS guides cover that step.
Step 1: Check the current settings
hostname prints the short name, and timedatectl prints the clock and timezone. Run both to see where you are starting from:
hostname
timedatectl
web1
Local time: Sat 2026-10-31 09:14:02 UTC
Universal time: Sat 2026-10-31 09:14:02 UTC
RTC time: Sat 2026-10-31 09:14:02
Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: yes
NTP service: active
Step 2: Set the hostname
hostnamectl set-hostname changes the name permanently, so it survives reboots. Replace web1 with your chosen name:
sudo hostnamectl set-hostname web1
Your current session still shows the old name until you log in again. That is expected.
Step 3: Add the name to /etc/hosts
Some tools look up the server's own name in the /etc/hosts file. If the name is missing, sudo may print a warning. Open the file in the nano editor:
sudo nano /etc/hosts
Find the line that begins with 127.0.1.1 and make it match your names. Use the full name first, followed by the short name:
127.0.1.1 web1.example.com web1
Save with Ctrl+O, press Enter, then exit with Ctrl+X.
Step 4: Stop cloud-init from resetting the name
Many cloud images use a tool called cloud-init, which can reset the hostname on reboot. Tell it to leave your choice alone by creating a small configuration file:
sudo nano /etc/cloud/cloud.cfg.d/99-preserve-hostname.conf
Type this single line, then save and exit:
preserve_hostname: true
Step 5: Set the timezone
Search the list of timezone names first. The grep filter narrows the long list to the region you want:
timedatectl list-timezones | grep -i europe
Then set your choice. Many admins keep servers on UTC, which avoids confusion about daylight saving time. The example below uses a US timezone:
sudo timedatectl set-timezone America/Chicago
timedatectl status
Check that System clock synchronized says yes. That means the clock is kept accurate against network time servers.
Etc/UTC. Logs from several servers are easier to compare when they all use the same timezone.Step 6: Confirm the changes in a new session
Log out and back in so the new name appears in your prompt:
exit
ssh alex@203.0.113.10
alex@web1:~$
Troubleshooting
- "sudo: unable to resolve host web1". The name is missing from
/etc/hosts. Repeat Step 3. - The hostname reverts after a reboot. Cloud-init is overriding it. Confirm the file from Step 4 exists and contains
preserve_hostname: true, then runsudo hostnamectl set-hostname web1again. - The clock is not synchronized. Check the time service with
sudo systemctl status systemd-timesyncd --no-pager. Wait a few minutes after a fresh boot, then runtimedatectl statusagain. - The timezone name is rejected. Timezone names are case-sensitive and use the form Region/City. Copy the exact name from the list in Step 5.
Next steps
Your server now has a clear name and an accurate clock. Next, consider adding swap space if your server has little memory.
Something not working? Chat or email our support team and we will help you get unstuck.
Contact support