ntpdate4 Command

Purpose

Sets the date and time using the Network Time Protocol (NTP).

Syntax

ntpdate4 [ -4] [ -6] [ -a key] [ -B ] [-b ] [-d] [-e authdelay] [ -k keyfile] [ -o version] [ -p samples] [-q] [-s] [ -t timeout] [ -u ] [ -v ] server [...]

Description

The ntpdate command sets the local date and time by polling the Network Time Protocol (NTP) server(s) given as the server arguments to determine the correct time. The ntpdate must be run as root on the local host. Samples are obtained from each of the servers specified and a subset of the NTP clock filter and selection algorithms are applied to select the best. Note that the accuracy and reliability of ntpdate depends on the number of servers, the number of polls each time it is run and the interval between runs.

The ntpdate can be run manually as necessary to set the host clock, or it can be run from the host startup script to set the clock at boot time. This is useful in some cases to set the clock initially before starting the NTP daemon ntpd. It is also possible to run ntpdate from a cron script. However, it is important to note that ntpdate with contrived cron scripts is not a substitute for the NTP daemon, which uses complex algorithms to maximize accuracy and reliability while minimizing resource use. Finally, since ntpdate does not tune the host clock frequency as does ntpd, the accuracy using ntpdate is limited.

Time adjustments are made by ntpdate in one of two ways. If ntpdate determines that the clock is in error of more than 0.5 seconds it will simply step the time by calling the system settimeofday() routine. If the error is less than 0.5 seconds, it will slew the time by calling the system adjtime () routine. The latter technique is less disruptive and more accurate when the error is small, and works quite well when ntpdate is run by cron every hour or two.

The ntpdate will decline to set the date if an NTP server daemon (ntpd) is running on the same host. When running ntpdate on a regular basis from cron as an alternative to running a daemon, doing so once every hour or two will result in precise enough timekeeping to avoid stepping the clock.

Note: Where a host name is expected, a -4 qualifier preceding the host name forces DNS resolution to the IP version 4 namespace, while a -6 qualifier forces DNS resolution to the IP version 6 namespace.

Flags

Item Description
- 4 Forces DNS resolution of following host names on the command line to the IP v4 namespace
- 6 Forces DNS resolution of following host names on the command line to the IP v6 namespace.
- a key Enables the authentication function and specifies the key identifier to be used for authentication as the argument keyntpdate. The keys and key identifiers must match in both the client and server key files. The default is to disable the authentication function.
- B Forces the time to be slewed using the adjtime () system call, even if the measured offset is greater than + or - 128 millisecond. The default is to step the time using settimeofday () if the offset is greater than + or -128 millisecond. Note that, if the offset is much greater than + or -128 millisecond in this case, that it can take a long time (hours) to slew the clock to the correct value. During this time the host should not be used to synchronize clients.
- b Forces the time to be stepped using the settimeofday () system call, rather than slewed (default) using the adjtime () system call. This option should be used when called from a startup file at boot time.
- d Enables the debugging mode, in which ntpdate will go through all the steps, but not adjust the local clock. Information useful for general debugging is also printed.
- e authdelay Specifies the processing delays to perform an authentication function as the value authdelay, in seconds and fraction (See the ntpd for more details). This number is usually small enough to be negligible for most purposes, though specifying a value may improve timekeeping on very slow CPUs.
- k keyfile Specifies the path for the authentication key file as the string keyfile. The default is /etc/ntp.keys.
- o version Specifies the NTP version for outgoing packets as the integer version, which can be 1 or 2. The default is 3. This allows ntpdate to be used with older NTP versions.
- p samples Specifies the number of samples to be acquired from each server as integer samples, with values from 1 to 8 inclusive. The default value is 4.
- q Specifies the query. Does not set the clock.
- s Diverts logging output from the standard output (default) to the system syslog facility. This is designed primarily for convenience of cron scripts.
- t timeout Specifies the maximum time waiting for a server response as the value timeout, in seconds and fraction. The value is rounded to a multiple of 0.2 seconds. The default is 1 second, a value suitable for polling across a LAN.
- u Directs ntpdate to use an unprivileged port or outgoing packets. You can use this option when behind a firewall that blocks incoming traffic to privileged ports, and you want to synchronize with hosts beyond the firewall. Note that the -d option always uses unprivileged ports.
- v Verbose output. This option causes the ntpdate version identification string to be logged.

Parameters

Item Description
Server... Specifies the servers to poll

Exit Status

This command returns the following exit values:
Item Description
0 Successful completion.
>0 An error occurred.

Security

Item Description
Access Control You must have root privilege to run this command.
Auditing Events N/A

Examples

  1. To set the local date and time by polling the NTP servers at address 9.41.254.24, enter:
    ntpdate 9.41.254.24
    Output similar to the following appears:
    address: ::
    address: 0.0.0.0
    25 Feb 12:19:41 ntpdate[434262]: adjust time server 9.41.254.24 offset -0.005270  sec

Files

Item Description
/usr/sbin/ntp4/ntpdate4 Contains the ntpdate command for NTP version 4.

Default Symbolic link to NTP version 4 binary from /usr/sbin directory.

/usr/sbin/ntpdate --> /usr/sbin/ntp3/ntpdate
/etc/ntp.keys Encryption keys used by ntpdate.