NTP

From Autopilot Wiki
Revision as of 01:02, 30 April 2022 by Jonny (talk | contribs)
Jump to: navigation, search

NTP is a Protocol for synchronizing clocks on computers. Used locally over a quiet network, it can synchronize clocks within dozens of microseconds. It has several different implementations, the default for RaspiOS is timesyncd, but if you want to synchronize clocks locally you will need to use

See Configuration

The default tool for querying and setting time settings is timedatectl. To see the general settings, use timedatectl status

>>> timedatectl status
               Local time: Fri 2022-04-29 17:22:54 PDT
           Universal time: Sat 2022-04-30 00:22:54 UTC
                 RTC time: n/a
                Time zone: America/Los_Angeles (PDT, -0700)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

Setup Local Synchronization

Switch to Chrony

Since systemd-timesyncd doesn't include an NTP server, we need to disable it and switch to Chrony

sudo timedatectl set-ntp off
sudo apt install chrony -y

Configure a Server

The server will continue to synchronize with external servers, but allow clients on the local network to sync with it.

Edit your /etc/chrony/chrony.conf file such that it includes these lines:

local stratum 10
allow 192.168.0
makestep 0.001 3

Note that the allow config specifies our local IP address being underneath 192.168.0.*, adjust this if your local network uses a different IP range. We need to adjust the makestep from its default to make chrony adjust the system clock with a finer grain than 1 second (we use 1ms), but only on the first 3 synchronization cycles so we don't go backwards in time later on. The local configuration allows us to synchronize clients even if we haven't synchronized with external servers for awhile.

Then restart the chrony daemon to make our changes take effect

sudo systemctl restart chronyd

And see the docs

Configure a Client

Do the same process of switching to using chrony described previously, and then configure your client to get its time from the local server.

References

Docs

See Also

stub Synchronization