Sync NTP server at specific times

Q I have an old box running Mandrake 8.2 as a home server for about six other PCs in the house. We are still on ISDN dial-up as there is no pressing need to upgrade to broadband. I have been using NTP fine for the past few months to update the server's clock once a week. I have a simple Cron job that connects to the internet, calls ntpdate to sync the time with one of the NTP servers at, then disconnects from the internet. The next stage is to get the client PCs to sync to the server's time. I cannot use ntpdate on the server as it is a one-off command rather than a daemon, so I have to use ntpd, the actual NTP daemon.

Now that I've finally figured out to set it up - the NTP documentation reads like an astrophysics PhD thesis rather than a user's guide - I can indeed sync the client PCs to the server, but the NTP daemon tries to sync to a server on the internet every few minutes, and most of the time this fails as the net connection happens to be down. Basically, how can I use ntpd but force it to only sync with a server on the internet at specific times? Alternatively, is it possible to use my ntpdate Cron job but run a separate NTP server that takes the current system time and serves that to the client PCs?

A Most NTP servers, including ntpd and openntpd, are designed to be used with a permanent internet connection. Liaising with other time servers is an integral part of the way they work, making them unsuitable for your needs. Chrony is designed to provide time services to a network with an intermittent, or even non-existent, internet connection. It consists of two programs: chronyd is the daemon, providing time services based on the system clock; chronyc is a command line program that can be run from your cron script to synchronise the clock with another time server. Get the latest version at You will need to compile it from source, but this is straightforward and clearly documented in the INSTALL file. The documentation is verbose, but setting up a basic server is quite simple. Put the following lines into/etc/crony.conf, replacing each nnn.nnn.nnn.nnn with the IP address of a server.

server nnn.nnn.nnn.nnn offline
server nnn.nnn.nnn.nnn offline
server nnn.nnn.nnn.nnn offline
keyfile /etc/chrony.keys
commandkey 1
driftfile /etc/chrony.drift
allow 192.168.1

You can obtain a list of suitable servers with

netselect -s 3

The 'offline' parameters stop chrony trying to synchronise with the servers, which is what you want. The allow command indicates the IP range allowed to get time for the server. Set up a password with

echo >/etc/chrony.keys '1 somepassword'

Then start the daemon with the supplied init script. Now it will serve time to your network based on its system clock. To update the system clock, amend your Cron script to do this after connecting:

/usr/local/bin/chronyc EOF password somepassword

Repeat it before disconnecting, changing online to offline.

Follow us on or Twitter

Username:   Password:
Create Account | About TuxRadar