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:

sudo apt-get install ntp

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:

server 0.ubuntu.pool.ntp.org
server 1.ubuntu.pool.ntp.org
server 2.ubuntu.pool.ntp.org
server 3.ubuntu.pool.ntp.org

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

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+ntp1.sil.at     95.101.196.145   2 u  40  1024  377   46.630    0.126  18.791
+pugot.canonical 192.36.143.234   2 u  37  1024  377   15.811   -0.938   5.680
 meerix.ru       130.149.17.8     2 u  36  1024  377   52.782   -1.438   0.126
 leesti.netinfor 193.6.176.59     2 u  36  1024  377   56.363    2.323   0.373
 alphyn.canonica 145.238.203.14   2 u  35  1024  377   77.512   -0.409   0.076

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:

sudo cp /etc./ntp.conf /etc/ntp.conf.original
sudo nano /etc/ntp.conf

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

sudo service ntp restart

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:

sudo service ntp stop
sudo ntpdate-debian
sudo service ntp restart

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

date

You have successfully subscribed

There was an error while trying to send your request. Please try again.

Linux Home Server will use the information you provide on this form to be in touch with you and to provide updates and marketing.

Sign up to be notified of updates and new articles. Tell me also what you want to know more about?