Jump to content

How to build a local time server

  carlaschroder's Photo
Posted Aug 25 2009 03:04 PM

If you want to set up a local time server, use ntp. It will synchronize with a public time server, and your LAN clients will connect to the local machine. This example assumes the PC acting as the local time server has a full-time Internet connection.

First, install or upgrade ntp on the PC that is going to act as a time server for your LAN. You'll also want ntpdate .

Next, make sure the ntp daemon is not running:

# /etc/init.d/ntpd stop

On Debian, use:

# /etc/init.d/ntp-server stop

Make these entries in /etc/ntp.conf, and create the driftfile and logfile if they do not already exist. root should own them (chmod 644).


driftfile  /etc/ntp.drift

logfile  /var/log/ntp.log


server pool.ntp.org

server pool.ntp.org

server pool.ntp.org

Make the initial time correction with ntpdate:

# ntpdate pool.ntp.org

Then start up ntpd:

# /etc/init.d/ntpd start

On Debian, use:

# /etc/init.d/ntp-server start

Use ntpq to see which servers you're connected to:

# ntpq -p

 remote refid st t when poll reach delay offset jitter

 =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  = 

 =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =

 +clock.fmt.he.ne .GPS. 1 u 37 64 377 105.562 26.771 2.539

 +dewey.lib.ci.ph reaper.twc.weat 2 u 25 64 377 398.666 -30.285 51.555

 *clock.sjc.he.ne .CDMA. 1 u 21 64 377 98.269 15.298 4.000

Be patient, because it takes a few minutes for a server list to appear and up to 30 minutes for the first correction to take place. The * and + prefixes indicate that the connections were successful and synchronization is occurring.

Be sure to get the ntp rpm, not xntp. ntp is newer and replaces xntp. Debian users need ntp-simple, ntp-doc, and ntp-server.

ntpd makes small, incremental changes over a period of time. By itself, it will take hours, or even days, to adjust the system time, depending how far off it is. If the system time is off by more than 60 minutes, ntpdate is the quickest way to make the initial correction. ntpdate will not run if ntpd is running.

The maintainers at ntp.org are trying to deprecate ntpdate, claiming that ntpd -g, which is ntpd's "burst" command, does the same thing. Unfortunately, it doesn't handle corrections larger than 60 minutes any faster than ntpd, so ntpdate is still useful.

Using the same entry in ntp.conf three times—server pool.ntp.org—puts three different hits on the DNS pool at your disposal, so you'll never have to worry about servers being unavailable.

pool.ntp.org is a worldwide DNS round-robin of participating time servers.


If you are running any databases, be sure to consult with your database admins before making any significant time changes. Large, sudden changes are generally unhealthy for databases, so it may be better to run only ntpd and allow it to make changes in its normal slow, incremental manner.

Linux Cookbook

Learn more about this topic from Linux Cookbook.

Linux information can be found scattered in man pages, texinfo files, and source code comments, but the best source is the experts who have built up a working knowledge of managing Linux systems. The Linux Cookbook's tested techniques distill years of hard-won experience into practical cut-and-paste solutions to everyday Linux dilemmas. Use just one recipe from this collection of real-world solutions, and the hours of tedious trial-and-error saved will more than pay for the cost of the book. It's more than a time-saver; it's a sanity saver.

See what you'll learn

0 Subscribe

0 Replies