sntp

A Simple Network Time Protocol (sntp) client program (command and daemon).

Syntax
      sntp [ -h | --help | -? ] [ -v | -V | -W ] [ -q [ -f savefile ] | [ { -r | -a } [ -P maxerr ]
         [ -l lockfile ] ] [ -e minerr ] [ -E maxerr ] [ -c count ] [ -d delay | -x [ separation ] ]
            [ -f savefile ] ] [ -4 ] | [ -6 ] [ address(es) ] ] 

Options
   
   -h   Display a syntax error message.
        If there are no other arguments, it then stops; otherwise it then does what was requested.
        --help and -? are synonyms.

   -v   Diagnostic messages for non-fatal errors and a limited amount of tracing should be written to standard error.
        Fatal errors always produce a diagnostic. This option should be set when there is a suspected problem with
        the server, network or the source.

   -V   Request more and less comprehensible output, mainly for investigating problems with apparently inconsistent
        timestamps. This option should be set when the program fails with a message indicating that is the trouble. 

   -W   Request very verbose debugging output, and will interfere with the timing when writing to the terminal
        (because of line buffered output from C). Note that the times produced by this are the corrections needed,
        and not the error in the local clock. This option should be set only when debugging the source. 

   -q   Query a daemon save file being maintained by it.
        This needs no privilege and will change neither the save file nor the clock.

        The default is that it should behave as a client, and the following options are then relevant:

   -r   The system clock should be reset by settimeofday. This will work only if the user has enough privilege.

   -a   The system clock should be reset by adjtime. This will work only if the user has enough privilege.

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 Oct 15 20:17:25.123 + 4.567 +/- 0.089 secs', where the '+ 4.567 +/- 0.089 secs' indicates the estimated error in the time on the local system. In daemon mode, it will add drift information in a format like ' + 1.3 +/- 0.1 ppm', and display this at roughly separation intervals (see under the -x option for details).

   -l lockfile
        Set the name of the lock file to ensure that there is only one copy of sntp running at once.
        The default is installation-dependent, but will usually be /etc/sntp.pid.

   -e minerr
        Set the maximum ignorable variation between the clocks to minerr.
        Acceptable values are from 0.001 to 1, and the default is 0.1 if a NTP host is is specified and 0.5 otherwise.

   -E maxerr
        Set the maximum value of various delays that are deemed acceptable to maxerr.
        Acceptable values are from 1 to 60, and the default is 5. It should sometimes be increased if there are problems
        with the network, NTP server or system clock, but take care.

   -P maxerr
        Set the maximum clock change that will be made automatically to maxerr.
        Acceptable values are from 1 to 3600 or no, and the default is 30.

        If the program is being run interactively in ordinary client mode, and the system clock is to be changed, larger
        corrections will prompt the user for confirmation. Specifying no will disable this and the correction will be
        made regardless.

   -c count
        Set the maximum number of NTP packets required to count.
        Acceptable values are from 1 to 25 if a NTP host is specified and from 5 to 25 otherwise, and the default is 5.
        If the maximum isn't enough, the system needs a better consistency algorithm than this program uses.

   -d delay
        Sets a rough limit on the total running time to delay seconds.
        Acceptable values are from 1 to 3600, and the default is 15 if a NTP host is specified and 300 otherwise.

   -x separation
        causes the program to run as a daemon (i.e. forever), and to estimate and correct for the clock drift.
        Separation sets the minimum time between calls to the server in minutes if a NTP host is specified,
        and between broadcast packets if not.
        Acceptable values are from 1 to 1440 (a day), and the default (if -x is specified but separation is omitted) is 300.

   -f savefile
        may be used with the -x option to store a record of previous packets, which speeds up recalculating the drift
        after sntp has to be restarted (e.g. because of network or server outages).

        In order to restart the data, sntp must be restarted reasonably soon after it died (within a few times the value
        of separation), with the same value of the -c option, the same value of separation, in the same mode (i.e. broadcast
        or client), though the NTP servers need not be the same for client mode, and with compatible values of other settings.

        Note that the file will be created with the default ownerships and permissions, using standard C facilities.
        The default is installation-dependent, but will usually be /etc/sntp.state. 

   -4    Force IPv4 DNS resolution.
   -6    Force IPv6 DNS resolution.

address(es) are the DNS names or IP numbers of hosts to use for the challenge and response protocol; if no names are given, the program waits for broadcasts. Polling a server is vastly more reliable than listening to broadcasts. Note that a single component numeric address is not allowed, to avoid ambiguities. If more than one name is give, they will be used in a round-robin fashion.

Constraints:

None of the above values are closely linked to the limits described in the NTP protocol (RFC 1305).

sntp can be used as a 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, in a cron job or as a daemon. It can be run as a daemon to provide a SNTP server for other clients. NTP is the Network Time Protocol (RFC 1305) and SNTP is the Simple Network Time Protocol (RFC 2030, which supersedes RFC 1769).

Public NTP servers

url Public NTP server Stratum  
time.nist.gov NIST Internet Time Service 1 From the NIST Physical Measurement Laboratory, maintains the standard for frequency and time interval for the United States.
Also time-a-wwv.nist.gov ... time-d-wwv.nist.gov
time.apple.com Apple time server. 1 Also for Europe: time.euro.apple.com and time.asia.apple.com.
time.google.com Google time server. 1 Serves leap-smeared time, to smoothly handle leap seconds with no disruptive events.
Also time1.google.com ... time4.google.com
pool.ntp.org NTP Pool project 1-3 A very large virtual cluster of timeservers. IPv4 only. Rules of Engagement.
Many standard Linux distributions use this.
Also 0.pool.ntp.org ... 3.pool.ntp.org
time.windows.com Microsoft time server. 3 IPv4 only.
Azure hosts are synchronized to internal Microsoft time servers that take their time from Microsoft-owned Stratum 1 devices, with GPS antennas.

Many other public NTP servers exist, choose one that is geographically close to your datacentre.

When comparing times, repeat the commands several times and take an average.

When used as a client in non-daemon mode, the program returns a zero exit status for success, and a non-zero one otherwise.
When used as a daemon (either client or server), it does not return except after a serious error.

The program implements the SNTP protocol, and does not provide all NTP facilities. In particular, it contains no checks against any form of spoofing. If this is a serious concern, some network security mechanism (like a firewall or even just tcpwrappers) should be installed.

There are some errors, ambiguities and inconsistencies in the RFCs, and this code may not interwork with all other NTP implementations. Any unreasonable restrictions should be reported as bugs to whoever is responsible. It may be difficult to find out who that is.

The program will stop as soon as it feels that things have got out of control. In client daemon mode, it will usually fail during an extended period of network or server inaccessibility or excessively slow performance, or when the local clock is reset by another process. It will then need restarting manually. Experienced system administrators can write a shell script, a cron job or put it in inittab, to do this automatically.

The error cannot be estimated reliably with broadcast packets or for the drift in daemon mode (even with client-server packets), and the guess made by the program may be wrong (possibly even very wrong). If this is a problem, then setting the -c option to a larger value may help. Or it may not.

Examples

Check the current time and error in the local clock against NTP:

$ sntp 0.pool.ntp.org

Sync the time with a the NIST server:

$ sudo sntp -a time.nist.gov

Run as a daemon to keep the local clock in step:

$ sudo sntp -a -x time.nist.gov

"First rate people hire other first rate people. Second rate people hire third rate people. Third rate people hire fifth rate peopleโ€ ~ André Weil

Related Linux commands


Equivalent Windows command: w32tm


 
Copyright © 1999-2026 SS64.com
Some rights reserved