How to set the time zone, hostname and NTP on a Linux server

Set a server's time zone with timedatectl, give it a proper hostname, and keep its clock in sync with chrony or systemd-timesyncd, then check it really is.

Tested on Ubuntu 24.04 LTS, Debian 13 Stable, AlmaLinux 10

Before you start

  • A Linux server with systemd
  • Root or a user with sudo

To set the time zone on a Linux server, run sudo timedatectl set-timezone Europe/Amsterdam (any name from timedatectl list-timezones), or UTC. To check the clock is kept in sync, run timedatectl and look for System clock synchronized: yes and NTP service: active; if it isn't, install chrony and enable it.

The hostname is set with sudo hostnamectl set-hostname web-1. All three settings take effect at once, with no reboot. This tutorial was run on Ubuntu 24.04, Debian 13 and AlmaLinux 10; see the note under each step for what a container could and couldn't test.

Check the current settings

bash
timedatectl
text
               Local time: Wed 2026-10-21 14:32:10 UTC
           Universal time: Wed 2026-10-21 14:32:10 UTC
                 RTC time: Wed 2026-10-21 14:32:10
                Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

The two lines that matter are Time zone and System clock synchronized.

Set the time zone

Find your zone's name, then set it:

bash
timedatectl list-timezones | grep -i amsterdam
sudo timedatectl set-timezone Europe/Amsterdam

Zone names are Region/City, such as America/New_York or Asia/Singapore. A misspelled one is refused with Failed to set time zone: Invalid or not installed time zone.

UTC or local time?

Many people leave servers on UTC: logs from servers in different places line up, and there's no daylight saving jump that runs a 02:30 job twice or not at all. Pick local time if the people reading logs or the cron schedules think in it. Either way, applications should store timestamps in UTC; the server's zone only changes how times are shown and when cron fires.

To go back to UTC:

bash
sudo timedatectl set-timezone UTC

Check it worked

date now prints the time with your zone's abbreviation (CEST, EDT), and /etc/localtime links to the zone file. Restart long-running services that print times (sudo systemctl restart cron, your app) so they pick up the new zone; new processes see it immediately.

Set the hostname

bash
sudo hostnamectl set-hostname web-1

Use a short name of letters, digits and hyphens. It's stored in /etc/hostname and shows up in your shell prompt (after you log in again), in logs and in emails the server sends.

Some programs look the hostname up and wait for a timeout if they can't resolve it (sudo warns unable to resolve host web-1). Add it to /etc/hosts:

text
127.0.1.1   web-1.example.com web-1

On Ubuntu and Debian 127.0.1.1 is the usual line for this; on AlmaLinux and Rocky, append the names to the existing 127.0.0.1 line instead.

The hostname is a label for the server itself. What the internet sees is DNS: point a name at the server with an A record, and for a mail server, set reverse DNS to match.

On a cloud server, cloud-init may set the hostname and rewrite /etc/hosts again at every boot, undoing both changes. Tell it to leave them alone:

bash
sudo tee /etc/cloud/cloud.cfg.d/99-hostname.cfg <<'EOF'
preserve_hostname: true
manage_etc_hosts: false
EOF

We couldn't test hostnamectl set-hostname in a container (containers can't change their own hostname); the commands are the documented ones from man hostnamectl.

Keep the clock in sync with NTP

A server's clock drifts by seconds a week without correction. TLS certificates, two-factor codes, database replication and log correlation all need the right time. NTP (Network Time Protocol) fixes it continuously.

Most images already run an NTP client:

Distribution Default client
Ubuntu 24.04 systemd-timesyncd (simple, client only)
Debian 12 and 13 Depends on the image; timedatectl and systemctl status chrony systemd-timesyncd tell you
AlmaLinux, Rocky Linux, Fedora chronyd (package chrony)

Either is fine for a server. chrony handles bad network conditions better and can serve time to other machines; timesyncd is smaller. If timedatectl says NTP service: active and synchronized: yes, you're done.

Install chrony

bash
sudo apt install -y chrony                                          # Ubuntu, Debian
sudo dnf install -y chrony && sudo systemctl enable --now chronyd   # AlmaLinux, Rocky

On Ubuntu and Debian, installing chrony removes systemd-timesyncd (the packages conflict, since only one should set the clock) and starts chrony right away.

The servers it asks are in /etc/chrony/chrony.conf (Ubuntu, Debian) or /etc/chrony.conf (AlmaLinux, Rocky): pool lines pointing at the distribution's NTP pool. The defaults are fine. To use a provider's time servers, add a server or pool line and restart the service (chrony on Ubuntu and Debian, chronyd on AlmaLinux and Rocky).

Check it worked

bash
chronyc tracking
chronyc sources -v

In tracking, System time is how far the clock is from NTP time, normally well under a millisecond once it has settled, and Leap status should be Normal. In sources, the line starting with ^* is the server currently in use.

To see the offset against one server without changing anything, chrony has a query-only mode (the service needn't be running):

bash
sudo chronyd -Q 'server time.cloudflare.com iburst'

It prints System clock wrong by -0.541810 seconds (ignored) or similar, then exits. That's what we ran in our containers, which share the host's clock and so can't set their own.

Troubleshooting

System clock synchronized: no for more than a few minutes. The NTP client can't reach its servers. NTP uses outbound UDP port 123; check that a firewall isn't blocking it, then chronyc sources (all ^? means unreachable) or journalctl -u systemd-timesyncd.

NTP service: n/a. No NTP client that timedatectl knows about is installed. Install chrony as above.

sudo: unable to resolve host web-1: Name or service not known. The new hostname isn't in /etc/hosts. Add it as shown above.

Cron jobs ran at the wrong hour after changing the zone. Cron read the zone when it started. sudo systemctl restart cron (crond on AlmaLinux and Rocky).

Next steps

Doing it on VPSNine

On VPSNine, the hostname you type when you order a server is set by cloud-init on first boot, with /etc/hosts managed to match; that's why the 99-hostname.cfg step above matters if you rename it later. The panel keeps showing the name you ordered with. Images start on UTC. Every plan runs Ubuntu 24.04, Debian 13 and AlmaLinux 10.

Be first when orders open

Join the waitlist and we'll send you one email when VPSNine launches. Pick a plan if you already know which one you want, and we'll size the first servers around it.

  • One email, on launch day
  • Monthly or yearly, no lock-in
  • 14-day money-back guarantee