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.comAdd it to /etc/hosts so the server can resolve its own name without DNS:
203.0.113.10 server1.example.com server1Check both the short and full forms:
hostname && hostname -fSome 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:
timedatectlList and set a zone:
timedatectl list-timezones | grep Europetimedatectl set-timezone Europe/BerlinMany 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 trueOptionally choose servers in /etc/systemd/timesyncd.conf:
[Time]
NTP=0.pool.ntp.org 1.pool.ntp.orgThen systemctl restart systemd-timesyncd.
AlmaLinux and Rocky: chrony
dnf install chrony && systemctl enable --now chronydCheck its sources and current offset:
chronyc sources -vchronyc trackingchrony 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 makestepCheck the result
hostname -fprints the FQDN.timedatectlshows the right zone and synchronized: yes.datematches 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.
