Initial import from FreeBSD RELENG_4:
[games.git] / usr.sbin / ntp / doc / ntpq.8
1 .\"
2 .\" $FreeBSD: src/usr.sbin/ntp/doc/ntpq.8,v 1.3.2.9 2003/03/11 22:31:30 trhodes Exp $
3 .\"
4 .Dd January 7, 2000
5 .Dt NTPQ 8
6 .Os
7 .Sh NAME
8 .Nm ntpq
9 .Nd standard NTP query program
10 .Sh SYNOPSIS
11 .Nm
12 .Op Fl inp
13 .Op Fl c Ar command
14 .Op Ar host ...
15 .Sh DESCRIPTION
16 The
17 .Nm
18 utility is used to query NTP servers
19 which implement the recommended NTP mode 6 control message format
20 about current state and to request changes in that state.
21 The
22 program may be run either in interactive mode or controlled using
23 command line arguments.
24 Requests to read and write arbitrary
25 variables can be assembled, with raw and pretty-printed output
26 options being available.
27 The
28 .Nm
29 utility can also obtain and print a
30 list of peers in a common format by sending multiple queries to the
31 server.
32 .Pp
33 If one or more request options is included on the command line
34 when
35 .Nm
36 is executed, each of the requests will be sent
37 to the NTP servers running on each of the hosts given as command
38 line arguments, or on localhost by default.
39 If no request options
40 are given,
41 .Nm
42 will attempt to read commands from the
43 standard input and execute these on the NTP server running on the
44 first host given on the command line, again defaulting to localhost
45 when no other host is specified.
46 The
47 .Nm
48 utility will prompt for
49 commands if the standard input is a terminal device.
50 .Pp
51 The
52 .Nm
53 utility uses NTP mode 6 packets to communicate with the
54 NTP server, and hence can be used to query any compatible server on
55 the network which permits it.
56 Note that since NTP is a UDP protocol
57 this communication will be somewhat unreliable, especially over
58 large distances in terms of network topology.
59 The
60 .Nm
61 utility makes
62 one attempt to retransmit requests, and will time requests out if
63 the remote host is not heard from within a suitable timeout
64 time.
65 .Pp
66 For examples and usage, see the
67 .Qq "NTP Debugging Techniques"
68 page
69 (available as part of the HTML documentation
70 provided in
71 .Pa /usr/share/doc/ntp ) .
72 .Pp
73 The following options are available:
74 .Bl -tag -width indent
75 .It Fl c
76 The following argument is interpreted as an interactive format
77 command and is added to the list of commands to be executed on the
78 specified host(s).
79 Multiple
80 .Fl c
81 options may be given.
82 .It Fl i
83 Force
84 .Nm
85 to operate in interactive mode.
86 Prompts
87 will be written to the standard output and commands read from the
88 standard input.
89 .It Fl n
90 Output all host addresses in dotted-quad numeric format rather
91 than converting to the canonical host names.
92 .It Fl p
93 Print a list of the peers known to the server as well as a
94 summary of their state.
95 This is equivalent to the
96 .Ic peers
97 interactive command.
98 .El
99 .Pp
100 Specifying a
101 command line option other than
102 .Fl i
103 or
104 .Fl n
105 will
106 cause the specified query (queries) to be sent to the indicated
107 host(s) immediately.
108 Otherwise,
109 .Nm
110 will attempt to read
111 interactive format commands from the standard input.
112 .Ss "Internal Commands"
113 Interactive format commands consist of a keyword followed by zero
114 to four arguments.
115 Only enough characters of the full keyword to
116 uniquely identify the command need be typed.
117 The output of a
118 command is normally sent to the standard output, but optionally the
119 output of individual commands may be sent to a file by appending a
120 .Ql \&> ,
121 followed by a file name, to the command line.
122 A
123 number of interactive format commands are executed entirely within
124 the
125 .Nm
126 utility itself and do not result in NTP mode 6
127 requests being sent to a server.
128 These are described following.
129 .Bl -tag -width indent
130 .It Ic \&? Op Ar command_keyword
131 .It Ic help Op Ar command_keyword
132 A
133 .Ql \&?
134 by itself will print a list of all the command
135 keywords known to this incarnation of
136 .Nm .
137 A
138 .Ql \&?
139 followed by a command keyword will print function and usage
140 information about the command.
141 This command is probably a better
142 source of information about
143 .Nm
144 than this manual
145 page.
146 .It Xo Ic addvars
147 .Ar variable_name Ns Op = Ns Ar value ...
148 .Xc
149 .It Ic rmvars Ar variable_name ...
150 .It Ic clearvars
151 The data carried by NTP mode 6 messages consists of a list of
152 items of the form
153 .Ql variable_name=value ,
154 where the
155 .Ql =value
156 is ignored, and can be omitted,
157 in requests to the server to read variables.
158 The
159 .Nm
160 utility maintains an internal list in which data to be included in control
161 messages can be assembled, and sent using the
162 .Ic readlist
163 and
164 .Ic writelist
165 commands described below.
166 The
167 .Ic addvars
168 command allows variables and their optional values to be added to
169 the list.
170 If more than one variable is to be added, the list should
171 be comma-separated and not contain white space.
172 The
173 .Ic rmvars
174 command can be used to remove individual variables from the list,
175 while the
176 .Ic clearlist
177 command removes all variables from the
178 list.
179 .It Ic authenticate Cm yes | Cm no
180 Normally
181 .Nm
182 does not authenticate requests unless
183 they are write requests.
184 The command
185 .Ql authenticate yes
186 causes
187 .Nm
188 to send authentication with all requests it
189 makes.
190 Authenticated requests causes some servers to handle
191 requests slightly differently, and can occasionally melt the CPU in
192 fuzzballs if you turn authentication on before doing a
193 .Ic peer
194 display.
195 .It Ic cooked
196 Causes output from query commands to be "cooked", so that
197 variables which are recognized by
198 .Nm
199 will have their
200 values reformatted for human consumption.
201 Variables which
202 .Nm
203 thinks should have a decodable value but didn't are
204 marked with a trailing
205 .Ql \&?  .
206 .It Xo Ic debug
207 .Cm more |
208 .Cm less |
209 .Cm off
210 .Xc
211 Turns internal query program debugging on and off.
212 .It Ic delay Ar milliseconds
213 Specify a time interval to be added to timestamps included in
214 requests which require authentication.
215 This is used to enable
216 (unreliable) server reconfiguration over long delay network paths
217 or between machines whose clocks are unsynchronized.
218 Actually the
219 server does not now require timestamps in authenticated requests,
220 so this command may be obsolete.
221 .It Ic host Ar hostname
222 Set the host to which future queries will be sent.
223 Hostname may
224 be either a host name or a numeric address.
225 .It Ic hostnames Cm yes | Cm no
226 If
227 .Cm yes
228 is specified, host names are printed in
229 information displays.
230 If
231 .Cm no
232 is specified, numeric
233 addresses are printed instead.
234 The default is
235 .Cm yes ,
236 unless
237 modified using the command line
238 .Fl n
239 switch.
240 .It Ic keyid Ar keyid
241 This command allows the specification of a key number to be
242 used to authenticate configuration requests.
243 This must correspond
244 to a key number the server has been configured to use for this
245 purpose.
246 .It Xo Ic ntpversion
247 .Cm 1 |
248 .Cm 2 |
249 .Cm 3 |
250 .Cm 4
251 .Xc
252 Sets the NTP version number which
253 .Nm
254 claims in
255 packets.
256 Defaults to 3, Note that mode 6 control messages (and
257 modes, for that matter) didn't exist in NTP version 1.
258 There appear
259 to be no servers left which demand version 1.
260 .It Ic quit
261 Exit
262 .Nm .
263 .It Ic passwd
264 This command prompts you to type in a password (which will not
265 be echoed) which will be used to authenticate configuration
266 requests.
267 The password must correspond to the key configured for
268 use by the NTP server for this purpose if such requests are to be
269 successful.
270 .It Ic raw
271 Causes all output from query commands is printed as received
272 from the remote server.
273 The only formating/interpretation done on
274 the data is to transform nonascii data into a printable (but barely
275 understandable) form.
276 .It Ic timeout Ar milliseconds
277 Specify a timeout period for responses to server queries.
278 The
279 default is about 5000 milliseconds.
280 Note that since
281 .Nm
282 retries each query once after a timeout, the total waiting time for
283 a timeout will be twice the timeout value set.
284 .El
285 .Ss Control Message Commands
286 Each peer known to an NTP server has a 16 bit integer association
287 identifier assigned to it.
288 NTP control messages which carry peer
289 variables must identify the peer the values correspond to by
290 including its association ID.
291 An association ID of 0 is special,
292 and indicates the variables are system variables, whose names are
293 drawn from a separate name space.
294 .Pp
295 Control message commands result in one or more NTP mode 6
296 messages being sent to the server, and cause the data returned to
297 be printed in some format.
298 Most commands currently implemented send
299 a single message and expect a single response.
300 The current
301 exceptions are the peers command, which will send a preprogrammed
302 series of messages to obtain the data it needs, and the mreadlist
303 and mreadvar commands, which will iterate over a range of
304 associations.
305 .Bl -tag -width indent
306 .It Ic associations
307 Obtains and prints a list of association identifiers and peer
308 statuses for in-spec peers of the server being queried.
309 The list is
310 printed in columns.
311 The first of these is an index numbering the
312 associations from 1 for internal use, the second the actual
313 association identifier returned by the server and the third the
314 status word for the peer.
315 This is followed by a number of columns
316 containing data decoded from the status word.
317 See the peers command
318 for a decode of the
319 .Sq condition
320 field.
321 Note that the data
322 returned by the
323 .Ic associations
324 command is cached internally
325 in
326 .Nm .
327 The index is then of use when dealing with stupid
328 servers which use association identifiers which are hard for humans
329 to type, in that for any subsequent commands which require an
330 association identifier as an argument, the form of index may be
331 used as an alternative.
332 .It Xo Ic clockvar Op Ar assocID
333 .Oo
334 .Ar variable_name Ns Op = Ns Ar value ...
335 .Oc
336 .Ar ...
337 .Xc
338 .It Xo Ic cv Op Ar assocID
339 .Oo
340 .Ar variable_name Ns Op = Ns Ar value ...
341 .Oc
342 .Ar ...
343 .Xc
344 Requests that a list of the server's clock variables be sent.
345 Servers which have a radio clock or other external synchronization
346 will respond positively to this.
347 If the association identifier is
348 omitted or zero the request is for the variables of the
349 .Sq system clock
350 and will generally get a positive response from all
351 servers with a clock.
352 If the server treats clocks as pseudo-peers,
353 and hence can possibly have more than one clock connected at once,
354 referencing the appropriate peer association ID will show the
355 variables of a particular clock.
356 Omitting the variable list will
357 cause the server to return a default variable display.
358 .It Ic lassociations
359 Obtains and prints a list of association identifiers and peer
360 statuses for all associations for which the server is maintaining
361 state.
362 This command differs from the
363 .Ic associations
364 command
365 only for servers which retain state for out-of-spec client
366 associations (i.e., fuzzballs).
367 Such associations are normally
368 omitted from the display when the
369 .Ic associations
370 command is
371 used, but are included in the output of
372 .Ic lassociations .
373 .It Ic lpassociations
374 Print data for all associations, including out-of-spec client
375 associations, from the internally cached list of associations.
376 This
377 command differs from
378 .Ic passociations
379 only when dealing with
380 fuzzballs.
381 .It Ic lpeers
382 Like R peers, except a summary of all associations for which
383 the server is maintaining state is printed.
384 This can produce a much
385 longer list of peers from fuzzball servers.
386 .It Ic mreadlist Ar assocID Ar assocID
387 .It Ic mrl Ar assocID Ar assocID
388 Like the
389 .Ic readlist
390 command, except the query is done
391 for each of a range of (nonzero) association IDs.
392 This range is
393 determined from the association list cached by the most recent
394 .Ic associations
395 command.
396 .It Xo Ic mreadvar Ar assocID Ar assocID
397 .Oo
398 .Ar variable_name Ns Op = Ns Ar value ...
399 .Oc
400 .Xc
401 .It Xo Ic mrv Ar assocID Ar assocID
402 .Oo
403 .Ar variable_name Ns Op = Ns Ar value ...
404 .Oc
405 .Xc
406 Like the
407 .Ic readvar
408 command, except the query is done for
409 each of a range of (nonzero) association IDs.
410 This range is
411 determined from the association list cached by the most recent
412 .Ic associations
413 command.
414 .It Ic opeers
415 An old form of the
416 .Ic peers
417 command with the reference ID
418 replaced by the local interface address.
419 .It Ic passociations
420 Displays association data concerning in-spec peers from the
421 internally cached list of associations.
422 This command performs
423 identically to the
424 .Ic associations
425 except that it displays
426 the internally stored data rather than making a new query.
427 .It Ic peers
428 Obtains a current list peers of the server, along with a
429 summary of each peer's state.
430 Summary information includes the
431 address of the remote peer, the reference ID (0.0.0.0 if this is
432 unknown), the stratum of the remote peer, the type of the peer
433 (local, unicast, multicast or broadcast), when the last packet was
434 received, the polling interval, in seconds, the reachability
435 register, in octal, and the current estimated delay, offset and
436 dispersion of the peer, all in milliseconds.
437 The character in the left margin indicates the fate of this
438 peer in the clock selection process.
439 Following is a list of these
440 characters, the pigeon used in the
441 .Ic rv
442 command, and a short
443 explanation of the condition revealed.
444 .Bl -tag -width indent
445 .It space
446 .Pq reject
447 The peer is discarded as unreachable, synchronized to this
448 server (synch loop) or outrageous synchronization distance.
449 .It x
450 .Pq falsetick
451 The peer is discarded by the intersection algorithm as a
452 falseticker.
453 .It \&.
454 .Pq excess
455 The peer is discarded as not among the first ten peers sorted
456 by synchronization distance and so is probably a poor candidate for
457 further consideration.
458 .It \&-
459 .Pq outlyer
460 The peer is discarded by the clustering algorithm as an
461 outlyer.
462 .It \&+
463 .Pq candidate
464 The peer is a survivor and a candidate for the combining
465 algorithm.
466 .It \&#
467 .Pq selected
468 The peer is a survivor, but not among the first six peers
469 sorted by synchronization distance.
470 If the association is ephemeral,
471 it may be demobilized to conserve resources.
472 .It \&*
473 .Pq peer
474 The peer has been declared the system peer and lends its
475 variables to the system variables.
476 .It o
477 .Pq (pps.peer)
478 The peer has been declared the system peer and lends its
479 variables to the system variables.
480 However, the actual system
481 synchronization is derived from a pulse-per-second (PPS) signal,
482 either indirectly via the PPS reference clock driver or directly
483 via kernel interface.
484 .El
485 .El
486 .Pp
487 The
488 .Va flash
489 variable is a valuable debugging aid.
490 It
491 displays the results of the original sanity checks defined in the
492 NTP specification RFC-1305 and additional ones added in NTP Version
493 4.
494 There are eleven tests called
495 .Sy TEST1
496 through
497 .Sy TEST11 .
498 The tests are performed in a certain order
499 designed to gain maximum diagnostic information while protecting
500 against accidental or malicious errors.
501 The
502 .Va flash
503 variable
504 is first initialized to zero.
505 If after each set of tests one or
506 more bits are set, the packet is discarded.
507 .Pp
508 Tests
509 .Sy TEST4
510 and
511 .Sy TEST5
512 check the access
513 permissions and cryptographic message digest.
514 If any bits are set
515 after that, the packet is discarded.
516 Tests
517 .Sy TEST10
518 and
519 .Sy TEST11
520 check the authentication state using Autokey
521 public-key cryptography, as described in the
522 .Sx Authentication Options
523 section of
524 .Xr ntp.conf 5 .
525 If any bits are set
526 and the association has previously been marked reachable, the
527 packet is discarded; otherwise, the originate and receive
528 timestamps are saved, as required by the NTP protocol, and
529 processing continues.
530 .Pp
531 Tests
532 .Sy TEST1
533 through
534 .Sy TEST3
535 check the packet
536 timestamps from which the offset and delay are calculated.
537 If any
538 bits are set, the packet is discarded; otherwise, the packet header
539 variables are saved.
540 Tests
541 .Sy TEST6
542 through
543 .Sy TEST8
544 check the health of the server.
545 If any bits are set, the packet is
546 discarded; otherwise, the offset and delay relative to the server
547 are calculated and saved.
548 Test
549 .Sy TEST9
550 checks the health of
551 the association itself.
552 If any bits are set, the packet is
553 discarded; otherwise, the saved variables are passed to the clock
554 filter and mitigation algorithms.
555 .Pp
556 The
557 .Va flash
558 bits for each test read in increasing order
559 from the least significant bit are defined as follows.
560 .Bl -tag -width indent
561 .It Sy TEST1
562 Duplicate packet.
563 The packet is at best a casual retransmission
564 and at worst a malicious replay.
565 .It Sy TEST2
566 Bogus packet.
567 The packet is not a reply to a message previously
568 sent.
569 This can happen when the NTP daemon is restarted and before
570 somebody else notices.
571 .It Sy TEST3
572 Unsynchronized.
573 One or more timestamp fields are invalid.
574 This
575 normally happens when the first packet from a peer is
576 received.
577 .It Sy TEST4
578 Access is denied.
579 See the
580 .Qq "Access Control"
581 page.
582 .It Sy TEST5
583 Cryptographic authentication fails.
584 See the
585 .Sx Authentication Options
586 section of
587 .Xr ntp.conf 5 .
588 .It Sy TEST6
589 The server is unsynchronized.
590 Wind up its clock first.
591 .It Sy TEST7
592 The server stratum is at the maximum than 15.
593 It is probably
594 unsynchronized and its clock needs to be wound up.
595 .It Sy TEST8
596 Either the root delay or dispersion is greater than one second,
597 which is highly unlikely unless the peer is synchronized to
598 Mars.
599 .It Sy TEST9
600 Either the peer delay or dispersion is greater than one second,
601 which is highly unlikely unless the peer is on Mars.
602 .It Sy TEST10
603 The autokey protocol has detected an authentication failure.
604 See the
605 .Sx Authentication Options
606 section of
607 .Xr ntp.conf 5 .
608 .It Sy TEST11
609 The autokey protocol has not verified the server or peer is
610 authentic and has valid public key credentials.
611 See the
612 .Sx Authentication Options
613 section of
614 .Xr ntp.conf 5 .
615 .El
616 .Pp
617 Additional system variables used by the NTP Version 4 Autokey
618 support include the following:
619 .Bl -tag -width indent
620 .It Ic certificate Ar filestamp
621 Shows the NTP seconds when the certificate file was
622 created.
623 .It Ic hostname Ar host
624 Shows the name of the host as returned by the Unix
625 .Xr gethostname 3
626 library function.
627 .It Ic flags Ar hex
628 Shows the current flag bits, where the
629 .Ar hex
630 bits
631 are interpreted as follows:
632 .Bl -tag -width indent
633 .It 0x01
634 autokey enabled
635 .It 0x02
636 RSA public/private key files present
637 .It 0x04
638 PKI certificate file present
639 .It 0x08
640 Diffie-Hellman parameters file present
641 .It 0x10
642 NIST leapseconds table file present
643 .El
644 .It Ic leapseconds Ar filestamp
645 Shows the NTP seconds when the NIST leapseconds table file was
646 created.
647 .It Ic params Ar filestamp
648 Shows the NTP seconds when the Diffie-Hellman agreement
649 parameter file was created.
650 .It Ic publickey Ar filestamp
651 Shows the NTP seconds when the RSA public/private key files
652 were created.
653 .It Ic refresh Ar filestamp
654 Shows the NTP seconds when the public cryptographic values were
655 refreshed and signed.
656 .It Ic tai Ar offset
657 Shows the TAI-UTC offset in seconds obtained from the NIST
658 leapseconds table.
659 .El
660 .Pp
661 Additional peer variables used by the NTP Version 4 Autokey
662 support include the following:
663 .Bl -tag -width indent
664 .It Ic certificate Ar filestamp
665 Shows the NTP seconds when the certificate file was
666 created.
667 .It Ic flags Ar hex
668 Shows the current flag bits, where the
669 .Ar hex
670 bits are
671 interpreted as in the system variable of the same name.
672 The bits
673 are set in the first autokey message received from the server and
674 then reset as the associated data are obtained from the server and
675 stored.
676 .It Ic hcookie Ar hex
677 Shows the host cookie used in the key agreement algorithm.
678 .It Ic initkey Ar key
679 Shows the initial key used by the key list generator in the
680 autokey protocol.
681 .It Ic initsequence Ar index
682 Shows the initial index used by the key list generator in the
683 autokey protocol.
684 .It Ic pcookie Ar hex
685 Specifies the peer cookie used in the key agreement
686 algorithm.
687 .It Ic timestamp Ar time
688 Shows the NTP seconds when the last autokey key list was
689 generated and signed.
690 .It Ic pstatus Ar assocID
691 Sends a read status request to the server for the given
692 association.
693 The names and values of the peer variables returned
694 will be printed.
695 Note that the status word from the header is
696 displayed preceding the variables, both in hexadecimal and in
697 pidgeon English.
698 .It Ic readlist Ar assocID
699 .It Ic rl Ar assocID
700 Requests that the values of the variables in the internal
701 variable list be returned by the server.
702 If the association ID is
703 omitted or is 0 the variables are assumed to be system variables.
704 Otherwise they are treated as peer variables.
705 If the internal
706 variable list is empty a request is sent without data, which should
707 induce the remote server to return a default display.
708 .It Xo Ic readvar Ar assocID
709 .Ar variable_name Ns Op = Ns Ar value
710 .Ar ...
711 .Xc
712 .It Xo Ic rv Ar assocID
713 .Ar variable_name Ns Op = Ns Ar value
714 .Ar ...
715 .Xc
716 Requests that the values of the specified variables be returned
717 by the server by sending a read variables request.
718 If the
719 association ID is omitted or is given as zero the variables are
720 system variables, otherwise they are peer variables and the values
721 returned will be those of the corresponding peer.
722 Omitting the
723 variable list will send a request with no data which should induce
724 the server to return a default display.
725 .It Xo Ic writevar Ar assocID
726 .Ar variable_name Ns Op = Ns Ar value
727 .Ar ...
728 .Xc
729 Like the readvar request, except the specified variables are
730 written instead of read.
731 .It Ic writelist Op Ar assocID
732 Like the readlist request, except the internal list variables
733 are written instead of read.
734 .El
735 .Sh SEE ALSO
736 .Xr ntp.conf 5 ,
737 .Xr ntpd 8 ,
738 .Xr ntpdc 8
739 .Sh BUGS
740 The
741 .Ic peers
742 command is non-atomic and may occasionally result in
743 spurious error messages about invalid associations occurring and
744 terminating the command.
745 The timeout time is a fixed constant,
746 which means you wait a long time for timeouts since it assumes sort
747 of a worst case.
748 The program should improve the timeout estimate as
749 it sends queries to a particular host, but doesn't.