2.6. NTP - time synchronization

Every server should have accurate time information, this is especially important for mail server. To make sure our servers time is always up to date we are going to install ntp package which enables our server to use NTP protocol for syncing your servers clock.

apt-get install ntp

If your data center or VPS provider offers an NTP service use their NTP server. Open up /etc/ntp.conf with nano and replace:

server 0.debian.pool.ntp.org iburst dynamic
server 1.debian.pool.ntp.org iburst dynamic
server 2.debian.pool.ntp.org iburst dynamic
server 3.debian.pool.ntp.org iburst dynamic

with

server ADDRESS-OF-NTP-SERVER-YOU-WANT-TO-USE

You should have at least two servers in the ntp.conf.

After saving the changes you have to restart the NTP service by running

invoke-rc.d ntp restart

Note: invoke-rc.d is Debians shortcut to /etc/init.d/. You can run /etc/init.d/ntp restart as well.

You can examine if the NTP server is working as expected if you run the ntpq -p command:

example:~# ntpq -p

    remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
zg1.ntp.CARNet. 161.53.1.2       2 u   58   64    3    7.157  106.619   4.158
zg2.ntp.CARNet. 161.53.1.2       2 u   57   64    3    7.677   25.934   4.792
morcic.RI.CARNe 161.53.1.2       2 u   58   64    3   11.796   26.527   7.751

After a while the reach column should have values greather that 0. Which means that the NTP servers we are pooling for time information are reachable.

[Caution]Caution

If your clock was way off from the current time NTP will not sync your servers time. In that case stop the NTP daemon. Set the time and date manually (or you can install and use the ntpdate utility) and run the NTP daemon again.