Share your love
Set Up Time Synchronization on Debian 12 Bookworm – Best Practises
This tutorial intends to teach you to Set Up Time Synchronization on Debian 12 Bookworm with NTP and timesyncd components. When a new Linux distribution is released, the NTP protocol is not running on the server. So you must synchronize the time on the machines to network time.
Now proceed to the following guide steps on the Orcacore website to Set Up Time Synchronization on Debian 12 Bookworm.
Table of Contents
How To Set Up Time Synchronization on Debian 12 Bookworm?
To Set Up Time Synchronization on Debian 12 Bookworm, you must have access to your server as a non-root user with sudo privileges. To do this, you can follow this guide on Initial Server Setup with Debian 12 Bookworm.
Prepare Debian 12 For Time Synchronization
Check the Current Clock and Time Zone on Debian 12:
First of all, you must check your current clock on your server. To do this, you can use the following date command:
sudo date
In your output, you should see something similar to the following output:
Output
Tue Jun 20 07:20:45 AM EDT 2023
Note: Most often your server will default to the UTC zone. Using Universal Time reduces confusion when your infrastructure spans multiple time zones.
List Available Time Zones on Debian 12:
To get all the available time zones, you can use the following timedatectl command:
sudo timedatectl list-timezones
You will get a list of time zones in your output:
Output
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Asmera
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau
...
Set Up Time Zone on Debian 12 Bookworm:
After you find your correct time zone from the above list, you can use the following command to change your time zone instead of set date and time automatically:
sudo timedatectl set-timezone America/New_York
Remember to replace the time zone you have found in the list.
Set Up NTP on Debian 12 Bookworm
At this point, you can use the following command to install Network Time Protocol on Debian 12 (Debian 12 bookworm configure NTP):
sudo apt install ntp -y
Then, restart your service with the following command:
sudo systemctl restart ntp
Check NTP Status on Debian 12:
At this point, you can verify your NTP service is active and running on your server with the following command:
sudo systemctl status ntp
In your output, you will see:
Output
● ntpsec.service - Network Time Service
Loaded: loaded (/lib/systemd/system/ntpsec.service; enabled; preset: enable>
Active: active (running) since Tue 2023-06-20 07:30:42 EDT; 59s ago
Docs: man:ntpd(8)
Process: 12518 ExecStart=/usr/libexec/ntpsec/ntp-systemd-wrapper (code=exite>
Main PID: 12522 (ntpd)
Tasks: 1 (limit: 4653)
Memory: 10.5M
CPU: 151ms
CGroup: /system.slice/ntpsec.service
...
To get more information about the status of ntpd, you can use the following command:
ntpq -p
Your output should be similar to this:
Output
remote refid st t when poll reach delay offset jitter
================================================================================
0.debian.pool.nt .POOL. 16 p - 256 0 0.0000 0.0000 0.0001
1.debian.pool.nt .POOL. 16 p - 256 0 0.0000 0.0000 0.0001
2.debian.pool.nt .POOL. 16 p - 256 0 0.0000 0.0000 0.0001
3.debian.pool.nt .POOL. 16 p - 256 0 0.0000 0.0000 0.0001
-86-126-139-108.s 194.58.203.20 2 u 67 64 3 2.4173 -0.9000 0.2056
#corporate1.bluep 193.204.114.232 2 u 67 64 3 4.4517 -1.6539 0.2341
-time.cloudflare. 10.50.9.9 3 u - 64 7 0.4717 0.1827 0.2574
#109.102.183.146 .PPS. 1 u - 64 7 1.3829 -0.9654 0.2122
...
Note: Your output will be different but you should see the default Debian pool servers plus a few others.
Also, if you have issues with NTP, you can visit this link.
Replace NTP with systemd-timesyncd on Debian 12
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 12 times in sync.
Note: 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
Then, install the systemd-timesyncd on your server with the command below:
sudo apt install systemd-timesyncd -y
Start timesyncd service on Debian 12 Bookworm
Next, start the timesyncd with the following command:
sudo systemctl start systemd-timesyncd
Verify that the timesyncd service is active and running on Debian 12:
sudo systemctl status systemd-timesyncd
Output
● systemd-timesyncd.service - Network Time Synchronization
Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; pre>
Active: active (running) since Tue 2023-06-20 07:38:35 EDT; 1min 1s ago
Docs: man:systemd-timesyncd.service(8)
Main PID: 12666 (systemd-timesyn)
Status: "Contacted time server 86.124.75.41:123 (0.debian.pool.ntp.org)."
Tasks: 2 (limit: 4653)
Memory: 1.3M
CPU: 71ms
CGroup: /system.slice/systemd-timesyncd.service
...
Now you can use the timedatectl command to print out systemd’s current understanding of the time on Debian 12:
timedatectl
Output
Local time: Tue 2023-06-20 07:41:37 EDT
Universal time: Tue 2023-06-20 11:41:37 UTC
RTC time: Tue 2023-06-20 11:41:37
Time zone: America/New_York (EDT, -0400)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
“System clock synchronized: yes” means that the time on Debian 12 has been successfully synced, and the “NTP service: active” means that the timesyncd is enabled and running.
That’s it, you are done with Set Up Time Synchronization on Debian 12 Bookworm.
Conclusion
At this point, you have learned How to Set up Time Synchronization on Debian 12 Bookworm with NTP and timesyncd. It is important every time a Linux machine is supplied to synchronize the time on the machines to network time.
Hope you enjoy it. Also, you may like the following articles:
Run Nginx Docker Container on Debian 12
Install Fathom Analytics on Debian 12