SkillPilotAI

Time sync: w32tm, chronyc, timedatectl, ntpdate, ntpq, ntpdig, sntp (1/2)

Part 1 of the time sync tools: the Windows w32tm command (query, config, resync, monitor, stripchart) and the Linux chronyc command for the chrony daemon (sources, tracking, NTP sources, server and monitoring access), with a real chrony server and client lab.

267.1 Why is it used?

  • If a server clock is more than 5 minutes off, Kerberos logins fail and TLS certificates look wrong.
  • w32tm checks and configures the Windows Time service (W32Time); chronyc checks and controls chronyd on Linux.
  • NTP runs on UDP 123; chronyc talks to chronyd on UDP 323 or a local socket.

267.2 How it works

NTP exchange in the lab
  1. 1.n267-client (192.168.67.20) notes T1 and sends a request to UDP 123

  2. 2.n267-timesrv (192.168.67.10) receives it at T2

  3. 3.Server sends the reply at T3

  4. 4.Client receives it at T4 and computes offset and delay

  5. 5.Server serves local stratum 8, so the client becomes stratum 9

Stratum = number of levels from the original source (GPS/atomic = 0)

267.3 w32tm: help, query, config

  • w32tm /? shows help; /register and /unregister add or remove the service with its registry config.
  • w32tm /query /? gives 'The following arguments were unexpected' (real output).
  • /query /source, /configuration, /peers, /status (+ /verbose, /computer:dc01).
  • /config /manualpeerlist + /syncfromflags:MANUAL|DOMHIER|ALL|NO; without /update the service never learns about the change.
  • /reliable:YES matters only on domain controllers; /largephaseoffset sets the spike limit (ms).
PowerShell
w32tm /?w32tm /query /status /verbosew32tm /config /manualpeerlist:"ntpserver.contoso.com clock.adatum.com" /syncfromflags:manual /updatew32tm /config /syncfromflags:domhier /update
Output
C:\> w32tm /query /status /verboseLeap Indicator: 0(no warning)Stratum: 1 (primary reference - syncd by radio clock)Last Successful Sync Time: 5/23/2023 7:51:39 PMSource: VM IC Time Synchronization ProviderPoll Interval: 6 (64s)Phase Offset: -0.0000013sState Machine: 2 (Sync)Last Sync Error: 0 (The command completed successfully.)

267.4 w32tm: resync, monitor, stripchart and others

  • /resync syncs immediately (/nowait, /rediscover, /soft); /monitor checks the offset of all domain DCs.
  • /stripchart is a small NTP client that measures the offset to any server (/samples, /dataonly, /period, /packetinfo).
  • Real run: offset about +5 s to time.windows.com; far below Kerberos' 5 minutes, but production servers aim for milliseconds.
  • /tz, /dumpreg, /debug, /ntte, /ntpte, /leapseconds, /ptp_monitor (PTP on UDP 319/320).
PowerShell
w32tm /stripchart /computer:time.windows.com /samples:3 /dataonly
Output
Tracking time.windows.com [40.81.94.65:123].Collecting 3 samples.The current time is 11/10/2026 1:54:45 AM.01:54:45, +05.0212498s01:54:47, +05.0216481s01:54:49, +05.0220735s
w32tm optionJobSafe on a work PC?
/query /statusStratum, last sync, sourceRead-only (shows domain source)
/config ... /updateChange time source settingsNo, changes config
/resyncSync nowNo, changes the clock
/stripchartMeasure offset to a serverYes, read-only
/tzShow time zoneYes

267.5 Lab: chrony server and client

  • Internal Docker network 192.168.67.0/24 with masquerade off: no packet leaves the lab.
  • No SYS_TIME capability and chronyd -x, so the real clock never changes.
  • timesrv: local stratum 8, allow + cmdallow for the lab subnet; client: server 192.168.67.10 iburst (4 quick requests at startup).
Terminal
# n267-timesrvlocal stratum 8allow 192.168.67.0/24bindcmdaddress 0.0.0.0cmdallow 192.168.67.0/24# n267-clientserver 192.168.67.10 iburst# both: clock control offchronyd -x -f /etc/chrony/chrony.conf

267.6 chronyc options and system clock

