Setting up an NTP Server in Ubuntu

Following on from my article on Computer time keeping and the Network Time Protocol, this article outlines the steps required to setup an NTP server in Ubuntu Server 14.04 LTS.

Before following the steps in this article and setting up your own NTP server, it is worth considering which time sources you wish to use. Most Internet Service Providers (ISP’s) operate at least one customer accessible NTP server. This should be the closest to your Computer in terms of network hops and is worth considering.

The NTP Pool Project is also worth a look, it offers pools of NTP servers by country. Taking the UK as an example it currently offers four separate groups of UK based NTP 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

Installation

From a terminal prompt issue the following command to install ntpd:

sudo apt-get install ntp

Configuration

Having successfully installed the NTP daemon, the configuration file should be updated to point to three or more time servers. To open the configuration file ready for editing issue the following command:

sudo nano /etc/ntp.conf

Use the cursor keys to scroll down the file until the following lines are visible:

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

Update the four lines to match the fully qualified domain names or IP addresses of the NTP servers you wish to use, ensure that the word server remains at the very beginning of each line. To exit nano and save the changes to the ntp.conf file press the following key combinations:

CTRL+X then Y when prompted to save the changes

The NTP daemon needs to be restarted in order for the changes made to the configuration file to take effect, to do this issue the following command:

sudo service ntp restart

Checking the synchronisation status

To check the synchronisation status of the new NTP server issue the following command:

ntpq -p

Initially the output of the above command will look similar to this as the server begins communication with the remote NTP servers:

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 cdns01.plus.net 195.66.241.2     2 u    1   64    1    9.488    0.480   0.000
 y.ns.gin.ntt.ne 129.250.35.251   2 u    -   64    1   13.091   -0.008   0.000
 ntp1.warwicknet .INIT.          16 u    -   64    0    0.000    0.000   0.000
 ntp3.wirehive.n .INIT.          16 u    -   64    0    0.000    0.000   0.000

Once the initialisation has completed and things have settled down the output of the ntpq -p command should look more like this, the NTP server marked with an asterisk (*) is the current primary time reference:

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*cdns01.plus.net 195.66.241.2     2 u   41   64  377    8.794    0.355   0.162
+y.ns.gin.ntt.ne 129.250.35.251   2 u   35   64  377   12.537   -0.014   0.177
-ntp1.warwicknet 195.66.241.3     2 u   41   64  377    9.430    3.731   0.183
+ntp3.wirehive.n 195.66.241.10    2 u   33   64  377   12.310    0.145   0.0787

Additional Information

Below is a explanation of what the various columns in the above output of the ntpq -p command relate to:

Tally Code

The left most character shown in the output of ntpq -p after initialisation provides an insight into the workings of the clock selection algorithm. A character is set for each peer or server association and can take on one of the following values:

Symbol Message Description
space reject The peer is discarded as unreachable, synchronised to this server (synch loop) or outrageous synchronization distance.
x falsetick The peer is discarded by the intersection algorithm as a falseticker.
. excess The peer is discarded as not among the first ten peers sorted by synchronisation distance and so is probably a poor candidate for further consideration.
outlyer The peer is discarded by the clustering algorithm as an outlier.
+ candidate The peer is a survivor and a candidate for the combining algorithm.
# selected The peer is a survivor, but not among the first six peers sorted by synchronisation distance. If the association is ephemeral, it may be demobilised to conserve resources.
* sys.peer The peer has been declared the system peer and lends its variables to the system variables.
o pps.peer The peer has been declared the system peer and lends its variables to the system variables. However, the actual system synchronisation is derived from a pulse-per-second (PPS) signal, either indirectly via the PPS reference clock driver or directly via kernel interface.

Remote

  • The FQDN or IP address of the remote peer or server this device is syncing to. If this field display’s LOCAL then no other peers or servers could be contacted to synchronise with

Refid

  • The time source the remote peer or server is synchronised to. This field can take on one of the following values per association:
Value Description
IP address The IP address of a remote peer or server
.LOCL. This local host, used when there are no remote peers or servers available
.PPS. This stands for Pulse Per Second and will be provided by a reference clock such as an Atomic clock
.IRIG. Inter-Range Instrumentation Group time code
.ACTS. American NIST time standard telephone modem
.NIST. American NIST time standard telephone modem
.PTB. German PTB time standard telephone modem
.USNO. American USNO time standard telephone modem
.CHU. CHU (HF, Ottawa, ON, Canada) time standard radio receiver
.DCFa. DCF77 (LF, Mainflingen, Germany) time standard radio receiver
.HBG. HBG (LF Prangins, Switzerland) time standard radio receiver
.JJY. JJY (LF Fukushima, Japan) time standard radio receiver
.LORC. LORAN-C station (MF) time standard radio receiver. Note, no longer operational (superseded by eLORAN)
.MSF. MSF (LF, Anthorn, Great Britain) time standard radio receiver
.TDF. TDF (MF, Allouis, France) time standard radio receiver
.WWV. WWV (HF, Ft. Collins, CO, America) time standard radio receiver
.WWVB. WWVB (LF, Ft. Collins, CO, America) time standard radio receiver
.WWVH. WWVH (HF, Kauai, HI, America) time standard radio receiver
.GOES. American Geosynchronous Orbit Environment Satellite
.GPS. American GPS
.GAL. Galileo European GNSS
.ACST. Manycast server
.AUTH. Authentication error
.AUTO. Autokey sequence error
.BCST. Broadcast server
.CRYPT. Autokey protocol error
.DENY. Access denied by server
.INIT. Association initialised
.MCST. Multicast server
.RATE. Polling rate exceeded
.TIME. Association timeout
.STEP. Step time change, the offset is less than the panic threshold (1000ms) but greater than the step threshold (125ms)
.MRS. Multi Reference Sources – A time source that has access to many different time and frequency references for redundancy

ST

  • The remote peer or servers Stratum

T

  • The type of client, server or connection used, possible values include:
Value Description
u Unicast or manycast client
b Broadcast or multicast client
l Local reference clock
s Symmetric peer
A Manycast server
B Broadcast server
M Multicast server

When

  • The number of seconds,minutes, hours, or days since the last successfull poll

Poll

  • Polling frequency, this typically ranges between 64 and 1024 seconds

Reach

  • The reach column is used to display the last eight transactions between the NTP daemon and a given remote peer or time server. The status (success = 1 or fail = 0) of each transaction is added to an 8-bit left-shifting shift register
  • Each time the NTP daemon sends out a request for a time update the entire 8-bit register is shifted one bit to the left with the state of the more recent poll entering from the right
  • This means that unsuccessful requests can be tracked over eight poll intervals before the information is overwritten in the shift register to make room for new poll status information
  • The reachability value is displayed in octal, eight successful polls would produce the following in binary: 1111 1111, in decimal this is 255 and in octal it is 377. Below is a table showing the progression of a failed poll through the 8-bit shift register and the corresponding octal values that may be displayed:
Status Bit Octal Value
1111 1110 376
1111 1101 375
1111 1011 373
1111 0111 367
1110 1111 357
1101 1111 337
1011 1111 277
0111 1111 177
1111 1111 377

Delay

  • Round trip communication delay to the remote peer or server in milliseconds

Offset

  • Mean offset (phase) in the times reported between this local host and the remote peer or server (RMS, milliseconds)

Jitter

  • Mean deviation (jitter) in the time reported for that remote peer or server (RMS of difference of multiple time samples, milliseconds)

 

Leave a Reply