How To Setup Ubuntu NTP Client

NTP stand for Network Time Protocol. It's a way to have your machine time synchronized with a standard or official time. It's needed in case of applications where time is critical, a near example is official communication (for example, via mail) that becomes invalid because time it's incorrect (for example a mail that is received before it's sent because of a time difference between the sender and the receiver.

Another useful application is to prevent/correct problematic situations caused by  Leap Seconds, as described in my post: The Unknown Leap Second

Remember: Ubuntu as standard comes with ntpdate installed. It is run automatically every time the OS boots, and can be run manually every time you need it. 
Another technicality: NTP communicates with port 123 UDP, so if you need it, be sure your firewall is not blocking your requests.

Let's see how to install and configure and NTP client. As always, almost every command is supposed to be preceded by sudo.

Fist, the installation:
apt-get install ntp
Second, the configuration:
vi /etc/ntp.conf
There are a number of NTP server on the internet. If you are in Italy, the official time is given by the "Istituto Galileo Ferraris" in Turin, and expose these time servers:
ntp1.inrim.it
ntp2.inrim.it
Default Ubuntu 12.04 NTP Servers are:
0.ubuntu.pool.ntp.org
1.ubuntu.pool.ntp.org
2.ubuntu.pool.ntp.org
3.ubuntu.pool.ntp.org
Ubuntu NTP servers refers to a worldwide NTP pool, managed by www.pool.ntp.org, which is probably the largest time server (or better, cluster of time server) in the world.

To add a server to your list, simply add this line to your /etc/ntp.conf
server <URL OF SERVER>

If you want servers outside the local machine to interrogate your server for time synchronization, just add your trusted servers to the permitted IPs (the following is just an example):
restrict 192.168.1.0 mask 255.255.255.0
Then to apply your modification, restart the NTP service:
service ntp restart 

Manually update time
Sometimes you'll need to force the time update, for example to recovery from a leap second crash. In this case you have to use ntpdate. NOTE: ntpdate cannot be executed if the ntp daemon is running.
service ntp stop
ntpdate <NTPSERVERURL>
service ntp start

Here, finished! This time was brief and simple! ;)

Labels: ,