Keeping Accurate Time on Linux

The network time protocol can ensure accurate, synchronized time across your entire network. Carla Schroder explains how to set up a local time server on Linux and how to configure it so that every PC on your network synchronizes with the server.

 By Carla Schroder
Page 1 of 3
Print Article

Keeping accurate, synchronized time across your network is important for all sorts of reasons: for accurate time stamps in logs, for ensuring that processes run on time, and also for applications that depend on keeping good time. Fortunately, it doesn’t have to be a difficult process to manage, as ntpd, the NTP (network time protocol) daemon, can do all the work for you.

Typically, with ntpd you can "set it and forget it." The hard part is wading through the documentation and finding the bits that tell you how to implement and configure it, and what programs and configuration files you’ll need. You know the old cliché about asking the time and being told how to build a watch? I think the NTP project may have inspired it.

In this article we’ll cover how to set up a local time server on a LAN, without discussing the protocol itself at all, even though it is very cool. Instead, we shall stay focused on telling the time, not on building a watch.

Most Linux distributions include a motley collection of time and date utilities: hwclock.sh, date, 822-date, tzselect, tzsetup, vcstime, uptime, zdump, ddate, rdate, ctime, and doubtless several more. These tools have all sorts of odd, specialized functions, and are fun to play with on occasion. In the olden days we kept time with hwclock.sh, rdate, or ntpdate. They ran at boot or were put in cron jobs for periodic updating.

ntpd replaces hwclock.sh, rdate, and ntpdate. I recommend disabling any of these that are set to run automatically, whether from init or cron, and instead let ntpd be your sole timekeeper. With one exception — for ntpdate, don't delete those init scripts; save them.

Quick Start

After installation, all you need to do is:

  • Add some public time servers to /etc/ntp.conf
  • Set your time zone. Make a symlink from /etc/localtime to the appropriate file in /usr/share/zoneinfo
  • Make sure that UDP port 123 is open through your firewall
  • Run ntpdate to set the system time
  • Start up ntpd

Let's take these steps one at a time.

Page 2: Finding Public Time Servers

This article was originally published on Jan 22, 2004
Get the Latest Scoop with Networking Update Newsletter