'\" t
.\"     Title: ntpdig
.\"    Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.23
.\"      Date: 2025-04-15
.\"    Manual: NTPsec
.\"    Source: NTPsec
.\"  Language: English
.\"
.TH "NTPDIG" "1" "2025-04-15" "NTPsec" "NTPsec"
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.ss \n[.ss] 0
.nh
.ad l
.de URL
\fI\\$2\fP <\\$1>\\$3
..
.als MTO URL
.if \n[.g] \{\
.  mso www.tmac
.  am URL
.    ad l
.  .
.  am MTO
.    ad l
.  .
.  LINKSTYLE blue R < >
.\}
.SH "NAME"
ntpdig \- standard Simple Network Time Protocol client program
.SH "SYNOPSIS"
.sp
.nf
ntpdig
    [\-\-help | \-?] [\-4 | \-6] [\-a keynum] [\-p samples]
    [\-c] [\-d] [\-D debug\-level] [\-g delay] [\-j] [\-k keyfile]
    [\-l logfile] [\-M steplimit] [\-S] [\-s]
    [\-\-wait] [\-\-no\-wait] [\-\-version] [address...]+
.fi
.br
.SH "DESCRIPTION"
.sp
ntpdig can be used as an SNTP client to query an NTP or SNTP server and
either display the time or set the local system\(cqs time (given suitable
privilege). It can be run as an interactive command or from a \fIcron\fP
job. NTP (the Network Time Protocol) and SNTP (the Simple Network Time
Protocol) are defined and described by RFC 5905.
.sp
The default is to write the estimated correct local date and time (i.e.
not UTC) to the standard output in a format like:
.sp
.if n .RS 4
.nf
.fam C
2015\-10\-14 13:46:04.534916 (+0500) \-0.000007 +/\- 0.084075 localhost 127.0.0.1 s2 no\-leap
.fam
.fi
.if n .RE
.sp
where the \f(CR(+0500)\fP means that to get to UTC from the reported local
time one must add 5 hours and 0 minutes, the \f(CR\-0.000007\fP indicates the
local clock is 0.000007 seconds ahead of correct time (so 0.000007 seconds
must be subtracted from the local clock to get it to be correct). Note that
the number of decimals printed for this value will change based on the
reported precision of the server. \f(CR+/\- 0.084075\fP is the reported
\fIsynchronization\fP \fIdistance\fP (in seconds), which represents the
maximum error due to all causes. If the server does not report valid
data needed to calculate the synchronization distance, this will be
reported as \f(CR+/\- ?\fP.
.sp
If the \fIhost\fP is different from the \fIIP\fP, both will be
displayed. Otherwise, only the \fIIP\fP is displayed. Finally, the
\fIstratum\fP of the host is reported and the leap indicator is decoded
and displayed.
.sp
With the \-j (JSON) option, the output format becomes a self\-describing
JSON record:
.sp
.if n .RS 4
.nf
.fam C
{"time":"2015\-10\-14T13:46:04.534916+0500",
         "offset":\-0.000007,"precision":"0.084075",
         "host":"localhost",ip:"127.0.0.1",
         "stratum":2,"leap":"noleap","adjusted":false}
.fam
.fi
.if n .RE
.sp
In the JSON format, time is in ISO 8601 format; precision is the synch
distance, with an unknown synch distance being reported as 0.  Host and
IP are always emitted even if duplicate. The "adjusted" boolean
reports whether ntpdig determined it should have slewed or stepped the
time. This may be shown as true even if time was not actually
adjusted due to lack of clock\-setting privileges.
.SH "OPTIONS"
.sp
\f(CR\-h, \-\-help\fP
.RS 4
Displays usage information and exits.
.RE
.sp
\f(CR\-4\fP, \f(CR\-\-ipv4\fP
.RS 4
Force IPv4 DNS name resolution. This option must not appear in
combination with any of the following options: ipv6.
.sp
Force DNS resolution of the following host names on the command line
to the IPv4 namespace.
.RE
.sp
\f(CR\-6\fP, \f(CR\-\-ipv6\fP
.RS 4
Force IPv6 DNS name resolution. This option must not appear in
combination with any of the following options: ipv4.
.sp
Force DNS resolution of the following host names on the command line
to the IPv6 namespace.
.RE
.sp
\f(CR\-a\fP \fIauth\-keynumber\fP, \f(CR\-\-authentication\fP=\fIauth\-keynumber\fP
.RS 4
  Enable authentication with the key \fIauth\-keynumber\fP. This option takes
an integer number as its argument.

.br
Enable authentication using the key specified in this option\(cqs
argument. The argument of this option is the \fIkeyid\fP, a number
specified in the \fIkeyfile\fP as this key\(cqs identifier. See the \fIkeyfile\fP
option (\f(CR\-k\fP) for more details.
.RE
.sp
\f(CR\-c\fP \fIhost\-name\fP, \f(CR\-\-concurrent\fP=\fIhost\-name\fP
.RS 4
Concurrently query all IPs returned for host\-name. This option may
appear an unlimited number of times.
.sp
Requests from an NTP "client" to a "server" should never be sent more
rapidly than one every 2 seconds. By default, any IPs returned as part
of a DNS lookup are assumed to be for a single instance of ntpd, and
therefore \f(CRntpdig\fP will send queries to these IPs one after another,
with a 2\-second gap in between each query.
.sp
The \f(CR\-c\fP or \f(CR\-\-concurrent\fP flag says that any IPs returned for the DNS
lookup of the supplied host\-name are on different machines, so we can
send concurrent queries.  This is appropriate when using a server pool.
.RE
.sp
\f(CR\-d\fP, \f(CR\-\-debug\-level\fP
.RS 4
Increase debug verbosity level. This option may appear an unlimited
number of times.
.RE
.sp
\f(CR\-D\fP \fInumber\fP, \f(CR\-\-set\-debug\-level\fP=\fInumber\fP
.RS 4
Set the debug verbosity level. This option may appear an unlimited
number of times. This option takes an integer number as its argument.
.RE
.sp
\f(CR\-g\fP \fImilliseconds\fP, \f(CR\-\-gap\fP=\fImilliseconds\fP
.RS 4
The gap (in milliseconds) between time requests. This option takes an
integer number as its argument. The default \fImilliseconds\fP for this
option is 50.
.sp
Separate the queries we send out by the specified number of
milliseconds. A larger \fIdelay\fP reduces the query load on the time
sources, at the cost of increasing the time to receive a valid
response if the first source attempted is slow or unreachable.
.RE
.sp
\f(CR\-j\fP
.RS 4
Output to stdout in JSON, suppressing syslog messages.
.RE
.sp
\f(CR\-k\fP \fIfile\-name\fP, \f(CR\-\-keyfile\fP=\fIfile\-name\fP
.RS 4
Look in this file for the key specified with \f(CR\-a\fP.
.sp
This option specifies the keyfile. \f(CRntpdig\fP will search for the key
specified with \f(CR\-a\fP keyno in this file. See \fIntp.keys(5)\fP for more
information.
.RE
.sp
\f(CR\-l\fP \fIfile\-name\fP, \f(CR\-\-logfile\fP=\fIfile\-name\fP
.RS 4
Log to specified logfile.
.sp
This option causes the client to write log messages to the specified
\fIlogfile\fP.
.RE
.sp
\f(CR\-M\fP \fInumber\fP, \f(CR\-\-steplimit\fP=\fInumber\fP
.RS 4
Adjustments less than \fIsteplimit\fP milliseconds will be slewed. This option
takes an integer number as its argument. The value of \fInumber\fP is
constrained to being greater than or equal to 0,
.sp
If the time adjustment is less than \fIsteplimit\fP milliseconds, slew the
amount using \fIadjtime(2)\fP. Otherwise, step the correction using
\fIclock_settime()\fP or local equivalent. The default value is 0, which
means all adjustments will be stepped. This is a feature, as different
situations demand different values.
.RE
.sp
\f(CR\-p\fP, \f(CR\-\-samples\fP
.RS 4
The number of samples to take (default 1). The best one (chosen by,
among other criteria, sync distance) is selected for display or use.
.RE
.sp
\f(CR\-S\fP, \f(CR\-\-step\fP
.RS 4
By default, \f(CRntpdig\fP displays the clock offset but does not attempt to
correct it. This option enables offset correction by stepping, that
is, directly setting the clock to the corrected time. This typically
requires \f(CRntpdig\fP be invoked as the superuser ("root").
.RE
.sp
\f(CR\-s\fP, \f(CR\-\-slew\fP
.RS 4
By default, \f(CRntpdig\fP displays the clock offset but does not attempt to
correct it. This option enables offset correction by slewing using
adjtime(), which changes the rate of the clock for a period long
enough to accomplish the required offset (phase) correction. This
typically requires \f(CRntpdig\fP be invoked as the superuser ("root").
.RE
.sp
\f(CR\-t\fP \fIseconds\fP, \f(CR\-\-timeout\fP=\fIseconds\fP
.RS 4
The number of seconds to wait for responses. This option takes an
integer number as its argument. The default \fIseconds\fP for this option
is: 5.
.sp
When waiting for a reply, \f(CRntpdig\fP will wait the number of seconds
specified before giving up. The default should be more than enough for
a unicast response. If \f(CRntpdig\fP is only waiting for a broadcast response
a longer timeout is likely needed.
.RE
.sp
\f(CR\-\-wait\fP, \f(CR\-\-no\-wait\fP
.RS 4
Wait for pending replies (if not setting the time). The \fIno\-wait\fP form
will disable the option. This option is enabled by default.
.sp
If we are not setting the time, wait for all pending responses.
.RE
.sp
\f(CR\-\-version\fP
.RS 4
Output version of program and exit.
.RE
.SH "USAGE"
.sp
\f(CRntpdig ntpserver.somewhere\fP
.RS 4
is the simplest use of this program and can be run as an unprivileged
command to check the current time and error in the local clock.
.RE
.sp
\f(CRntpdig \-S \-s \-M 128 ntpserver.somewhere\fP
.RS 4
With suitable privilege, run as a command or from a \fIcron\fP(8) job,
\f(CRntpdig \-Ss \-M 128 ntpserver.somewhere\fP will request the time from the
server, and if that server reports that it is synchronized then if the
offset adjustment is less than 128 milliseconds the correction will be
slewed, and if the correction is more than 128 milliseconds the
correction will be stepped.
.RE
.sp
\f(CRntpdig \-S ntpserver.somewhere\fP
.RS 4
With suitable privilege, run as a command or from a \fIcron\fP(8) job,
\f(CRntpdig \-S ntpserver.somewhere\fP will set (step) the local clock from a
synchronized specified server, like the \f(CRntpdate\fP utility from older
NTP implementations.
.RE
.SH "COMPATIBILITY"
.sp
Not all options of the NTP classic sntp(1) utility have been retained;
don\(cqt expect \-b, \-K, \-o, \-r, \-w, or \-W to work.  These have either
been removed for security reasons or discarded as unnecessary in a modern
environment.
.sp
This version does not log to syslog.  Pipe standard output and
standard error to logger(1) if you want this behavior.
.sp
The synchronization\-distance formula used in this version is slightly
different from that found in sntp(1), tracking the newer formula used
in ntpd(8).  Expect offset computations to match but synch\-distances
not to.
.SH "AUTHORS"
.sp
Johannes Maximilian Kuehn, Harlan Stenn, Dave Hart.
.SH "EXIT STATUS"
.sp
One of the following exit values will be returned:
.sp
0 (EXIT_SUCCESS)
.RS 4
Successful program execution.
.RE
.sp
1 (EXIT_FAILURE)
.RS 4
The operation failed or the command syntax was not valid.
.RE