Solved How to verify ntpd synchronization?

I'm trying to use ntpd(8) to set the correct time on a machine.

I have setup the service by adding these two lines in /etc/rc.conf:
Code:
ntpd_enable="YES"
ntpd_sync_on_start="YES"
Then i ran service ntpd start to start the service.

The thing I can't figure out is how to see that the time has been successfully synchronized with an NTP server.

I have checked the log file /var/log/messages but the closest thing I can find there is the ntpd(8) daemon starting successfully; not that it has synchronized its time.

I also tried using the ntpq(8) program.
Code:
mschultz@rpi3-bsd:~ % ntpq -c apeers
     remote       refid   assid  st t when poll reach   delay   offset  jitter
==============================================================================
*10.1.23.5        c23ac814 50747   2 u   49   64  377    0.596   -0.390   0.070

Code:
mschultz@rpi3-bsd:~ % ntpq -c "pstats 50747"
associd=50747 status=961a conf, reach, sel_sys.peer, 1 event, sys_peer,
remote host:           10.1.23.5:123
local address:         10.1.23.90:123
time last received:    24
time until next send:  42
reachability change:   6008
packets sent:          127
packets received:      124
bad authentication:    0
bogus origin:          0
duplicate:             0
bad dispersion:        0
bad reference time:    0
candidate order:       6

What I want is a command or log file saying something like:
Local time successfully set to 'Sat Apr 23 10:44:21 CEST 2022' by NTP server 10.1.23.5. Time corrected by -0.390 seconds. (just as an example)

Is there such a command? Just so it's clear that the time has been updated.
 
You could try:
Code:
ntpq -p
ntpq -crv
From what I can see the ntpq -crv only shows the current system time.

If I change the system time with date 1644 (which sets the time to 16:44) and then issue the command ntpq -c rv, the output is instantly reflected in that output, suggesting that this is not the synchronized time from the NTP server.
Code:
root@rpi3-bsd:~ # ntpq -c "rv 0 clock"
clock=e60e9156.7facb931  Sat, Apr 23 2022 16:53:10.498
root@rpi3-bsd:~ # date 1644
Sat Apr 23 16:44:00 CEST 2022
root@rpi3-bsd:~ # ntpq -c "rv 0 clock"
clock=e60e8f32.4b095f87  Sat, Apr 23 2022 16:44:00.434
I have added 0 clock to the command to filter out the time from the verbose output.
 
What I want is a command or log file saying something like:
Local time successfully set to 'Sat Apr 23 10:44:21 CEST 2022' by NTP server 10.1.23.5. Time corrected by -0.390 seconds. (just as an example)
You are assuming that ntpd(8) always changes the time in discrete steps. This is not how it works. Under normal conditions, Ntpd will slew the time gradually using the adjtime(2) C library function. This will actually slow down or speed up the system clock very slightly until it catches up with what Ntpd has determined should be the correct time.

If the time offset exceeds the step threshold, which is 128 ms by default, Ntpd will step the time using settimeofday(2). It may log something if and when that happens. I've never witnessed it happening so I don't know.

See also ntpdate(8).
 
It's getting a bit more clear to me how ntpd(8) works, but I still have no idea how to confirm that the NTP clock synchronization is working.

I have been looking into the ntpdate(8) prior to using ntpd(8) but since the manual says that it is about to be removed from the distribution I thought it would be better to learn ntpd(8) instead.

Maybe it's safe to assume synchronization is working if I have successful peers connected?
Code:
root@rpi3-bsd:~ # ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*10.1.23.5       194.58.200.20    2 u   38   64  377    0.871   +0.325   0.074
 
I have used ntptime(8) without any options to verify that the clock is synchronized.

It displays ”OK” status with timing information when ntpd is working.
 
  • Like
Reactions: mer
ntpq -pn will show you the list of peers, the one you are synchronized with will have an asterisk in the leftmost column.
If you are not synchronized, there will be no peer with an asterisk.

If you have sync, then a simple "date" command tells you what your system thinks the time is.

To the best of my knowledge I've not seen a log like you are asking for. Not saying it doesn't exist, but I've not seen it.
 
Back
Top