sntp Command for NTPv4
Purpose
The sntp command queries a Network Time Protocol (NTP) server and displays the offset time of the system clock with respect to the server clock.
Syntax
Description
The sntp program is a Simple Network Time Protocol (SNTP) client that is used
to query a Network Time Protocol (NTP) server. The sntp command displays the
offset time of the system clock with respect to the server clock. If the root user of the system
runs the sntp command, the sntp command corrects the
system-offset time. The sntp command can be executed as an interactive command or
from a script in a cron
job. The sntp command implements the
SNTP protocol that is defined in RFC 5905, including the full on-wire protocol. The
sntp command does not provide the sanity checks, access controls, security
functions, and mitigation algorithms as defined in the full NTP version 4 (NTPv4) specification that
are also defined in RFC 5905.
By default, the sntp command displays the local date and time to the standard output in a format similar to the following format:
2011-08-04 00:40:36.642222 (+0000) +0.006611 +/- 0.041061 psp-os1 149.20.68.26 s3 no-leap
Where +0.006611 +/- 0.041061
indicates the time offset and error bound of the
system clock with respect to the server clock, in seconds. The hostname, host IP address, stratum of
the server, and leap indicator status are also displayed by the sntp command.
Flags
Item | Description |
---|---|
-?, --help | Displays usage information. |
-4, --ipv4 | Forces DNS resolution of hostnames to the IP version 4 (IPv4) namespace. |
-6, --ipv6 | Forces DNS resolution of hostnames to the IP version 6 (IPv6) namespace. |
-a keynum, --authentication keynum | Enables authentication with the key ID that is specified by the keynum variable. The key ID is a number that is specified in the key file along with an authentication password. For more information about the key file, see the -k option. |
-b bcaddress, --broadcast bcaddress | Listens for the NTP packets that are sent to the broadcast or multicast address that is specified by the bcaddress variable. The broadcast or multicast address is a DNS name or IP address. The default maximum wait time to listen for broadcast or multicast NTP messages is 68 seconds. The wait time to listen for broadcast or multicast NTP messages can be modified by using the -B option. |
-B bctimeout, --bctimeout bctimeout | Sets the wait time to listen for the broadcast or multicast NTP messages. The wait time is specified by the bctimeout variable. The default wait time is 68 seconds, as the ntpd command transmits broadcast or multicast NTP messages every 64 seconds. |
-c, --concurrent | Concurrently queries all the addresses that are returned for hostname resolution. Requests from an NTP client to a single server can be sent only once every two seconds. By default, all the addresses that are resolved from a single hostname are assumed to be for a single instance of the ntpd command. The sntp command sends queries to the addresses that are resolved from a single hostname, one after another, waiting for two seconds between the queries. The sntp command can send concurrent queries because the multiple addresses that are returned for a hostname are on different machines. |
-d, --debug-level | Increases the debug verbosity level by one. The -d option can be specified multiple times. You can also set the debug verbosity level to a specific level by using the -D option. |
-D debug-level, --set-dubug-level debug-level | Sets the debug verbosity level to the level specified by the debug-level variable. The default debug verbosity level is zero. You can also use the -d option to increase the debug verbosity level by one. |
-g delay, --gap delay | Sets the delay time between two outgoing queries. The delay time is specified by the delay variable, in milliseconds. The default delay time is 50 ms. The sntp command sends queries to all the provided hostnames or addresses in short succession. By default, the sntp command terminates once the first valid response is received for the queries sent. With the multiple number of time sources, only one valid response for the queries that are sent by the sntp command is used. To limit the number of queries whose responses are not used, each query is separated from the preceding one by the specified delay time. The delay between two queries gives time to receive a response for the earlier query. A larger delay time between two queries reduces the query load on the time sources by increasing the time to receive a valid response if the first time source attempted is slow or unreachable. |
-k keyfile, --keyfile keyfile | Specifies the key file name that must be used with the -a option. The key file name is specified with the keyfile variable. For more information about the format of the key file, see the ntp-keygen Command for NTPv4 topic. |
-K kodfile, --kod kodfile | Specifies the file path that must be used for the persistent history of kiss-of-death (KoD) or rate-limiting responses that are received from the servers. The file path is specified by the kodfile variable. The default file path is /var/db/ntp-kod. If the file specified by the kodfile variable does not exist, a warning message is displayed. However, a new file is not created. |
-l logfile, --filelog logfile | Specifies the file name to which a copy of the status message is appended. The status message also appears on the terminal. |
-M steplimit, --steplimit steplimit | Specifies the offset limit in milliseconds to decide whether to correct the time by slewing the clock or by setting the clock to the correct time. If the offset is less than the offset limit specified by the steplimit variable, the time is corrected by slewing the clock by using the adjtime subroutine. If the offset is equal to or greater than the offset limit specified by the steplimit variable, the time is corrected by setting the clock to the correct time. |
-o ntpver, --ntpversion ntpver | Specifies the NTP protocol version number to include in the requests. The NTP protocol version number is specified by the ntpver variable. The default value is 4. |
-r, --usereservedport | Directs the sntp command to use the reserved NTP port 123
to query the NTP server. When the -r option is not used, by default the
sntp command uses a User Datagram Protocol (UDP) source port number that the
operating system selects. The -r option requires a root user to run the
sntp command. This feature helps to identify connectivity failures due to
port-based firewalling that affects the ntpd command. The ntpd
command always uses the NTP source port 123 . |
-s, --slew | Enables offset correction by slewing with the help of adjtime subroutine. This option changes the rate of the clock for a period long enough to accomplish the required offset correction. The -s option requires a root user to run the sntp command. |
-S, --step | Enables offset correction by stepping where the clock is directly set to the correct time. The -S option requires a root user to run the sntp command. |
-u uctimeout, --uctimeout uctimeout | Specifies the maximum time to wait for a unicast response before the sntp command terminates, in seconds. The maximum time to wait is specified by the uctimeout variable. |
--wait | Causes the sntp command to wait for the responses of all the pending queries. When -s or -S options are not specified, the sntp command terminates after the first valid response is received. However, when --wait option is specified, the sntp command waits for all the pending queries to respond. |
--version | Displays the version number of the sntp program and the date and time when it was compiled. |
Parameters
Item | Description |
---|---|
address | NTP server address. |
Exit status
Item | Description |
---|---|
Zero | Successful completion. |
Nonzero | An error occurred. |
Security
- Access Control
- You must be a part of the system group to run this command.
Files
- /usr/sbin/ntp4/sntp4
- Contains the sntp daemon for NTPv4.
- /usr/sbin/sntp-->/usr/sbin/ntp4/sntp4
- The default symbolic link to the NTP version 4 binary file from the /usr/sbin directory.
Example
To get the time offset of the system clock relative to the server (9.41.254.24) clock, enter the following command:
sntp 9.41.254.24
The following output appears:
2009 Feb 25 12:28:38.00620 - 0.00679 +/- 0.31077 secs