Synchronise the Server Clock to NTP

Your server is capable of keeping track of time by itself, but there is always the possibility that it may drift or be out of sync. This could possibly have some knock on effects if you have any time sensitive applications running, an email server for instance. In this case it may show an email as having been sent at an incorrect time. It is good practice to set the server up to sync itself with an accurate reference time source, which is what NTP is all about.

NTP, or Network Time Protocol, is a way for clients, in this case our server, to synchronise their internal clock with a cluster of global timeservers. To set this up we first need to install the NTP daemon:

We then need to set up the time servers which your server synchronises itself against. The NTP configuration file lists 4 server pools, collections of servers which have volunteered to provide highly accurate time references. Each hour, your server will select a server at random from a pool and synchronise its clock against it. The default servers in my /etc/ntp.conf file were:

You can see the servers that are being referenced within each pool by typing ntpq –p

You can choose time servers closer to your geographic location by visiting the NTP pool site at http://support.ntp.org/bin/view/Servers/NTPPoolServers. I am going to update my NTP servers to the European pools, although you can also choose country specific servers also.

As a best practice, before you edit any configuration files you should take a backup first:

then replace the default NTP servers with your geographic specific ones, and restart the NTP daemon

if you run ntpq –p now, you should see the updated NTP pools.

MANUAL SYNCHRONISATION

By default the NTP daemon works away in the background every hour. If you want to manually sync your clock though, you need to stop the NTP service first, and run the ntpdate-debian command:

to check the time on your machine, run the date command: