S6-SNTPCLOCK(8)
π s6-sntpclock(8) β small SNTP client
okay so bestie, this is a page from the System Manager's Manual and it's about s6-sntpclock, a lil SNTP client that is genuinely iconic. let's get into it π«Ά
β¨ SYNOPSIS β¨
s6-sntpclock [-f] [-v verbosity] [-r roundtrips] [-t triptimeout]
[-h throttle] [-T totaltimeout] [-e errmax] [-p port]
ipaddress
πΈ DESCRIPTION πΈ
so s6-sntpclock connects to an SNTP or NTP server, figures out roughly how far off your local clock is from the absolute time that server says it is, and then prints that discrepancy to stdout. no cap. that's the whole job π
it does this by exchanging SNTPv4 messages with an SNTP server that's listening on ipaddress, UDP port 123. and ipaddress can be IPv4 or IPv6, we love a flexible queen β¨
it computes the mean difference between the absolute time given by the system clock and the one given by the server.
then it prints the difference to stdout in a format that s6-clockadd(8) and s6-clockview(8) understand, and exits 0. slay.
π the NTP protocol has infelicities (real)
there are a LOT of infelicities in the NTP protocol (and SNTP is a subset of it, so it inherits all of them, rip). the biggest offender is probably that NTP literally cannot handle a time difference of more than 34 years: if the time given by the NTP server is more than 34 years away from the time given by the system clock, then NTP just cannot compute. like, it gives up. π
this is a whole problem for CMOS-less systems, where the system clock is initialized to the Unix Epoch. the solution is to first manually initialize the system clock with a program such as date(1) or s6-clock[1] to a closer time (such as 2013-01-01, which will be good up to 2047), and then contact the NTP server. pre-game your clock, basically π
a less obvious problem with NTP is that it works with UTC time, which means it gives inaccurate results when close to a leap second, up to one second off when used during a leap second, and this is bound to the use of UTC: there is nothing you can do about it. π the only solution to get reliable results even around a leap second is to use linear time such as TAI; the s6-taiclock(8) and s6-taiclockd(8) programs provide tools to do so.
π§ a word on ntpd
from a Unix software engineering standpoint, the well-known ntpd[2] program is an eldritch abomination. i said what i said. the main reason for it is that, just like its lovely cousin BIND[3], ntpd performs a lot of different tasks in a unique process, instead of separating what could, and should, be separated. this is confusing for both the programmer and the software user. the term "NTP server" means two different things:
- A program that serves NTP time to the Internet and can be accessed by NTP clients.
- A daemon, i.e. a long-lived process, that runs on a machine and handles NTP-related stuff such as keeping the system clock accurate.
the former is the real meaning of "NTP server". the latter is a common usage for the term, but comes from a misuse of "server" to mean "daemon". iykyk β¨
ntpd does not help clear the misunderstanding since it does both. it acts as an NTP server, and as an NTP client getting its time from lower-strata NTP servers, and as a local system clock management daemon. those are already 3 separate tasks, bestie. three. π«
local system clock management itself involves several duties:
- there's the regular setting of the system clock, which can be done with a loop over a simple program such as
s6-clockadd(8). - there's also control of the clock skew, which s6-networking does not provide because there is no portable interface for that; there is such a tool in the
clockspeed[4] package.
ntpd includes a complete cryptographic key management system for the crypto part of NTP. but NTP is not the only protocol that uses cryptography and asymmetric keys; managing keys in a separate tool, not in the NTP daemon itself, would be simpler and smarter. π
ntpd provides monitoring support for client and server timekeeping performance. this would be best implemented as a separate specific log analyzing tool.
and of course, no matter how many layers of complexity you add onto ntpd, it will never be able to give accurate time in the vicinity of a leap second, since the very protocol is flawed by design β but the ntpd authors cannot be blamed for that. also, the ntpd writers, not the designers, should be praised: the history of ntpd security flaws is remarkably small, which is quite a feat for a huge monolithic root daemon. genuinely impressive, we stan π
network synchronization is important, NTP has its perks and valid use cases, and its existence is a good thing. however, the author wishes that the main NTP implementation weren't written as a big fat clumsy process running as root. s6-sntpclock together with s6-clockadd(8) aims to provide a small, simple tool to keep system clocks β especially in embedded devices β synchronized to a NTP server. periodt. π
π OPTIONS π
-fβ Force. normally,s6-sntpclockexits111if it cannot compute a time with a smaller uncertainty thanerrmax. if this option is set, it will output a time difference and exit0even if the error is too big. (chaotic but valid π)-vverbosity β Be more or less verbose. by default,verbosityis1.0means only print fatal error messages;3means trace every exchange with the server. pick your vibe.-rroundtrips β Performroundtripsexchanges with the server. by default,roundtripsis10. a lower value yields a higher time uncertainty; a higher value puts more load on the server. balance, bestie βοΈ-ttriptimeout β If an SNTP exchange with the server takes more thantriptimeoutmilliseconds, abort this exchange and move on to the next one. by default,triptimeoutis2000.-hthrottle β Waitthrottlemilliseconds between exchanges with the server. a lower value gets the final result earlier, but exerts more load on the server. a higher value puts a lighter load on the server, but delays the computation. by default,throttleis0. it is recommended to set it to a reasonable nonzero value when increasingroundtrips. be polite to the server fr fr π₯Ί-Ttotaltimeout β If the whole operation takes more thantotaltimeoutmilliseconds, abort and exit1. by default,totaltimeoutis10000.-eerrmax β Accept a maximum time uncertainty oferrmaxmilliseconds. by default,errmaxis100.-pport β Contact a server on portport. by default,portis123.
π¦ SEE ALSO π¦
s6-clockadd(8), s6-clockview(8), s6-taiclock(8), s6-taiclockd(8)
[1] https://skarnet.org/software/s6-portable-utils/s6-clock.html
[2] https://doc.ntp.org/4.1.0/ntpd.htm
[3] https://www.isc.org/downloads/bind/
[4] https://cr.yp.to/clockspeed.html
this man page is ported from the authoritative documentation at: https://skarnet.org/software/s6-networking/s6-sntpclock.html
π AUTHORS π
Laurent Bercot Alexis <flexibeast@gmail.com> (man page port)
okay that's the whole page bestie, go sync some clocks π
and that's a wrap, mwah π β this one shipped on the Debian side of things, dated September 29, 2021, and it's the s6-sntpclock(8) page from the System Manager's Manual πβ¨
π¦ where this page comes from
- nixpkgs unstable: s6-networking 2.8.0.1
- nixpkgs unstable: s6-networking-man-pages 2.7.2.1.4
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms