Time synchronization involves keeping your system time and date updated so as to receive new updates. If your system time is not synchronized correctly, you might miss out on the latest package and system updates which in turn might affect the installation of newer packages released. Also, the thing to do with SSL certificates expiring can be caused by not having an updated time on your system. Time synchronization in a distributed system is important as it maintains order or the sequence of events with coordinated network clocks. The clock is not only used to indicate time but also plays a role in how the system operations and services are performed to ensure a simultaneous working environment.
There are two types of synchronization; external and internal. External synchronization is where all computers in the system are synchronized with an external source of time like a UTC signal or radion. Internal synchronization is where all computers in the system are synchronized with one another, but the time is not necessarily accurate with respect to UTC. Both types of synchronization use the Network Time Protocol (NTP) to synchronize time.
NTP has been widely used to synchronize network time from a public Internet Time Server, However, there is a security concern as the port used by NTP which is the UDP port 23 is left open in the firewall to receive packets that contain the time information. NTP is mainly used to implement the security mechanism which depends on consistent timekeeping over the network. But if the servers go down, the sync time is affected across a running communication and may delay r drift the time.
Systemd Timesyncd is a service that is used to synchronize the local system clock with a remote Network Time Protocol (NTP) server. It implements the SNTP client querying time from one remote server and synchronizing the local clock to it. It is more lightweight as it cannot as an NTP server for other machines.
Configure Systemd Timesyncd on Linux
Set the timezone to your region with the following command
sudo timedatectl set-timezone Africa/Nairobi
You can get a list of the available time zones with the following command.
timedatectl list-timezones | column
To list down the timezones in a particular region say, Africa, use the following command.
timedatectl list-timezones | grep Africa
The service is already available with systemd. Start and enable it with the following command.
sudo systemctl enable systemd-timesyncd.service
Check for the status of the service.
sudo systemctl status systemd-timesyncd.service
When the service starts. It reads from the configuration file located at /etc/systemd/timesyncd.conf. Edit the file to add time servers by listing their hostname or IP separated by a space.
Different options are provided to edit the configuration file.
- NTP represents a space-separated list of NTP server host names or IP addresses.
- FallbackNTP is a space-separated list of NTP server host names or IP addresses to be used as the fallback NTP servers.
- RootDistanceMaxSec is the maximum acceptable root distance.
- PollIntervalMinSec is the minimum poll interval for NTP messages.
- PollIntervalMaxSec is the maximum poll interval for NTP messages.
- ConnectionRetrySec specifies the minimum delay before subsequent attempts to contact a new NTP server are made.
- SaveIntervalSec is the interval at which the current time is periodically saved to disk, in the absence of any recent synchronization from an NTP server.
Edit the file to add time servers by listing their hostname or IP separated by a space.
sudo vim /etc/systemd/timesyncd.conf
So a sample configuration file would look like below. Uncomment the relevant lines.
[Time]
NTP=192.168.200.43 192.168.200.47
Save and exit the file and restart the service to apply changes.
sudo systemctl restart systemd-timesyncd.service
To verify your configuration:
$ timedatectl show-timesync --all
LinkNTPServers=
SystemNTPServers=192.168.200.43 192.168.200.47
FallbackNTPServers=0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org
ServerName=192.168.200.43
ServerAddress=192.168.200.43
RootDistanceMaxUSec=5s
PollIntervalMinUSec=32s
PollIntervalMaxUSec=34min 8s
PollIntervalUSec=32s
Frequency=0
To enable and start it, simply run:
sudo timedatectl set-ntp true
To check the service status.
$ timedatectl status
Local time: Tue 2025-01-28 15:35:17 EAT
Universal time: Tue 2025-01-28 12:35:17 UTC
RTC time: Tue 2025-01-28 12:35:17
Time zone: Africa/Nairobi (EAT, +0300)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
Conclusion
In this guide, we have seen how to configure systemd timesyncd on Debian and RHEL-based Linux systems. Synchronizing time is important for systems as time depends on a lot of services and operations. It may affect the order or sequence of events as isolated computers connected to a network run at the correct time.
Similar articles: