Share your love
Set Up Time Synchronization on Debian 11
In this section of Linux Tutorials on the orcacore website, we want to teach you how to Set Up Time Synchronization on Debian 11 with NTP and timesyncd component.
When Linux machines are supplied with an operating system, the Network Time Protocol (NTP) service is not running. After moving the newly supplied Linux machines to a network with access to the NTP server, you must synchronize the time on the machines to network time.
How To Set Up Time Synchronization on Debian 11
To set up time synchronization you need to log in to your server as a non-root user with sudo privileges. For this, you can check our article about the Initial Server Setup with Debian 11.
When you are done, follow the steps below.
Check the Clock and the Time Zone on Debian 11
The most basic command for finding out the time on your server is “date”. Any user can run the following command to check the date and time on Debian 11:
date
Output Sat 06 Nov 2021 07:36:50 AM EDT
Note: Most often your server will default to the UTC time zone. UTC is Coordinated Universal Time, the time at zero degrees longitude. Also, using Universal Time reduces confusion when your infrastructure spans multiple time zones.
If you have requirements and you need to change the time zone on Debian 11, you can use the “timedatectl” command.
List Available Time Zones on Debian 11
First, list the available time zones on Debian 11 with the following command:
timedatectl list-timezones
In your output, you will see a list of available time zones on Debian 11.
Set Time Zone on Debian 11
When you find the correct time zone, use the following command to set the time zone:
sudo timedatectl set-timezone America/New_York
Remember to replace the time zone you have found in the list.
Now that you know how to check the time zone and clock on Debian 11, let’s install and start NTP.
Install NTP on Debian 11
To install NTP on your server, you can use the following command:
sudo apt install ntp
Then, restart your service with the following command:
systemctl restart ntp
Check NTP Status on Debian
Verify that the service is active and running on your server:
systemctl status ntp
in your output you will see:
Output ntp.service - Network Time Service Loaded: loaded (/lib/systemd/system/ntp.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2021-11-06 05:28:26 EDT; 2h 23min ago Docs: man:ntpd(8) Process: 5715 ExecStart=/usr/lib/ntp/ntp-systemd-wrapper (code=exited, status=0/SUCCESS) Main PID: 5721 (ntpd) Tasks: 2 (limit: 2340) Memory: 960.0K CPU: 1.022s CGroup: /system.slice/ntp.service └─5721 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 107:113
To get more information about the status of ntpd, you can use the following command:
ntpq -p
Your output should similar to this:
Output
remote refid st t when poll reach delay offset jitter
==============================================================================
0.debian.pool.n .POOL. 16 p - 64 0 0.000 +0.000 0.000
1.debian.pool.n .POOL. 16 p - 64 0 0.000 +0.000 0.000
2.debian.pool.n .POOL. 16 p - 64 0 0.000 +0.000 0.000
3.debian.pool.n .POOL. 16 p - 64 0 0.000 +0.000 0.000
-c-68-54-100-49. 128.10.252.6 2 u 470 1024 377 160.901 +2.020 1.420
-mail5.nosuchhos 131.130.251.107 2 u 105 512 377 28.053 +0.799 1.259
*n1.taur.dk .PPS0. 1 u 470 512 377 55.076 +1.084 1.554
+185.83.169.27 .GPS. 1 u 491 512 377 58.452 +1.065 0.150
+server01.coloce 245.189.13.59 2 u 133 512 377 32.332 +1.240 1.677
-ip-79-111-152-5 .PSM0. 1 u 397 1024 377 79.103 +0.005 6.059
Your output will be different but you should see the default Debian pool servers plus a few others.
Replace ntpd with systemd-timesyncd on Debian 11
You can use systemd’s built-in timesyncd component to replace the ntpd. timesyncd is more integrated with systemd than ntpd.
It doesn’t support running as a time server, and it is slightly less sophisticated in the techniques it uses to keep your Debian 11 times in sync.
If you are running complex real-time distributed systems, you may want to stay with ntpd.
First, you should uninstall ntpd with the following command to use timesyncd:
sudo apt purge ntp
Start timesyncd service on Debian 11
Then, start the timesyncd with the following command:
sudo systemctl start systemd-timesyncd
Verify that service is active and running:
sudo systemctl status systemd-timesyncd
Output systemd-timesyncd.service - Network Time Synchronization Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; ve> Active: active (running) since Sat 2021-11-06 08:17:54 EDT; 1min 33s ago Docs: man:systemd-timesyncd.service(8) Main PID: 6700 (systemd-timesyn) Status: "Initial synchronization to time server 91.216.151.61:123 (0.debia> Tasks: 2 (limit: 2340) Memory: 996.0K CPU: 72ms CGroup: /system.slice/systemd-timesyncd.service └─6700 /lib/systemd/systemd-timesyncd
Now you can use the timedatectl command to print out systemd’s current understanding of the time on Debian 11:
timedatectl
Output Local time: Sat 2021-11-06 08:20:15 EDT Universal time: Sat 2021-11-06 12:20:15 UTC RTC time: Sat 2021-11-06 12:20:16 Time zone: US/Eastern (EDT, -0400) System clock synchronized: yes NTP service: active RTC in local TZ: no
“System clock synchronized: yes” means that the time on Debian 11 has been successfully synced, and the “NTP service: active” means that the timesyncd is enabled and running.
Conclusion
At this point, you learn to view the system time, change time zones, work with ntpd and switch to timesyncd on Debian 11.
Hope you enjoy it.
May this article about the Setup and configure NTP Server and Client on Debian 11 be useful for you.
What is the difference between systemd-Timesyncd and ntpd?
ntpd and chrony can also function as LAN time servers, while systemd-timesyncd is a lightweight client with no server functions