Linux VPS

Set the hostname, time zone and time sync on a Linux VPS

Give a new Linux VPS a proper FQDN hostname, set the right time zone and keep the clock accurate with chrony or systemd-timesyncd.

BeginnerLinux VPS3 min read

Three small settings on a new server prevent a surprising number of problems later: the hostname (mail servers and control panels check it), the time zone (log times and cron schedules) and time sync (SSL, 2FA codes and database replication break when the clock drifts).

Before you start

  • Root or sudo access to any systemd-based distro.
  • A hostname you control, ideally a subdomain such as server1.example.com, with an A record pointing to the VPS IP.

Set the hostname

Use a fully qualified domain name (FQDN):

hostnamectl set-hostname server1.example.com

Add it to /etc/hosts so the server can resolve its own name without DNS:

203.0.113.10   server1.example.com server1

Check both the short and full forms:

hostname && hostname -f

Some cloud images reset the hostname on reboot through cloud-init. If yours does, set preserve_hostname: true in /etc/cloud/cloud.cfg.

Tip: for a mail server, also ask your provider to set the IP's reverse DNS (PTR) to the same hostname. Matching forward and reverse DNS helps deliverability.

Set the time zone

Show the current setting:

timedatectl

List and set a zone:

timedatectl list-timezones | grep Europe
timedatectl set-timezone Europe/Berlin

Many admins keep servers on UTC to avoid daylight-saving surprises and to match logs across servers in different regions. Restart services that cache the zone (cron, PHP-FPM, MySQL) after changing it. For PHP, also set date.timezone in php.ini to match.

Enable time synchronisation

Check whether the clock is synced: timedatectl should show System clock synchronized: yes and NTP service: active.

Ubuntu and Debian: systemd-timesyncd

timedatectl set-ntp true

Optionally choose servers in /etc/systemd/timesyncd.conf:

[Time]
NTP=0.pool.ntp.org 1.pool.ntp.org

Then systemctl restart systemd-timesyncd.

AlmaLinux and Rocky: chrony

dnf install chrony && systemctl enable --now chronyd

Check its sources and current offset:

chronyc sources -v
chronyc tracking

chrony is also available on Debian/Ubuntu (apt install chrony) and handles large offsets and virtual machines well. Run only one time service at a time.

Fix a clock that is far off

chrony corrects large offsets slowly by default. Step the clock immediately:

chronyc makestep

Check the result

  • hostname -f prints the FQDN.
  • timedatectl shows the right zone and synchronized: yes.
  • date matches a trusted clock within a second.

Troubleshooting

  • sudo: unable to resolve host: the new hostname is missing from /etc/hosts.
  • NTP stays inactive: outbound UDP port 123 is blocked by a firewall, or the VPS type does not allow guests to set the clock (container VPS); the host manages time then.
  • cron jobs run at the wrong hour: restart cron after changing the time zone.
  • 2FA codes rejected: the clock is off by more than about 30 seconds. Fix time sync first.

Hostname and time FAQ

What makes a good server hostname?

A subdomain you own that is not your website's address, e.g. srv1.example.com, with a matching A record.

Should servers use UTC?

It is common practice, especially with servers in several regions. Applications can still display local time to users.

Does cPanel need a specific hostname?

Yes, WHM requires an FQDN hostname that resolves to the server, and it is used for the server's SSL certificate.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.