OptionMeaning
-n / -NDo not resolve names / print configured names
-cCSV output for scripts
-eEnd every response with a dot
-h host -p 323Which chronyd to talk to, UDP port
-4 / -6, -m, -dAddress family, multiple commands, debug
  • tracking: reference, stratum and system time offset (client: stratum 9, about 2 microseconds fast).
  • makestep steps the clock now; in -x mode it failed and over UDP it gave 501 Not authorised (privileged commands only on the local socket).
  • waitsync waits until the clock is synced.
Terminal
chronyc -h 127.0.0.1 makestepchronyc waitsync 30 0.1 0 1
Output
[client]$ chronyc -h 127.0.0.1 makestep501 Not authorised[client]$ chronyc waitsync 30 0.1 0 1try: 1, refid: 00000000, correction: 0.000000000, skew: 0.000try: 2, refid: C0A8430A, correction: 0.000003041, skew: 1000000.000

267.7 chronyc: sources and NTP sources

  • sources -v legend: ^ = server, * = current best, ? = unusable; Reach is an octal record of the last 8 polls (377 = all 8 answered).
  • sourcestats: frequency error and offset estimate; selectdata: why a source was selected; selectopts/reselect change selection.
  • ntpdata: last measurement in detail; add server/pool/peer and delete change sources at runtime.
  • offline -> source shows ^?; online -> back in burst mode; activity counts online/offline sources.
Terminal
printf 'dns -n\ntimeout 2000\nretries 3\nsources\nquit\n' | chronycchronyc -n sourcestats -vchronyc ntpdata 192.168.67.10
Output
MS Name/IP address         Stratum Poll Reach LastRx Last sample===============================================================================^* 192.168.67.10                 8   6    17     7   -414ns[ -407ns] +/-   43us Name/IP Address            NP  NR  Span  Frequency  Freq Skew  Offset  Std Dev==============================================================================192.168.67.10               4   3     6     -0.000    149.441  +2149ns    12us Remote address  : 192.168.67.10 (C0A8430A)Remote port     : 123Local address   : 192.168.67.20 (C0A84314)Mode            : ServerStratum         : 8Poll interval   : 6 (64 seconds)Offset          : -0.000000147 secondsPeer delay      : 0.000083720 secondsNTP tests       : 111 111 1111Total good RX   : 4

267.8 chronyc: server access, monitoring access, manual and RTC

Two kinds of access on the timesrv
  1. 1.Client asks for time on UDP 123

  2. 2.allow/deny decides NTP access (accheck: 208 allowed / 209 denied)

  3. 3.Client runs chronyc -h 192.168.67.10 on UDP 323

  4. 4.cmdallow decides monitoring access: tracking works

  5. 5.Remote makestep -> 501 Not authorised (read-type commands only)

Terminal
chronyc accheck 192.168.67.20; chronyc accheck 192.168.99.5   # on timesrvchronyc smoothingchronyc -h 192.168.67.10 -p 323 tracking                      # from clientchronyc -h 192.168.67.10 makestep
Output
208 Access allowed209 Access denied505 Facility not enabled in daemonReference ID    : 7F7F0101 ()Stratum         : 8501 Not authorised
  • clients lists who asked for time (lab client sent 8 NTP packets); serverstats counts received and dropped packets.
  • Manual input: manual on/off/list/delete/reset and settime; manual list showed n_samples = 0.
  • rtcdata gave 513 RTC driver not running (no RTC in a container); trimrtc, writertc, cyclelogs, dump, rekey, shutdown.
  • keygen 73 SHA1 256 generates an auth key for the chrony keys file.

267.9 Common mistakes

  • Thinking sync means 'set it now': NTP normally slews; use makestep or w32tm /resync only for a large offset.
  • Running w32tm /config without /update.
  • Seeing ^? with Reach 0 and not checking UDP 123 on the firewall and the server's allow rule.
  • Expecting privileged chronyc commands to work remotely: they need the local socket.

267.10 Interview tips

  • Check Linux time sync: chronyc sources (^* selected, Reach 377) then chronyc tracking (system time offset, stratum).
  • On Windows: w32tm /query /status and /stripchart; for a large offset makestep or /resync.
  • ^? + Reach 0 = source unreachable: check UDP 123 and the allow rule.
  • allow = who may get time (UDP 123); cmdallow = who may monitor with chronyc (UDP 323).