ELS Howto: Accurate Timekeeping


Synopsis

This document explains how to keep your Elemental Linux Server (ELS) system's clock in sync using the Network Time Protocol (NTP).


Prerequisites

You will need to obtain the IP address of an NTP time source on your network or on the Internet. If you choose to use an Internet-based time server, you should obtain permission to use the server before proceeding.


Installation

The OpenNTPD package is included as part of the ELS base installation. No installation is required.


Configuration

The following steps demonstrate how to configure OpenNTPD.

  1. Copy the sample ntpd.conf file into /etc/openntpd.
  2. Edit ntpd.conf to suit your needs using the ntpd.conf(5) man page as a reference.
  3. Open the firewall for NTP traffic and restart the network subsystem to refresh the rules.
  4. Set ntpd to start automatically at boot-up.

Example

The following example shows portions of /etc/openntpd/ntpd.conf and /etc/firewall set up to use a time server provided by your ISP.

cp /usr/share/doc/openntpd/config/ntpd.conf /etc/openntpd

vi /etc/openntpd/ntpd.conf

# sync to a single server
server 10.10.10.123

# use a random selection of 8 public stratum 2 servers
# see http://twiki.ntp.org/bin/view/Servers/NTPPoolServers
#servers pool.ntp.org

vi /etc/firewall

# Allow NTP replies from time server.  Be sure to change the IP address
# to that of your NTP source.
-A INPUT -p udp -s 10.10.10.123 --sport 123 -j ACCEPT

/etc/init.d/network restart

chmod +x /etc/init.d/ntpd

Notes


Testing

When configuration is finished you can check it by following these steps.

  1. Start ntpd with the command /etc/init.d/ntpd start.
  2. Periodically check the syslog for messages from ntpd.
  3. Check the system time with the date command and compare it to the time at http://www.time.gov.

Here is an example of a successful test for a machine with a clock that was off by a few minutes and is slowly being brought back into sync with the network time source.

login: root
password:

# /etc/init.d/ntpd start
Time synchronization service is starting.

# tail /var/log/syslog
ntpd: ntp engine ready
ntpd: peer 10.10.10.123 now valid
ntpd: adjusting local clock by 167.683291s
ntpd: adjusting local clock by 167.609554s
ntpd: adjusting local clock by 167.483246s

Here are some troubleshooting steps you can try if things are not working right.

  1. Verify that ntpd is running using the command ps -ef | grep ntpd.
  2. Check the firewall rules using the command iptables -L -n and make sure UDP traffic on port 123 is able to come in from your time server.
  3. Try an alternate time server.