Saturday, March 31, 2007

Finding the time...

After discovering that the clocks on several of the servers I work with now were out of sync, I decided to check my own system's accuracy. The simple command "ntpdate [server]" (on Ubuntu by default) will sync your clock with whatever server you select. "" or any of the North American NTP pool servers (e.g., will work fine.

However, before you think of the clever idea of adding this command to a cron job or startup script, know that there is a better way: ntpd. This is a daemon that is designed to bring your clock in sync with time from the atomic clock time servers optimally. It adjusts the time to a synchronized state in small increments so as not to harm programs that rely on a regular passage of time, and so that your logs don't appear to jump. It works very well, and keeps your clock as accurate as possible all the time.

One catch: ntpd is not installed on Ubuntu by default, as they did not want any network listening apps installed on the desktop version by default. And good for them to improve security. The problem is that ntpd will not be found in the repos. It goes under the guises "ntp-simple" and "ntp-refclock". The latter is really only when you want to set up your own time server, and have the means to do so. The former is what should be used to keep "simple" (single, personal) systems synced. So install that.

There are a few more steps left. Run ntpdate to get the current time:
sudo ntpdate

Then edit /etc/ntp.conf:
sudo vim /etc/ntp.conf

Add the lines after these 2 (should be there already):
# You do need to talk to an NTP server or two (or three).

Lastly start up the ntp server:
sudo /etc/init.d/ntp-server start

To see the results:
sudo ntpd -p


Post a Comment

Subscribe to Post Comments [Atom]

<< Home