Accurate time keeping is very important task. One example where it is critical is using FT8 digital mode from WSJT-X software for ham radio operators. FT8 works in 15 seconds transmit/receive windows. To have good experience with FT8 you really need accurate time. So what time is it?
$ date Mon Jun 18 17:51:43 CEST 2018
That’s basic but not good enough. Lets dig a bit deeper.
First off default Ubuntu settings are pretty good. So no need to change them unless you need to. Ubuntu 18.04 uses systemd as its core to run system services. One of these services is time keeping service. You can check your time keeping setup and status with timedatectl.
$ timedatectl Local time: Mon 2018-06-18 17:27:59 CEST Universal time: Mon 2018-06-18 15:27:59 UTC RTC time: Mon 2018-06-18 15:27:59 Time zone: Europe/Warsaw (CEST, +0200) System clock synchronized: yes systemd-timesyncd.service active: yes RTC in local TZ: no
As you see it says system clock is synchronized and time synchronization is done by systemd-timesyncd service. If for some reason systemd-timesyncd.service is not active you can enable it with:
$ timedatectl set-ntp on
By default systemd-timesyncd service uses ntp.ubuntu.com NTP server as its time source. Lets see what its status is:
$ 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 Mon 2018-06-04 20:14:24 CEST; 1 weeks 6 days ago Docs: man:systemd-timesyncd.service(8) Main PID: 854 (systemd-timesyn) Status: "Synchronized to time server 126.96.36.199:123 (ntp.ubuntu.com)." Tasks: 2 (limit: 4915) CGroup: /system.slice/systemd-timesyncd.service └─854 /lib/systemd/systemd-timesyncd Jun 04 20:14:23 box systemd: Starting Network Time Synchronization... Jun 04 20:14:24 box systemd: Started Network Time Synchronization. Jun 04 20:14:54 box systemd-timesyncd: Synchronized to time server 188.8.131.52:123 (ntp.ubuntu.com).
It says it is “Synchronized to time server…” but what drift do we really have? To check this we have to use ntpdate for example.
$ sudo apt install ntpdate
Now query the NTP server and compare it to our clock:
$ ntpdate -q ntp.ubuntu.com server 184.108.40.206, stratum 2, offset 0.002062, delay 0.07565 server 220.127.116.11, stratum 2, offset 0.002592, delay 0.07542 server 18.104.22.168, stratum 2, offset 0.002430, delay 0.07707 server 22.214.171.124, stratum 2, offset 0.002217, delay 0.14827 18 Jun 17:26:20 ntpdate: adjust time server 126.96.36.199 offset 0.002592 sec
2 ms offset. Not bad!
In any case if you want to FORCE synchronization to NTP server all you need to do is restart systemd-timesyncd service:
$ sudo systemctl restart systemd-timesyncd
And see what happens in its logs:
$ journalctl -fu systemd-timesyncd Jun 18 17:56:28 box systemd: Stopping Network Time Synchronization... Jun 18 17:56:28 box systemd: Stopped Network Time Synchronization. Jun 18 17:56:28 box systemd: Starting Network Time Synchronization... Jun 18 17:56:28 box systemd: Started Network Time Synchronization. Jun 18 17:56:28 box systemd-timesyncd: Synchronized to time server 188.8.131.52:123 (ntp.ubuntu.com).
If for any reason you want to change NTP server timesyncd configuration is kept in /etc/systemd/timesyncd.conf. See man timesyncd.conf for more.
$ cat /etc/systemd/timesyncd.conf # This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # # Entries in this file show the compile time defaults. # You can change settings by editing this file. # Defaults can be restored by simply deleting this file. # # See timesyncd.conf(5) for details. [Time] #NTP= #FallbackNTP=ntp.ubuntu.com #RootDistanceMaxSec=5 #PollIntervalMinSec=32 #PollIntervalMaxSec=2048