Sntp User’s Manual

Next: , Previous: , 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.8p15 of sntp.

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

Short Table of Contents


Next: , Up: Top  

1 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.


Next: , Previous: , Up: sntp Description  

1.1 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 from 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 of the host is reported and the leap indicator is decoded and displayed.

This section was generated by AutoGen, using the agtexi-cmd template and the option descriptions for the sntp program. This software is released under the NTP license, <http://ntp.org/license>.


Next: , Up: sntp Invocation  

1.1.1 sntp help/usage (--help)

This is the automatically generated usage text for sntp.

The text printed is the same whether selected with the help option (--help) or the more-help option (--more-help). more-help will print the usage text by passing it through a pager program. more-help is disabled on platforms without a working fork(2) function. The PAGER environment variable is used to select the program, defaulting to more. Both will exit with a status code of 0.

sntp - standard Simple Network Time Protocol client program - Ver. 4.2.8p15
Usage:  sntp [ -<flag> [<val>] | --<name>[{=| }<val>] ]... \
                [ hostname-or-IP ...]
  Flg Arg Option-Name    Description
   -4 no  ipv4           Force IPv4 DNS name resolution
                                - prohibits the option 'ipv6'
   -6 no  ipv6           Force IPv6 DNS name resolution
                                - prohibits the option 'ipv4'
   -a Num authentication Enable authentication with the key auth-keynumber
   -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 Num 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 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 protocol 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)
   -t Num timeout        The number of seconds to wait for 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: , Up: sntp Invocation  

1.1.2 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: , Up: sntp Invocation  

1.1.3 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: , Up: sntp Invocation  

1.1.4 authentication option (-a)

This is the “enable authentication with the key auth-keynumber” option. This option takes a number argument auth-keynumber. Enable 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: , Up: sntp Invocation  

1.1.5 broadcast option (-b)

This is the “listen to the address specified for broadcast time sync” option. This option takes a string argument broadcast-address.

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 (and probably should) be modified with -t.


Next: , Previous: , Up: sntp Invocation  

1.1.6 concurrent option (-c)

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

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: , Up: sntp Invocation  

1.1.7 gap option (-g)

This is the “the gap (in milliseconds) between time requests” option. This option takes a number argument milliseconds. 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: , Up: sntp Invocation  

1.1.8 kod option (-K)

This is the “kod history filename” option. This option takes a file argument file-name. Specifies the filename to be used for the persistent history of KoD responses received from servers. If the file does not exist, a warning message will be displayed. The file will not be created.


Next: , Previous: , Up: sntp Invocation  

1.1.9 keyfile option (-k)

This is the “look in this file for the key specified with -a” option. This option takes a file argument file-name. This option specifies the keyfile. sntp will search for the key specified with -a keyno in this file. See ntp.keys(5) for more information.


Next: , Previous: , Up: sntp Invocation  

1.1.10 logfile option (-l)

This is the “log to specified logfile” option. This option takes a file argument file-name. This option causes the client to write log messages to the specified logfile.


Next: , Previous: , Up: sntp Invocation  

1.1.11 steplimit option (-M)

This is the “adjustments less than steplimit msec will be slewed” option. This option takes a number argument. If the time adjustment is less than steplimit milliseconds, slew the amount using adjtime(2). Otherwise, step the correction using settimeofday(2). The default value is 0, which means all adjustments will be stepped. This is a feature, as different situations demand different values.


Next: , Previous: , Up: sntp Invocation  

1.1.12 ntpversion option (-o)

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


Next: , Previous: , Up: sntp Invocation  

1.1.13 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.


Next: , Previous: , Up: sntp Invocation  

1.1.14 timeout option (-t)

This is the “the number of seconds to wait for responses” option. This option takes a number argument seconds. When waiting for a reply, sntp will wait the number of seconds specified before giving up. The default should be more than enough for a unicast response. If sntp is only waiting for a broadcast response a longer timeout is likely needed.


Next: , Previous: , Up: sntp Invocation  

1.1.15 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.


Next: , Previous: , Up: sntp Invocation  

1.1.16 presetting/configuring sntp

Any option that is not marked as not presettable may be preset by loading values from configuration ("rc" or "ini") files, and values from environment variables named SNTP and SNTP_<OPTION_NAME>. <OPTION_NAME> must be one of the options listed above in upper case and segmented with underscores. The SNTP variable will be tokenized and parsed like the command line. The remaining variables are tested for existence and their values are treated like option arguments.

libopts will search in 2 places for configuration files:

The environment variables HOME, and PWD are expanded and replaced when sntp runs. For any of these that are plain files, they are simply processed. For any that are directories, then a file named .ntprc is searched for within that directory and processed.

Configuration files may be in a wide variety of formats. The basic format is an option name followed by a value (argument) on the same line. Values may be separated from the option name with a colon, equal sign or simply white space. Values may be continued across multiple lines by escaping the newline with a backslash.

Multiple programs may also share the same initialization file. Common options are collected at the top, followed by program specific segments. The segments are separated by lines like:

[SNTP]

or by

<?program sntp>

Do not mix these styles within one configuration file.

Compound values and carefully constructed string values may also be specified using XML syntax:

<option-name>
   <sub-opt>...&lt;...&gt;...</sub-opt>
</option-name>

yielding an option-name.sub-opt string value of

"...<...>..."

AutoOpts does not track suboptions. You simply note that it is a hierarchicly valued option. AutoOpts does provide a means for searching the associated name/value pair list (see: optionFindValue).

The command line options relating to configuration and/or usage help are:

version (-)

Print the program version to standard out, optionally with licensing information, then exit 0. The optional argument specifies how much licensing detail to provide. The default is to print just the version. The licensing infomation may be selected with an option argument. Only the first letter of the argument is examined:

version

Only print the version. This is the default.

copyright

Name the copyright usage licensing terms.

verbose

Print the full copyright usage licensing terms.


Next: , Previous: , Up: sntp Invocation  

1.1.17 sntp exit status

One of the following exit values will be returned:

0 (EXIT_SUCCESS)

Successful program execution.

1 (EXIT_FAILURE)

The operation failed or the command syntax was not valid.

66 (EX_NOINPUT)

A specified configuration file could not be loaded.

70 (EX_SOFTWARE)

libopts had an internal operational error. Please report it to autogen-users@lists.sourceforge.net. Thank you.


Next: , Previous: , Up: sntp Invocation  

1.1.18 sntp Usage


Previous: , Up: sntp Invocation  

1.1.19 sntp Authors


Previous: , Up: sntp Description  

1.2 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