On the Linux side of the world you need a configured /etc/ntp.conf
that looks like this:
fudge 127.127.1.0 stratum 10
restrict default ignore
restrict 127.0.0.1 mask 255.0.0.0
restrict 192.168.2.1 mask 255.255.255.255
In this example, 192.168.2.1 is the address of your time server.
From you Linux system you should be able to ping
the time server; e.g.,
ping -c 5 192.168.2.1
(obviously, substitute the actual address of your time server).
Now, NTPD (the NTP daemon) on your Linux system, is started at boot; the typical command looks like this:
# Start ntpd:
echo -n "Starting NTP daemon: $CMDLINE"
$CMDLINE -p /var/run/ntpd.pid
Your locations may vary from the above, but look for the daemon start in /etc/init.d
or one of the /etc/rc[0-6].d
directories, depending upon where your service start files are located in /etc
. The important thing is that the daemon is started with /usr/sbin/ntpd -g -p /var/run/ntpd.pid
allows the first time adjustment to be big (NTPD will not synchronize if the time is more than about five minutes off). Again, the location of the executable ntpd
may not be in /usr/sbin
on your system, use the whereis
utility to find it.
You don't want to start it in a cron job, you want it to start at boot and run "forever."
Once NTPD has started, it can take 5-to-10 minutes for it to synchronize with your time server (it can take up to half an hour). You use the ntpq
utility to view the status:
remote refid st t when poll reach delay offset jitter
*192.168.2.1 188.8.131.52 3 u 916 1024 377 0.367 7.897 2.552
LOCAL(0) .LOCL. 10 l 10h 64 0 0.000 0.000 0.000
The asterisk means it's synchronized; before it syncs, the asterisk will be on the LOCAL line in the ntpq
You will need to, as root,
once (your log entries will go in there).
You can use ntpdate
to set the system clock at boot if you don't want to use the daemon; however, if the system is running long-term (over days or weeks), it's better to use the daemon -- it will "walk" your system clock into synchronization over time, applying the drift value (which is kept in /etc/ntp/drift
) to slowly adjust the system clock into accuracy.
One function of the "init" functions (the ones that start system services) is that NTPD will read time from the hardware clock to initially set the system clock. NTPD runs, synchronizes your system clock then, at shutdown, saves that synchronized (accurate) time to the hardware clock (which runs on the battery while the power is off). That generally keeps your system on-time within a few milliseconds.
Hope this helps some.
Note: the above example is taken from Niki Kovacs' article at http://docs.slackware.com/howtos:network_services:ntp
. Although the article is Slackware-centric, it serves as a good guide to setting up NTP on a LAN.