Configuring ntp on Ubuntu Server 14.04 LTS

Check how the server is set, “RTC time” is your hardware clock…

root@ubuntu01:/# timedatectl

      Local time: Wed 2015-10-28 14:51:18 CET
  Universal time: Wed 2015-10-28 13:51:18 UTC
        RTC time: Wed 2015-10-28 13:52:41
        Timezone: Europe/Stockholm (CET, +0100)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: no
 Last DST change: DST ended at
                  Sun 2015-10-25 02:59:59 CEST
                  Sun 2015-10-25 02:00:00 CET
 Next DST change: DST begins (the clock jumps one hour forward) at
                  Sun 2016-03-27 01:59:59 CET
                  Sun 2016-03-27 03:00:00 CEST

The ntp daemon ntpd calculates the drift of your system clock and continuously adjusts it, so there are no large corrections that could lead to inconsistent logs for instance.

install ntpd:

root@ubuntu01:/# sudo apt-get install ntp

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  libopts25
Suggested packages:
  ntp-doc
The following NEW packages will be installed:
  libopts25 ntp
0 upgraded, 2 newly installed, 0 to remove and 95 not upgraded.
Need to get 474 kB of archives.
After this operation, 1,677 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://se.archive.ubuntu.com/ubuntu/ trusty/main libopts25 amd64 1:5.18-2ubuntu2 [55.3 kB]
Get:2 http://se.archive.ubuntu.com/ubuntu/ trusty-updates/main ntp amd64 1:4.2.6.p5+dfsg-3ubuntu2.14.04.5 [419 kB]
Fetched 474 kB in 0s (831 kB/s)
Selecting previously unselected package libopts25:amd64.
(Reading database ... 58224 files and directories currently installed.)
Preparing to unpack .../libopts25_1%3a5.18-2ubuntu2_amd64.deb ...
Unpacking libopts25:amd64 (1:5.18-2ubuntu2) ...
Selecting previously unselected package ntp.
Preparing to unpack .../ntp_1%3a4.2.6.p5+dfsg-3ubuntu2.14.04.5_amd64.deb ...
Unpacking ntp (1:4.2.6.p5+dfsg-3ubuntu2.14.04.5) ...
Processing triggers for ureadahead (0.100.0-16) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up libopts25:amd64 (1:5.18-2ubuntu2) ...
Setting up ntp (1:4.2.6.p5+dfsg-3ubuntu2.14.04.5) ...
 * Starting NTP server ntpd  [ OK ]
Processing triggers for libc-bin (2.19-0ubuntu6.6) ...
Processing triggers for ureadahead (0.100.0-16) ...

Configure ntp.conf with your pool, mine is the swedish pool found at

http://www.pool.ntp.org/zone/se
root@ubuntu01:/# vi /etc/ntp.conf

change these:

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

to these:

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

Checking that ntp is started at boot time

root@ubuntu01:/# sysv-rc-conf --list

acpid
apache2      0:off      1:off   2:on    3:on    4:on    5:on    6:off
apparmor     S:on
apport
atd
console-setu
cron
dbus
ddclient     1:off      2:on    3:on    4:on    5:on
dns-clean    1:on       2:on    3:on    4:on    5:on
friendly-rec
grub-common  2:on       3:on    4:on    5:on
halt         0:on
iptables-per 0:off      1:off   2:on    3:on    4:on    5:on    6:off
irqbalance
killprocs    1:on
kmod
mysql
networking
ntp          1:off      2:on    3:on    4:on    5:on
ondemand     2:on       3:on    4:on    5:on
pppd-dns     1:on       2:on    3:on    4:on    5:on
procps
rc.local     2:on       3:on    4:on    5:on
reboot       6:on
resolvconf
rsync        0:off      1:off   2:on    3:on    4:on    5:on    6:off
rsyslog
screen-clean 0:off      1:off   2:on    3:on    4:on    5:on    6:off
sendsigs     0:on       6:on
single       1:on
ssh
sudo
udev
umountfs     0:on       6:on
umountroot   0:on       6:on
unattended-u 0:off      6:off
urandom      0:on       6:on    S:on

looks okay, so lets reload the new config…

root@ubuntu01:/# service ntp reload

verify the daemon is running with the pstree -p command

root@ubuntu01:/# pstree -p

        │             
        ├─ntpd(1716)
        ├─rsyslogd(688)─┬─{rsyslogd}(689)
        │               ├─{rsyslogd}(690)
        │               └─{rsyslogd}(691)
        ├─sshd(939)─┬─sshd(1970)───sshd(1971)
        │           └─sshd(32233)───sshd(32316)───bash(32317)───sudo(32449)───bash(32452)───pstree(1972)
        ├─systemd-logind(685)
        ├─systemd-udevd(289)
        ├─upstart-file-br(704)
        ├─upstart-socket-(707)
        └─upstart-udev-br(284)

Sweet, now sync the system clock with the hwclock:

root@ubuntu01:/# hwclock --systohc

and verify:

root@ubuntu01:/# timedatectl

      Local time: Wed 2015-10-28 15:10:15 CET
  Universal time: Wed 2015-10-28 14:10:15 UTC
        RTC time: Wed 2015-10-28 14:10:15
        Timezone: Europe/Stockholm (CET, +0100)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: no
 Last DST change: DST ended at
                  Sun 2015-10-25 02:59:59 CEST
                  Sun 2015-10-25 02:00:00 CET
 Next DST change: DST begins (the clock jumps one hour forward) at
                  Sun 2016-03-27 01:59:59 CET
                  Sun 2016-03-27 03:00:00 CEST

All done!