Sntp User's Manual


Next: , Previous: (dir), Up: (dir)

Simple Network Time Protocol User Manual

This document describes the use of the NTP Project's sntp program, that can be used to query a Network Time Protocol (NTP) server and display the time offset of the system clock relative to the server clock. Run as root, it can correct the system clock to this offset as well. It can be run as an interactive command or from a cron job.

This document applies to version 4.2.7p210 of sntp.

The program implements the SNTP protocol as defined by RFC 5905, the NTPv4 IETF specification.

Short Contents



Description

By default, sntp writes the local data and time (i.e., not UTC) to the standard output in the format:

     1996-10-15 20:17:25.123 (+0800) +4.567 +/- 0.089 secs

where YYYY-MM-DD HH:MM:SS.SUBSEC is the local date and time, (+0800) is the local timezone adjustment (so we would add 8 hours and 0 minutes to convert the reported local time to UTC), and the +4.567 +/- 0.089 secs indicates the time offset and error bound of the system clock relative to the server clock.



Invoking sntp

sntp can be used as an SNTP client to query a NTP or SNTP server and either display the time or set the local system's time (given suitable privilege). It can be run as an interactive command or in a cron job.

NTP (the Network Time Protocol) and SNTP (the Simple Network Time Protocol) are defined and described by RFC 5905.

The default is to write the estimated correct local date and time (i.e. not UTC) to the standard output in a format like

     1996-10-15 20:17:25.123 (+0800) +4.567 +/- 0.089 [host] IP sN

where the

     (+0800)

means that to get to UTC from the reported local time one must add 8 hours and 0 minutes, the

     +4.567

