Setting up NTP on Ubuntu 14.04

This is a really quick post, as most Linux (or M$ Windows) installations will use/need an NTP server to keep the time in sync with other machines on the LAN.

Update and Install

As always, start with an up to date install. Installing the software is just two packages the server, ntp, and some utilities, ntpdate.

sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install ntp ntpdate

Which pool to use

If you want a server that syncs its time to the Ubuntu pool that is all you need do. I told you it was a quick post.

BUT, if you want to use some time servers closer to your home. Go and have a look at https://www.ntppool.org/en/use.html there you will find lists of pool servers from all over the world. I live in England so I use the UK pool.

Edit the ntp configuration file.

sudo nano /etc/ntp.conf

Look for the lines similar to these and either remove or comment them out.

server 0.ubuntu.pool.ntp.org
server 1.ubuntu.pool.ntp.org
server 2.ubuntu.pool.ntp.org
server 3.ubuntu.pool.ntp.org
# Use Ubuntu's ntp server as a fallback.
server ntp.ubuntu.com

Replace them with the pool servers of your choice, I will be using the UK pool. You need 3 servers to form a quorum for ntp, so always configure at least 4 servers.

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

If this is running a machine that is turned on all the time or for long periods, you can use this setup for your own local time server. Which means you can point all of your other local machines at this one. It will also save a very small amount of your broadband bandwidth. 🙂

Local clients

If you have a machine with the setup above and now you want to point your remaining local machines at it. Use the same setup but add the following line to /etc/ntp.conf, for the local clients.

server your.ntp.server.local prefer iburst

This line tell the ntp server to prefer the server at your.ntp.server.local, change ithe hostname to point at your main NTP server. The iburst sends requests quicker at the beginning so it can get established quicker after a restart.

Testing that you are using a time server

After the server has been running for 10-20 minutes it will get synced up and will be keeping your ntp server in time. Run the command below, note it uses watch so it will rerun the command every 2 seconds.

watch ntpq -cpe -cas

You should see some output similar to this

ind assid status  conf reach auth condition  last_event cnt
===========================================================
  1 45093  931a   yes   yes  none   outlyer    sys_peer  1
  2 45094  941a   yes   yes  none candidate    sys_peer  1
  3 45095  9324   yes   yes  none   outlyer   reachable  2
  4 45096  941a   yes   yes  none candidate    sys_peer  1
  5 45097  961a   yes   yes  none  sys.peer    sys_peer  1
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
-84.52.184.247   193.2.1.117      2 u   27   64  377   61.189  -10.651   2.794
+de-ntp01.10g.ch 212.82.32.15     2 u   30   64  373   24.568    1.526   4.754
-mirror.muntinte 193.190.230.65   2 u   28   64  377   17.568    9.128   5.514
+smtp2.xipalia.c 131.188.3.221    2 u   21   64  267   26.973   -1.563   3.192
*golem.canonical 140.203.204.77   2 u    5   64  373   11.054   -0.279   6.532

In the output from ‘pe’ , short for peers. One of the servers listed has a condition of sys.peer. This is the one you are syncing to.
Looking at the output from ‘as’, associations, one of the servers has an ‘*’ by it this is the one you are syncing to.

The columns in the second out put show the following data.

  • st stratus, The lower the number the closer you are to the real GPS time source. anything below 3 is good.
  • When the number of seconds before the next poll, or time check.
  • reach This is a scrolling number in base 8. it show the status of the connections to the sever. When it reads 377 that is the best.
  • delay is the time taken to get a reading from the server.
  • Offset is how much time your server is out from the ones you are using.
  • Jitter the amount of wobble on the time server.

For more information see https://www.ntp.org/.

Stopping and starting the ntp server.

To start, stop, restart the ntp server use the usual commands

sudo service ntp start
sudo service ntp stop
sudo service ntp restart

6 thoughts on “Setting up NTP on Ubuntu 14.04

  1. Jakob Gaardsted

    Hi. I may be mistaken here, but my comment:
    Suggesting people just run ‘sudo apt-get dist-upgrade’
    in the process of adding ntp, should come with a warning..?
    As far as I can see, dist-upgrade does a MAJOR(?) upgrade to the system..
    Luckily, I tried this on a development-server first,
    but if I had tried that on one of our production-servers,
    I could have gotten myself into serious trouble – just because I wanted to activate NTP.

    So, at least my warning here: beware what you are doing, if you include the ‘dist-upgrade’ part.

    If I’m mistaken, sorry in advance 🙂

    Reply
    1. Richard Post author

      Hi Jakob,

      Take a look at “man 8 apt-get” it describes the differences between the subcommand for apt-get upgrade and dist-upgrade. The main difference between them is that dist-upgrade will upgrade the kernel packages as well. but read the man page.

      As for following some blog on a production server, that would be utter stupidity! If any of my team did that they would be escorted from the premises and looking for a new job. Always try out new software on a test machine or on virtual machines. first.

      Reply
  2. Mark Lukinovich

    ‘sudo apt-get dist-upgrade’ did crash the WiFi on my DELL 5414. There appears to be a problem with the new WiFi driver it installs. This is 4/1/2019. Not a big deal since this is a build machine for HAM radio and I’ve learned to use CloneZilla before new app installs since they are not exactly mainstream applications. The section of the upgrade appears to deal with 22 packages with I’ve found I can’t install dealing with the Kernel update in the last 2 weeks.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *