ntpq のインタラクティブモード

日頃は ntpq -p とかで済ませてますが、インタラクティブモードに入ってデバッグレベルを上げるとトラブルシュートに役に立つこともあるかも?

インタラクティブモードに入る

オプションを付けずに ntpq します。

# ntpq
ntpq>

使えそうなコマンドを探す

? でコマンド一覧が出ますね。

ntpq> ?
ntpq commands:
:config          drefid           mreadlist        readvar
addvars          exit             mreadvar         reslist
apeers           help             mrl              rl
associations     host             mrulist          rmvars
authenticate     hostnames        mrv              rv
authinfo         ifstats          ntpversion       saveconfig
cl               iostats          opeers           showvars
clearvars        kerninfo         passociations    sysinfo
clocklist        keyid            passwd           sysstats
clockvar         keytype          peers            timeout
config-from-file lassociations    poll             timerstats
cooked           lopeers          pstats           version
cv               lpassociations   quit             writelist
debug            lpeers           raw              writevar
delay            monstats         readlist

コマンドの使い方を調べる

? <コマンド> でヘルプが出るみたいです。

ntpq> ? debug
function: set/change debugging level
usage: debug [ no|more|less ]

ntpq -p 相当のコマンドを投げる

peers を投げると ntpq -p と同じ出力が得られるみたいです。

ntpq> peers
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*ntp-a3.nict.go. .NICT.           1 u   88  128  377    8.454    0.079   0.879
+ntp2.jst.mfeed. 133.243.236.17   2 u   42  128  377   10.440   -1.667   0.741
+133.40.41.136   133.40.41.133    2 u   22  128  377   20.110   -1.020   0.656

デバッグレベルを上げる

debug more で1段階ずつ上がり、degug less で1段階ずつ下がるみたいです。

ntpq> debug more
debug level set to 1
ntpq> peers
1 packets reassembled into response
[45029] [45028] [45027]
3 associations total
::1 reversed to localhost
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
2 packets reassembled into response
133.243.238.244 reversed to ntp-a3.nict.go.jp
*ntp-a3.nict.go. .NICT.           1 u    4  128  377    8.454    0.079   0.959
2 packets reassembled into response
210.173.160.57 reversed to ntp2.jst.mfeed.ad.jp
+ntp2.jst.mfeed. 133.243.236.17   2 u   89  128  377   10.440   -1.667   0.741
2 packets reassembled into response
+133.40.41.136   133.40.41.133    2 u   69  128  377   20.110   -1.020   0.656

もう1段あげる。

ntpq> debug more
debug level set to 2
ntpq> peers
Got packet, size = 24
Packet okay
1 packets reassembled into response
[45029] [45028] [45027]
3 associations total
::1 reversed to localhost
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
Got packet, size = 480
Packet okay
Got packet, size = 80
Packet okay
2 packets reassembled into response
133.243.238.244 reversed to ntp-a3.nict.go.jp
*ntp-a3.nict.go. .NICT.           1 u   39  128  377    8.454    0.079   0.959
Got packet, size = 480
Packet okay
Got packet, size = 104
Packet okay
2 packets reassembled into response
210.173.160.57 reversed to ntp2.jst.mfeed.ad.jp
+ntp2.jst.mfeed. 133.243.236.17   2 u  124  128  377   10.440   -1.667   0.741
Got packet, size = 480
Packet okay
Got packet, size = 100
Packet okay
2 packets reassembled into response
+133.40.41.136   133.40.41.133    2 u  104  128  377   20.110   -1.020   0.656

おもしろいのでもっとデバッグレベルを上げてみますw

tpq> debug more
debug level set to 3
ntpq> debug more
debug level set to 4
ntpq> debug more
debug level set to 5
ntpq> peers
Sending 12 octets
Request packet:
16 01 00 0d 00 00 00 00 00 00 00 00             ............
Response packet:
16 81 00 0d 06 15 00 00 00 00 00 0c af e5 94 24 ...............$
af e4 94 24 af e3 96 4d                         ...$...M
Got packet, size = 24
Packet okay
1 packets reassembled into response
[45029] [45028] [45027]
3 associations total
::1 reversed to localhost
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
Sending 12 octets
Request packet:
16 02 00 0e 00 00 af e3 00 00 00 00             ............
Response packet:
16 a2 00 0e 96 4d af e3 00 00 01 d4 73 72 63 61 .....M......srca
64 72 3d 31 33 33 2e 32 34 33 2e 32 33 38 2e 32 dr=133.243.238.2
34 34 2c 20 73 72 63 70 6f 72 74 3d 31 32 33 2c 44, srcport=123,
20 64 73 74 61 64 72 3d 31 37 32 2e 32 32 2e 31  dstadr=172.22.1
36 2e 38 2c 20 64 73 74 70 6f 72 74 3d 31 32 33 6.8, dstport=123
2c 0d 0a 6c 65 61 70 3d 30 2c 20 73 74 72 61 74 ,..leap=0, strat
75 6d 3d 31 2c 20 70 72 65 63 69 73 69 6f 6e 3d um=1, precision=
2d 32 30 2c 20 72 6f 6f 74 64 65 6c 61 79 3d 30 -20, rootdelay=0
2e 30 30 30 2c 20 72 6f 6f 74 64 69 73 70 3d 30 .000, rootdisp=0
2e 30 30 30 2c 0d 0a 72 65 66 69 64 3d 4e 49 43 .000,..refid=NIC
54 2c 20 72 65 66 74 69 6d 65 3d 30 78 64 63 39 T, reftime=0xdc9
32 65 33 35 33 2e 30 30 30 30 30 30 30 30 2c 20 2e353.00000000,
72 65 63 3d 30 78 64 63 39 32 65 33 35 33 2e 62 rec=0xdc92e353.b
39 61 36 61 33 34 33 2c 0d 0a 72 65 61 63 68 3d 9a6a343,..reach=
30 78 66 66 2c 20 75 6e 72 65 61 63 68 3d 30 2c 0xff, unreach=0,
20 68 6d 6f 64 65 3d 33 2c 20 70 6d 6f 64 65 3d  hmode=3, pmode=
34 2c 20 68 70 6f 6c 6c 3d 37 2c 20 70 70 6f 6c 4, hpoll=7, ppol
6c 3d 37 2c 20 68 65 61 64 77 61 79 3d 34 32 2c l=7, headway=42,
0d 0a 66 6c 61 73 68 3d 30 78 30 2c 20 6b 65 79 ..flash=0x0, key
69 64 3d 30 2c 20 6f 66 66 73 65 74 3d 30 2e 31 id=0, offset=0.1
39 36 2c 20 64 65 6c 61 79 3d 38 2e 32 35 37 2c 96, delay=8.257,
20 64 69 73 70 65 72 73 69 6f 6e 3d 33 2e 34 39  dispersion=3.49
34 2c 0d 0a 6a 69 74 74 65 72 3d 30 2e 38 32 32 4,..jitter=0.822
2c 20 78 6c 65 61 76 65 3d 30 2e 30 32 35 2c 0d , xleave=0.025,.
0a 66 69 6c 74 64 65 6c 61 79 3d 20 38 2e 32 36 .filtdelay= 8.26
20 31 30 2e 34 36 20 38 2e 34 35 20 31 30 2e 37  10.46 8.45 10.7
31 20 38 2e 39 30 20 31 30 2e 31 35 20 31 30 2e 1 8.90 10.15 10.
33 34 20 38 2e 39 30 2c 0d 0a 66 69 6c 74 6f 66 34 8.90,..filtof
66 73 65 74 3d 20 30 2e 32 30 20 31 2e 31 36 20 fset= 0.20 1.16
30 2e 30 38 20 31 2e 33 30 20 30 2e 34 34 20 31 0.08 1.30 0.44 1
Got packet, size = 480
Packet okay
Response packet:
16 82 00 0e 96 4d af e3 01 d4 00 45 2e 32 39 20 .....M.....E.29
31 2e 31 36 20 30 2e 38 31 2c 0d 0a 66 69 6c 74 1.16 0.81,..filt
64 69 73 70 3d 20 30 2e 30 30 20 32 2e 30 33 20 disp= 0.00 2.03
33 2e 39 39 20 35 2e 39 37 20 37 2e 39 34 20 39 3.99 5.97 7.94 9
2e 38 39 20 31 30 2e 38 36 20 31 31 2e 38 35 0d .89 10.86 11.85.
0a 00 00 00                                     ....
Got packet, size = 84
Packet okay
2 packets reassembled into response
133.243.238.244 reversed to ntp-a3.nict.go.jp
*ntp-a3.nict.go. .NICT.           1 u   21  128  377    8.257    0.196   0.822

~以下略~

……やりすぎ注意。

インタラクティブモードを抜ける

exitquit も通るみたいですね。

ntpq> quit
#
https://manimani.cc/lib/plugins/linkback/exe/trackback.php/wiki:linux:ntpq_interactive_mode