indicates the local clock is 4.567 seconds behind the correct time (so 4.567 seconds must be added to 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.

     +/- 0.089

is the reported synchronization distance (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

     +/- ?

If the host is different from the IP, both will be displayed. Otherwise, only the IP is displayed. Finally, the stratum is reported.

This section was generated by AutoGen, the aginfo template and the option descriptions for the sntp program. It documents the sntp usage text and option meanings.

This software is released under a specialized copyright license.


Next: , Up: sntp Invocation

sntp usage help (-?)

This is the automatically generated usage text for sntp:

sntp - standard Simple Network Time Protocol client program - Ver. 4.2.7p210
USAGE:  sntp [ -<flag> [<val>] | --<name>[{=| }<val>] ]... \
                [ hostname-or-IP ...]
  Flg Arg Option-Name    Description
   -4 no  ipv4           Force IPv4 DNS name resolution
                                - prohibits these options:
                                ipv6
   -6 no  ipv6           Force IPv6 DNS name resolution
                                - prohibits these options:
                                ipv4
   -a Num authentication Enable authentication with the key auth-keynumber
   -B Num bctimeout      The number of seconds to wait for broadcasts
   -b Str broadcast      Listen to the address specified for broadcast time sync
                                - may appear multiple times
   -c Str concurrent     Concurrently query all IPs returned for host-name
                                - may appear multiple times
   -d no  debug-level    Increase debug verbosity level
                                - may appear multiple times
   -D Str set-debug-level Set the debug verbosity level
                                - may appear multiple times
   -g Num gap            The gap (in milliseconds) between time requests
   -K Fil kod            KoD history filename
   -k Fil keyfile        Look in this file for the key specified with -a
   -l Fil logfile        Log to specified logfile
   -M Num steplimit      Adjustments less than @file{steplimit} msec will be slewed
                                - It must be in the range:
                                  greater than or equal to 0
   -o Num ntpversion     Send <int> as our NTP version
                                - It must be in the range:
                                  0 to 7
   -r no  usereservedport Use the NTP Reserved Port (port 123)
   -S no  step           OK to 'step' the time with settimeofday(2)
   -s no  slew           OK to 'slew' the time with adjtime(2)
   -u Num uctimeout      The number of seconds to wait for unicast responses
      no  wait           Wait for pending replies (if not setting the time)
                                - disabled as --no-wait
                                - enabled by default
      opt version        Output version information and exit
   -? no  help           Display extended usage information and exit
   -! no  more-help      Extended usage information passed thru pager
   -> opt save-opts      Save the option state to a config file
   -< Str load-opts      Load options from a config file
                                - disabled as --no-load-opts
                                - may appear multiple times

Options are specified by doubled hyphens and their name or by a single
hyphen and the flag character.



The following option preset mechanisms are supported:
 - reading file $HOME/.ntprc
 - reading file ./.ntprc
 - examining environment variables named SNTP_*

please send bug reports to:  http://bugs.ntp.org, bugs@ntp.org


Next: , Previous: sntp usage, Up: sntp Invocation

authentication option (-a)

This is the “enable authentication with the key auth-keynumber” option. This option enables authentication using the key specified in this option's argument. The argument of this option is the keyid, a number specified in the keyfile as this key's identifier. See the keyfile option (-k) for more details.


Next: , Previous: sntp authentication, Up: sntp Invocation

bctimeout option (-B)

This is the “the number of seconds to wait for broadcasts” option. When waiting for a broadcast packet sntp will wait the number of seconds specified before giving up.


Next: , Previous: sntp bctimeout, Up: sntp Invocation

broadcast option (-b)

This is the “listen to the address specified for broadcast time sync” option.

This option has some usage constraints. It:

If specified sntp will listen to the specified address for NTP broadcasts. The default maximum wait time can be modified with -B.


Next: , Previous: sntp broadcast, Up: sntp Invocation

concurrent option (-c)

This is the “concurrently query all ips returned for host-name” option.

This option has some usage constraints. It:

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 sntp will send queries to these IPs one after another, with a 2-second gap in between each query.

The -c or --concurrent 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.


Next: , Previous: sntp concurrent, Up: sntp Invocation

debug-level option (-d)

This is the “increase debug verbosity level” option.

This option has some usage constraints. It:


Next: , Previous: sntp debug-level, Up: sntp Invocation

gap option (-g)

This is the “the gap (in milliseconds) between time requests” option. Since we're only going to use the first valid response we get and there is benefit to specifying a good number of servers to query, separate the queries we send out by the specified number of milliseconds.


Next: , Previous: sntp gap, Up: sntp Invocation

ipv4 option (-4)

This is the “force ipv4 dns name resolution” option.

This option has some usage constraints. It:

Force DNS resolution of the following host names on the command line to the IPv4 namespace.


Next: , Previous: sntp ipv4, Up: sntp Invocation

ipv6 option (-6)

This is the “force ipv6 dns name resolution” option.

This option has some usage constraints. It:

Force DNS resolution of the following host names on the command line to the IPv6 namespace.


Next: , Previous: sntp ipv6, Up: sntp Invocation

keyfile option (-k)

This is the “look in this file for the key specified with -a” option. This option specifies the keyfile. sntp will search for the key specified with -a keyno in this file. Key files follow the following format:

keyid keytype key

Where keyid is a number identifying this key keytype is one of the following: S Key is a 64 Bit hexadecimal number as specified in in the DES specification. N Key is a 64 Bit hexadecimal number as specified in the NTP standard. A Key is a 1-to-8 character ASCII string. M Key is a 1-to-8 character ASCII string using the MD5 authentication scheme.

For more information see ntp.keys(5).


Next: , Previous: sntp keyfile, Up: sntp Invocation

kod option (-K)

This is the “kod history filename” option. Specifies the filename to be used for the persistent history of KoD responses received from servers.


Next: , Previous: sntp kod, Up: sntp Invocation

logfile option (-l)

This is the “log to specified logfile” option. This option causes the client to write log messages to the specified logfile.


Next: , Previous: sntp logfile, Up: sntp Invocation

ntpversion option (-o)

This is the “send <int> as our ntp version” option. When sending requests to a remote server, tell them we are running NTP protocol version ntpversion .


Next: , Previous: sntp ntpversion, Up: sntp Invocation

set-debug-level option (-D)

This is the “set the debug verbosity level” option.

This option has some usage constraints. It:


Next: , Previous: sntp set-debug-level, Up: sntp Invocation

slew option (-s)

This is the “ok to 'slew' the time with adjtime(2)” option.


Next: , Previous: sntp slew, Up: sntp Invocation

step option (-S)

This is the “ok to 'step' the time with settimeofday(2)” option.


Next: , Previous: sntp step, Up: sntp Invocation

steplimit option (-M)

This is the “adjustments less than steplimit msec will be slewed” option. If the time adjustment is less than steplimit milliseconds, slew the amount using adjtime(2). Otherwise, step the correction using settimeofday(2).


Next: , Previous: sntp steplimit, Up: sntp Invocation

uctimeout option (-u)

This is the “the number of seconds to wait for unicast responses” option. When waiting for a unicast reply, sntp will wait the number of seconds specified before giving up.


Next: , Previous: sntp uctimeout, Up: sntp Invocation

usereservedport option (-r)

This is the “use the ntp reserved port (port 123)” option. Use port 123, which is reserved for NTP, for our network communications.


Previous: sntp usereservedport, Up: sntp Invocation

wait option

This is the “wait for pending replies (if not setting the time)” option.

This option has some usage constraints. It:

If we are not setting the time, wait for all pending responses.



Usage

The simplest use of this program is as an unprivileged command to check the current time, offset, and error in the local clock. For example:

    sntp ntpserver.somewhere

With suitable privilege, it can be run as a command or in a crom job to reset the local clock from a reliable server, like the ntpdate and rdate commands. For example:

    sntp -a ntpserver.somewhere