skip to content
Skesov.com

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:

Terminal window
$ 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-timesyncd

Pay attention to two key areas:

  1. enabled: If this says disabled, the service won’t start automatically on boot.
  2. 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:

Terminal window
# Enable the service for auto-start
sudo systemctl enable systemd-timesyncd
# Start the service immediately
sudo systemctl start systemd-timesyncd

Using timedatectl

Next, use the timedatectl command to view the overall synchronization status:

Terminal window
$ 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: no

In an ideal scenario, System clock synchronized should be yes and NTP service should be active.

If the NTP service is inactive, enable it with:

Terminal window
sudo timedatectl set-ntp true

Troubleshooting 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:

Terminal window
journalctl -xeu systemd-timesyncd

The 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):

Terminal window
$ nc -uvzw 3 ru.pool.ntp.org 123
Connection 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=2048

Lines starting with # are comments. To specify a server, uncomment the NTP= line and add your preferred servers:

NTP=ru.pool.ntp.org time.google.com

In restricted or corporate environments, your network administrator will usually provide internal NTP server addresses. Here are some reliable public options:

  • time.google.com
  • ru.pool.ntp.org
  • ntp0.NL.net
  • clock.isc.org
  • ntp.ix.ru

After saving your changes, restart the service to apply them:

Terminal window
sudo systemctl restart systemd-timesyncd

Finally, 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!