Synchronizing the time on all machines on the same network is incredibly useful and very simple. The Network Time Protocol daemon (ntpd) does all of the dirty work for you. If you have DNS configured and are connected to the Internet, you can synchronize with an external NTP master server or you can set up your own local master server and synchronize all of your machines to it. In the latter case, you'll only need to monitor the master system for reasonably accurate time.
How can I set all of my machines to the same wall clock time?
Synchronizing the time on all machines on the same network is incredibly useful and very simple. The Network Time Protocol daemon (ntpd) does all of the dirty work for you. If you have DNS configured and are connected to the Internet, you can synchronize with an external NTP master server or you can set up your own local master server and synchronize all of your machines to it. In the latter case, you’ll only need to monitor the master system for reasonably accurate time.
Let’s get ntpd up and running. First, verify that all of your machines are set to your time zone. For example, if you live in Dallas, Texas, your systems should be set to the Central Time Zone. The time zone code for Central Time is CST6CDT or US/Central. To set the time zone, enter the command: timeconfig –utc “CST6CDT”. You have to be the superuser to change time zones. (And be careful! Setting the time zone incorrectly causes the system to have the “wrong time” — an error that can be quite infuriating. If your system is constantly off by an hour or two, double-check your time zone to make sure it’s set properly.)
After setting the time zone (say, to Central Time), the file /etc/sysconfig/clock should read:
Now you have a decision to make. Do you want to set up one system as your master time host and synchronize all other machines to it? Or, do you want to synchronize all systems to some external time host? If you have a large number of machines, you should use the first choice; for only one or two systems, the second choice is fine. Separately, if you use a notebook that moves around a lot, you may want to synchronize it to an external host even if you take the second option.
To continue the process, verify that ntpd is installed on all of your machines by using the command rpm -q ntp on each machine. If ntpd is not installed somewhere, download its RPM from Red Hat, http://www.rpmfind.net, or your distribution CD-ROMs, and install it.
Now that you have ntpd everywhere, you need to find an external time host to synchronize with. It’s highly recommended that you use a Stratum 2 server. Stratum 1 servers are at the top of the NTP hierarchy and are very heavily loaded. At the time this was written, there were 163 public Stratum 2 servers listed at http://www.eecis.udel.edu/~mills/ntp/clock2a.html. Pick two or three servers from the list at random.
For example, you might choose sushi.compsci.lyon.edu (18.104.22.168), ntp1.mainecoon.com (22.214.171.124), and harbor.ecn.purdue.edu (126.96.36.199, 188.8.131.52, 128.46. 154.76). Once you’ve made your selections, edit /etc/ntp.conf and enter the names of the Stratum 2 servers you chose. The file should look like this:
Given a list of NTP time hosts, ntpd synchronizes your machine’s time with the definitive time kept by one of NTP master hosts. If you want to check on the status of your time synchronization, execute ntpq -p. Read the man page for a detailed explanation of all the options and output details.
By the way, NTP won’t change your clocks if the time difference between the master time host and your local machine is too large. To be sure you have accurate time, you need to perform a full sync immediately after you install ntpd. Choose one of the time servers and use the ntpdate command to sync with it. The command looks like this:
% ntpdate ntp1.mainecoon.com
If the offset returned is greater than one second, run the ntpdate command again. After the second time, your machine’s time should be virtually identical to that of the master host. Ideally, you should run ntpdate during a non-busy time for your users. Having the clock change in unexpected ways while others are working can create confusion.
Now that you have an accurate time, you can start the NTP daemon running with service ntpd start. Execute chkconfig –level 2345 ntpd on to automatically start ntpd at boot time.
When you have a reasonably accurate time, execute setclock to set your hardware clock. Once you do this, your system will boot with an accurate time and ntpd will adjust for any small differences quickly.
Refer to http://www.linux.org/docs/ldp/howto/TimePrecision-HOWTO/index.html for a more detailed explanation of time zones and time synchronization.
John R. S. Mascio is a systems and network manager. He can be reached at email@example.com.