ntpd(8)
Name
ntpd − network time protocol (NTP) daemon
Syntax
/usr/etc/ntpd [ −a threshold ][ −c file ][ −d ][ −D level ][ −l ][ −n ][ −s ]
Description
The University of Maryland’s ntpd daemon synchronizes the local clock with a set of distributed time servers. The ntpd daemon distributes accurate, reliable time from the best time source available at your site to hosts on wide area networks (WAN) and local area networks (LAN). The three recommended time sources in decreasing order of accuracy are: Internet NTP service, local radio clock, and wristwatch. Note that the ntpd daemon does not require time servers to be on the same LAN as time clients, and does not create a heavy broadcast load on the network.
Note
If the NTP servers are not on your Local Area Network (LAN), you must run the routed daemon before running the ntpd daemon. To run routed, remove the number signs (#) from in front of the following lines in your /etc/rc.local file:
#[ −f /etc/routed ] && {
# /etc/routed & echo ’routed’ >/dev/console
#}
The routed daemon will be invoked when you reboot your system. To start routed without rebooting, type the following on the command line:
/etc/routed
For information on setting up the network time services, see the Guide to System and Network Setup.
The ntpd daemon automatically splits the nodes running the ntpd daemon into a dynamically reconfigurable hierarchy of nodes. The nodes at the top level of the hierarchy (low stratum numbers) are connected to the most accurate sources available. This information is transferred to the lower-level nodes (higher stratum numbers) which set their clocks based on the calculated offset from a remote server, and then distribute this time to lower levels of the hierarchy.
The ntpd daemon provides a solution for distributing time to a large number of individual workstations. It can also be used in conjunction with a master timed daemon to distribute NTP time to workstations running timed. If timed is run with the −E and −M options on at least one system that is also running ntpd, then all other systems on the network running timed can receive time updates from a host running ntpd. Although timed is easier to set up on clients, NTP is recommended because it is more accurate and more secure.
Normally, the ntpd daemon is invoked at boot time from the /etc/rc.local file. When ntpd is started, it reads configuration information from the /etc/ntp.conf file, unless you have specified another configuration file with the −c option. The configuration file either specifies the list of NTP servers with which this host should synchronize, or identifies this host as a local reference clock. See the ntp.conf() reference page for more information on the /etc/ntp.conf configuration file.
The ntpd daemon uses the adjtime() system call to gradually adjust the local clock for small clock offsets (< 0.128 seconds). If the local clock lags the time on the server by more than 0.128 seconds, the settimeofday() system call is used to make a forward step adjustment of the local clock. Clocks are never stepped backwards; they are adjusted gradually, which can take a very long time. Therefore, it is important to initialize the time using the ntp command before running the ntpd daemon.
Options
−a threshold
Sets the threshold (in seconds) which limits how far the ntpd daemon can change the local clock. By default, the threshold is 1000 seconds. This is set to avoid propagating major mistakes throughout the network. If you specify the string any instead of a number, the ntpd daemon can change the local clock by any amount.
−c file
Specifies a configuration file for the ntpd daemon. By default, the configuration file is /etc/ntp.conf.
−dIncrements the debug level by one. The −d option can be specified more than once. Higher debug levels provide more diagnostic information.
−D level
Sets the debug level to the specified value.
−lCauses the ntpd daemon to log a message each time the local clock is adjusted. Specify this option only if you want to gather statistical information to analyze the local clock behavior. If the −l option is set, a message may be logged every two minutes. Messages are logged to /usr/spool/mqueue/syslog.
−nInhibits the ntpd program from being swapped out of memory. Using the −n option is recommended for both time servers and time clients.
−sPrevents the ntpd daemon from altering the time on the local host. The ntpd daemon participates as an NTP server with the −s flag set, but it does not change the time of the local host.
Examples
Before starting the ntpd daemon, either manually or from the /etc/rc.local file, you must edit the /etc/ntp.conf file with the appropriate information. If your system is a client you must specify the time servers for it to query. If it is a time server, you must specify the time servers with which it peers. See the ntp.conf() reference page for more information.
To start the ntpd daemon manually (on a time client), enter the following commands:
# /etc/rdate −s
# /usr/etc/ntp −s −f server1 server2 server3
# /usr/etc/ntpd −n
The /etc/rdate command initializes your time to the average network time. The /usr/etc/ntp command further refines the initial time to the NTP time. The servers specified on the command line are the same as those specified in the /etc/ntp.conf file.
To start the ntpd daemon from the /etc/rc.local file (on a time client), place the following entries in the /etc/rc.local file. Multiple servers are included in case one of the servers crashes, or is brought down. The servers specified in the /etc/rc.local file are the same as those specified in the /etc/ntp.conf file. These entries should be placed after the syslog entry:
[−f /etc/syslog] && {
/etc/syslog & echo −n ’ syslog’ >/dev/console
}
[−f /etc/rdate] && {
/etc/rdate −s & echo −n ’ rdate’ >/dev/console
}
[−f /usr/etc/ntp] && {
/usr/etc/ntp −s −f server1 server2 server3 \
& echo −n ’ ntp’ >/dev/console
}
[−f /usr/etc/ntpd] && {
/usr/etc/ntpd −n & echo −n ’ ntpd’ >/dev/console
}
Diagnostics
The ntpd daemon logs errors, major state changes, and statistics reports using the syslog daemon; the log entries appear in the file /usr/spool/mqueue/syslog with the word ntpd: on each relevant line. Normal log entries show when ntpd gains or loses synchronization with a lower-stratum host. Also, once an hour ntpd issues a ntpd: stats: entry that gives information about its state.
Once an hour, if ntpd is synchronized, it updates the /etc/ntp.drift file. This file shows the estimated clock drift for each of the past 5 hours, with the most recent hour listed first. (The 6th number in this file is the number of hours ntpd has been running). To convert the drift values to parts per million (ppm), divide them by 4096 and multiply by 1000000. For example, +0.0107001161 means that ntpd estimates that the clock is drifting by about 2.61 ppm, or is losing about 0.226 seconds per day. [(2.61/1000000) * 24 * 60 * 60 = 0.226]. Negative drift values mean that the clock is gaining time. If ntpd is working, your computer’s clock should be accurate to within a few seconds per day.
Another diagnostic tool is the ntpdc command. You can use this to look at any host running ntpd. The following command line returns the state of the remote host’s ntpd server:
% /usr/etc/ntpdc hostname
The value that is returned for the offset should contain values not greater than 100 milliseconds. See the ntpdc() reference page for more information.
If the ntpd daemon sets the time as frequently as every 10 minutes (indicated by messages in the /usr/spool/mqueue/syslog file), then you should kill the ntpd daemon, remove the /etc/ntp.drift file, run the ntp command to initialize the time, and restart the ntpd daemon.
If your system clock is ahead of the server time by more than 1 second, you should kill the ntpd daemon, remove the /etc/ntp.drift file, run the ntp command to initialize the time, and restart the ntpd daemon.
If your clock is more than 1000 seconds off from the server time, and you did not specify the −a any option, ntpd will not change your system time. Rather, ntpd will repeatedly log messages to the /usr/spool/mqueue/syslog file, indicating that the time is too far off to reset.
See Also
ntp(1), adjtime(2), settimeofday(2), ntp.conf(5), ntpdc(8), timed(8)
RFC 1129—Internet Time Synchronization: the Network Time Protocol
Guide to System and Network Setup
Introduction to Networking and Distributed System Services