Time Synchronization in Modern Linux Systems: A Simple Guide
/ 3 min read
Table of Contents
Hello everyone. I decided to write this guide because I’m tired of seeing search results dominated by 10-year-old articles. Many of those guides still suggest installing and configuring older tools like chronyd or ntp, without mentioning that the (relatively) new systemd-timesyncd performs the task perfectly for most use cases without unnecessary complexity.
systemd-timesyncd has been the default out-of-the-box solution in almost all modern distributions (Ubuntu, Fedora, Arch, Manjaro, Debian) for about five years now.
Let’s look at how to configure it.
Checking the Service Status
First, verify that the service is enabled and running using the following command:
$ systemctl status systemd-timesyncd● systemd-timesyncd.service - Network Time Synchronization Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2024-03-02 10:51:42 UTC; 3min 53s ago Docs: man:systemd-timesyncd.service(8) Main PID: 580 (systemd-timesyn) Status: "Initial synchronization to time server 192.168.71.1:123 (192.168.71.1)." Tasks: 2 (limit: 4558) Memory: 1.5M CPU: 42ms CGroup: /system.slice/systemd-timesyncd.service └─580 /lib/systemd/systemd-timesyncdPay attention to two key areas:
enabled: If this saysdisabled, the service won’t start automatically on boot.active (running): If this shows any other state, the service is either stopped or has crashed.
You can enable and start the service with these commands:
# Enable the service for auto-startsudo systemctl enable systemd-timesyncd
# Start the service immediatelysudo systemctl start systemd-timesyncdUsing timedatectl
Next, use the timedatectl command to view the overall synchronization status:
$ timedatectl Local time: Sat 2024-03-02 11:10:56 UTC Universal time: Sat 2024-03-02 11:10:56 UTC RTC time: Sat 2024-03-02 11:10:56 Time zone: Etc/UTC (UTC, +0000)System clock synchronized: yes NTP service: active RTC in local TZ: noIn an ideal scenario, System clock synchronized should be yes and NTP service should be active.
If the NTP service is inactive, enable it with:
sudo timedatectl set-ntp trueTroubleshooting Synchronization Issues
If the NTP service is active but the system clock is not synchronized, the service likely cannot reach a reference time server. You can inspect the logs to diagnose the issue:
journalctl -xeu systemd-timesyncdThe logs will show which server timesyncd is trying to contact. You can test the connectivity to an NTP server (which uses port 123 via UDP) using nc (netcat):
$ nc -uvzw 3 ru.pool.ntp.org 123Connection to ru.pool.ntp.org (162.159.200.123) 123 port [udp/ntp] succeeded!If the connection fails, check your local firewall settings or the network’s security group (if you’re on a cloud provider).
Configuring Custom NTP Servers
To change the synchronization servers, edit /etc/systemd/timesyncd.conf. The default file looks like this:
[Time]#NTP=#FallbackNTP=ntp.ubuntu.com#RootDistanceMaxSec=5#PollIntervalMinSec=32#PollIntervalMaxSec=2048Lines starting with # are comments. To specify a server, uncomment the NTP= line and add your preferred servers:
NTP=ru.pool.ntp.org time.google.comIn restricted or corporate environments, your network administrator will usually provide internal NTP server addresses. Here are some reliable public options:
time.google.comru.pool.ntp.orgntp0.NL.netclock.isc.orgntp.ix.ru
After saving your changes, restart the service to apply them:
sudo systemctl restart systemd-timesyncdFinally, verify the status again with timedatectl to ensure that System clock synchronized now says yes.
If the issue persists, the logs are your best friend. Most synchronization failures are caused by network security rules blocking UDP traffic on port 123.
Thanks for your attention!