Using NTP to Synchronize Server Time

The Network Time Protocol daemon (ntpd) program is a Linux operating system daemon. It sets and maintains the server time in sync with the global time servers.

In order to synchronize server time, you will need to find one or more NTP servers to use. Your network administrator or ISP may have set up an NTP server for this purpose—check their documentation to see if this is the case. There is an online list of publicly accessible NTP servers which you can use to find an NTP server near to you. Make sure you are aware of the policy for any servers you choose, and ask for permission if required.

Choosing several unconnected NTP servers is a good idea in case one of the servers you are using becomes unreachable or its clock is unreliable. ntpd uses the responses it receives from other servers intelligently—it will favor unreliable servers less than reliable ones

Basic Configuration

If you only wish to synchronize your clock when the machine boots up, you can use ntpdate. This may be appropriate for some desktop machines which are frequently rebooted and only require infrequent synchronization, but most machines should run ntpd.

Using ntpdate at boot time is also a good idea for machines that run ntpd. The ntpd program changes the clock gradually, whereas ntpdate sets the clock, no matter how great the difference between a machine’s current clock setting and the correct time.

General Configuration

NTP is configured by the /etc/ntp.conf file in the format described in ntp.conf. Here is a simple example:

server prefer
driftfile /var/db/ntp.drift

The server option specifies which servers are to be used, with one server listed on each line. If a server is specified with the prefer argument, as with, that server is preferred over other servers. A response from a preferred server will be discarded if it differs significantly from other servers’ responses, otherwise it will be used without any consideration to other responses. The prefer argument is normally used for NTP servers that are known to be highly accurate, such as those with special time monitoring hardware.

The driftfile option specifies which file is used to store the system clock’s frequency offset. The ntpd program uses this to automatically compensate for the clock’s natural drift, allowing it to maintain a reasonably correct setting even if it is cut off from all external time sources for a period of time.

Many Internet services rely on  computers’ clocks being accurate. Services such as cron, authentication etc also rely on an accurate system clock to run commands at the specified times. So, having the time in the server to be accurate is very much necessary in this fast paced world.