有很多实用程序可以用来检查 NTP 是否正常工作。ntpq -p 命令将打印出您系统当前的时间状态。
# ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== *cudns.cit.corne ntp0.usno.navy. 2 u 832 1024 377 43.208 0.361 2.646 LOCAL(0) LOCAL(0) 10 l 13 64 377 0.000 0.000 0.008 |
ntpdc -c loopinfo 将显示系统时间偏差的秒数,基于上次联系远程服务器的时间。
# ntpdc -c loopinfo offset: -0.004479 s frequency: 133.625 ppm poll adjust: 30 watchdog timer: 404 s |
ntpdc -c kerninfo 将显示当前剩余的校正量。
# ntpdc -c kerninfo pll offset: -0.003917 s pll frequency: 133.625 ppm maximum error: 0.391414 s estimated error: 0.003676 s status: 0001 pll pll time constant: 6 precision: 1e-06 s frequency tolerance: 512 ppm pps frequency: 0.000 ppm pps stability: 512.000 ppm pps jitter: 0.0002 s calibration interval: 4 s calibration cycles: 0 jitter exceeded: 0 stability exceeded: 0 calibration errors: 0 |
ntptime 是 ntpdc -c kerninfo 的一个略微不同的版本
# ntptime ntp_gettime() returns code 0 (OK) time c35e2cc7.879ba000 Thu, Nov 13 2003 11:16:07.529, (.529718), maximum error 425206 us, estimated error 3676 us ntp_adjtime() returns code 0 (OK) modes 0x0 (), offset -3854.000 us, frequency 133.625 ppm, interval 4 s, maximum error 425206 us, estimated error 3676 us, status 0x1 (PLL), time constant 6, precision 1.000 us, tolerance 512 ppm, pps frequency 0.000 ppm, stability 512.000 ppm, jitter 200.000 us, intervals 0, jitter exceeded 0, stability exceeded 0, errors 0. |
另一种查看 NTP 工作情况的方法是使用 ntpdate -d 命令。这将联系 NTP 服务器并确定时间差异,但不会更改您的系统时间。
# ntpdate -d 132.236.56.250 13 Nov 14:43:17 ntpdate[29631]: ntpdate 4.1.1c-rc1@1.836 Thu Feb 13 12:17:20 EST 2003 (1) transmit(132.236.56.250) receive(132.236.56.250) transmit(132.236.56.250) receive(132.236.56.250) transmit(132.236.56.250) receive(132.236.56.250) transmit(132.236.56.250) receive(132.236.56.250) transmit(132.236.56.250) server 132.236.56.250, port 123 stratum 2, precision -17, leap 00, trust 000 refid [192.5.41.209], delay 0.06372, dispersion 0.00044 transmitted 4, in filter 4 reference time: c35e5998.4a46cfc8 Thu, Nov 13 2003 14:27:20.290 originate timestamp: c35e5d55.d69a6f82 Thu, Nov 13 2003 14:43:17.838 transmit timestamp: c35e5d55.d16fc9bc Thu, Nov 13 2003 14:43:17.818 filter delay: 0.06522 0.06372 0.06442 0.06442 0.00000 0.00000 0.00000 0.00000 filter offset: 0.000036 0.001020 0.000527 0.000684 0.000000 0.000000 0.000000 0.000000 delay 0.06372, dispersion 0.00044 offset 0.001020 13 Nov 14:43:17 ntpdate[29631]: adjust time server 132.236.56.250 offset 0.001020 sec |
如果您想实际观看系统同步过程,可以使用 ntptrace。
# ntptrace 132.236.56.250 cudns.cit.cornell.edu: stratum 2, offset -0.003278, synch distance 0.02779 truetime.ntp.com: stratum 1, offset -0.014363, synch distance 0.00000, refid 'ACTS' |
如果您需要立即同步系统时间,可以使用 ntpdate remote-servername 强制同步。无需等待!
# ntpdate 132.236.56.250 13 Nov 14:56:28 ntpdate[29676]: adjust time server 132.236.56.250 offset -0.003151 sec |