Ntp client only

From LinuxNewbie

Configuring the NTP Daemon excerpted from http://www.halley.cc/ed/linux/howto/ntp.html ( Text, code, layout and artwork are Copyright © 1996-2002 Ed Halley. Copying in whole or in part, with author attribution, is expressly allowed.)

There is a list of publically accessible NTP servers at http://www.eecis.udel.edu/~mills/ntp/servers.htm, or see the actual NTP informational homepage at http://www.eecis.udel.edu/~ntp/ for other details.

Red Hat Linux comes with a sample /etc/ntp.conf, but if you just want your machine to synchronize with a public server, I recommend removing that file and starting with a far simpler script. Remove the existing file and create one thatlooks like the following.

/etc/ntp.conf (complete sample file)

# A very simple client-only ntp configuration.
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
driftfile /etc/ntp/drift
restrict default ignore
restrict 127.0.0.0 mask 255.0.0.0
authenticate no

Choose your preferred NTP servers. Note that some servers are not availableto the public, and some servers are too busy to handle new requests. Please do your homework in choosing appropriate servers that are geographically near you, and which will accept new public connections, and whether you must obtain their permission first.

You should select two or three servers for best results. For each server you find, discover its hostname and its fixed numerical address. Then add lines like the following to the /etc/ntp.conf file you created above.

/etc/ntp.conf (additional lines for each server)

server ntp5.someserver.etc
restrict 123.123.123.123 nomodify  # ntp5.someserver.etc

Next, a separate ticker file must be created that lists the servers. The following command will read the /etc/ntp.conf file you've made, and create the proper list of servers for the ticker file. This finds the hostnames listed on lines beginning with 'server', except for the initial 127.127.1.0 local clock, and lists them in the ticker file.

$ su -
# awk '/^server/ {print $2}' /etc/ntp.conf | grep -v '127.127.1.0' > /etc/ntp/step-tickers

Before starting the service, roughly synchronize your clock using one of the servers with ntpdate. Ensure your configuration is set to run the NTP daemon ntpd to track and alleviate clock drifting.

Red Hat/Fedora Core example:

$ su -
# chkconfig --list ntpd
ntpd        0:off   1:off   2:off   3:off   4:off   5:off   6:off
# ntpdate -u ntp5.someserver.etc
 9 Dec 15:15:15 ntpdate[12345]: step time server 123.123.123.123 offset 7.879896 sec
# chkconfig --level 345 ntpd on

If your system clock is likely more than a few minutes off, it is best to shut down as many applications as possible before performing gross clock corrections. Some programs may have bugs which cause themto lose data or crash. A minimal environment such as running at runlevel 1 (single user mode) is the ideal situation for drastic clock changes.