NTP
From HerzbubeWiki
Contents |
Debian packages
Debian package required to run an NTP daemon that synchronizes local time, but also provides a time sync service to clients:
ntp
Debian package required to simply synchronize local time:
ntpdate
Documentation package:
ntp-doc
References
- NTP documentation @ pelargir.herzbube.ch (available only if the
ntp-docpackage is installed): Main page with overview information, the Sitemap is more useful to quickly find stuff - A list of public time servers : http://www.eecis.udel.edu/~mills/ntp/servers.html
Glossary
- Stratum 1 = Primary Server
- Stratum 2 = Secondary Server
- [...]
System time vs. hardware clock
Edit
/etc/init.d/hwclock.sh
- Comment (= disable) the line where hwclock is run with the parameter --adjust, in order to prevent conflicts between hwclock and NTP
- Uncomment (= enable) the line where hwclock is run with the parameter --systohc, in order to write the system time to the hardware clock on reboot
Note: I have not enabled this option.
NTP daemon
Local time sync
To activate an NTP server
- Add the following lines to /etc/ntp.conf if they don't exist
driftfile /var/lib/ntp/ntp.drift server ntp.foobar.org
- Restart the NTP server
- Wait some time until system time has been updated. When I first experimented with NTP on my old server
osgiliathI had to wait up to half an hour until the time sync occurred. On my new serverpelargir, however, time sync happened immediately after the daemon restart. - It is important that the system time is not out-of-sync more than 1000 seconds, otherwise ntp refuses to automatically correct the system time ("time correction exceeds sanity limit")
These days on my new server pelargir I simply use the default configuration in /etc/ntp.conf which seems to work out of the box. The servers configured there are
0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org
Provide time to clients
The configuration file /etc/ntp.conf mentions that, in order to provide time to clients a "broadcast" line needs to be enabled. For instance
broadcast 192.168.1.255 broadcast 192.168.2.255
However, I did not enable these commands because so far my Mac OS X clients were perfectly able to synchronize, once I told them where they were supposed to connect to (System Preferences > Date & Time).
Note: I added a "time-servers" option to my DHCP configuration (e.g. "time-servers 192.168.1.11" on the 192.168.1.0 subnet), but at the time of writing Mac OS X did not honor this option (Mac OS X 10.6). I have not yet tested how Windows behaves.
pool.ntp.org
A long time ago, on my old server osgiliath I tried to use the server pool.ntp.org - which is supposed to assign a different NTP server to my client every time my client is restarted. Unfortunately, pool.ntp.org never seemed to work, even after several attempts to use it. The system time never got corrected - the drift grew to 40 minutes and more until I had to manually re-adjust the system time. Nowadays pool.ntp.org may work better, but when I had trouble with it I instead connected to
time.euro.apple.com
ntpdate
The Debian package ntpdate provides the utility ntpdate which can be used to immediately adjust the system date at the time when the utility is run. For instance:
ntpdate time.euro.apple.com
For continuous time sync, I add the following crontab entry:
pelargir:~# ls -l /etc/cron.hourly/pelargir-ntpdate -rwxr-xr-x 1 root root 56 2011-02-09 19:15 /etc/cron.hourly/pelargir-ntpdate pelargir:~# cat /etc/cron.hourly/pelargir-ntpdate #!/bin/sh /usr/sbin/ntpdate -u -s time.euro.apple.com
There is also the utility ntpdate-debian which uses the configuration in the following file
/etc/default/ntpdate
ntpq
ntpq is the standard NTP query program. For instance, it can be used to check the current time source
ntpq -pn
(the source is the line with the asterisk)
For example:
root@pelargir:~# ntpq -pn
remote refid st t when poll reach delay offset jitter
==============================================================================
+217.147.208.1 194.242.34.149 2 u 61 64 3 9.450 -10.368 10.087
+192.33.214.57 129.194.216.1 3 u 55 64 7 13.198 -10.532 8.899
+94.23.99.155 94.23.99.153 3 u 31 64 7 27.351 -5.038 7.588
*192.33.96.102 .PPS. 1 u 24 64 17 9.889 -12.321 11.285
