Difference between revisions of "NTP"
Line 1: | Line 1: | ||
− | [[NTP]] is a [[Protocol]] for [[Strategy For::Synchronization|synchronizing]] clocks on computers. Used locally over a quiet network, it can synchronize clocks within dozens of microseconds | + | [[NTP]] is a [[Protocol]] for [[Strategy For::Synchronization|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 <code>timedatectl</code>. To see the general settings, use <code>timedatectl status</code> | ||
+ | |||
+ | <pre> | ||
+ | >>> 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 | ||
+ | </pre> | ||
== Setup Local Synchronization == | == Setup Local Synchronization == | ||
+ | === Switch to Chrony === | ||
+ | |||
+ | Since systemd-timesyncd doesn't include an NTP server, we need to disable it and switch to Chrony | ||
+ | |||
+ | <pre> | ||
+ | sudo timedatectl set-ntp off | ||
+ | sudo apt install chrony -y | ||
+ | </pre> | ||
+ | |||
+ | === 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 <code>/etc/chrony/chrony.conf</code> file such that it includes these lines: | ||
+ | |||
+ | <pre> | ||
+ | local stratum 10 | ||
+ | allow 192.168.0 | ||
+ | makestep 0.001 3 | ||
+ | </pre> | ||
+ | |||
+ | Note that the <code>allow</code> 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 <code>makestep</code> 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 <code>local</code> 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 | ||
+ | |||
+ | <pre> | ||
+ | sudo systemctl restart chronyd | ||
+ | </pre> | ||
+ | |||
+ | And see the [https://chrony.tuxfamily.org/faq.html#_how_do_i_make_an_ntp_server 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 == | == References == | ||
Line 11: | Line 59: | ||
* https://www.eecis.udel.edu/~mills/ntp.html - David Mill's big collection of NTP benchmarks and information | * https://www.eecis.udel.edu/~mills/ntp.html - David Mill's big collection of NTP benchmarks and information | ||
* https://unix.stackexchange.com/a/178023/487659 - an elusive answer on local sync | * https://unix.stackexchange.com/a/178023/487659 - an elusive answer on local sync | ||
+ | * https://unix.stackexchange.com/questions/305643/ntpd-vs-systemd-timesyncd-how-to-achieve-reliable-ntp-syncing - comparison of ntpd and systemd-timesyncd | ||
+ | * https://www.linuxtechi.com/sync-time-in-linux-server-using-chrony/ - basic chrony usage information | ||
+ | |||
+ | === Docs === | ||
+ | |||
+ | * [https://chrony.tuxfamily.org/ Chrony Homepage] | ||
+ | * [https://chrony.tuxfamily.org/doc/4.2/chrony.conf.html Chrony Configuration] | ||
+ | |||
+ | == See Also == | ||
+ | |||
+ | * [[Localization]] | ||
[[Category:Software]] | [[Category:Software]] | ||
[[Has Completion Status::stub]] | [[Has Completion Status::stub]] | ||
[[Strategy For::Synchronization]] | [[Strategy For::Synchronization]] |
Revision as of 01:02, 30 April 2022
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
- https://en.wikipedia.org/wiki/Network_Time_Protocol
- https://linux.die.net/man/8/ntpd
- https://www.eecis.udel.edu/~mills/ntp.html - David Mill's big collection of NTP benchmarks and information
- https://unix.stackexchange.com/a/178023/487659 - an elusive answer on local sync
- https://unix.stackexchange.com/questions/305643/ntpd-vs-systemd-timesyncd-how-to-achieve-reliable-ntp-syncing - comparison of ntpd and systemd-timesyncd
- https://www.linuxtechi.com/sync-time-in-linux-server-using-chrony/ - basic chrony usage information
Docs
See Also
stub Synchronization