Network Time Protocol (NTP) is a networking protocol for time and date synchronization between computers. Having an NTP server decreases the number of calls to the internet made by hosts and creates a better system time for all computers that rely on punctuality and performance. Accurate time across a network is important for many reasons, as even minute discrepancies in time can cause big problems in the long run.

Luckily, an NTP server is very simple to build. This tutorial describes how to set up your machine as a local NTP server on Ubuntu 16.04 and how to use the NTP daemon to regularly maintain an accurate system time. 

 

Install NTP daemon

sudo apt-get update 

sudo apt-get install ntpd 

Note: ntpd can act both as a client and as a server. 

Remove the old-time synchronization program. 

sudo apt-get remove ntpdate 

 

Configure the daemon properly

The configuration file for ntpd is located at /etc/ntp.conf 

STEP 1: Add the NTP servers to the list. You can change them depending on your location and add iburst after the most promising one. Here’s our example: 

 

# You do need to talk to an NTP server or two (or three). 

server 0.ca.pool.ntp.org iburst 

server 1.ca.pool.ntp.org 

server 2.ca.pool.ntp.org 

server 3.ca.pool.ntp.org 

 

STEP 2:  Add a few extra lines to the bottom of your servers list to provide your current local time as a default, should you temporarily lose internet connectivity: 

 

server 127.127.1.0fudge  

127.127.1.0 stratum 10 

 

STEP 3:  Save your list and restart the daemon. 

sudo systemctl daemon-reload ntp 

 

STEP 4: Next, monitor your system log to see if you synchronize with a time server: 

tail -f /var/log/syslog 

 

STEP 5: In about 10-15 seconds (or up to 15-20 minutes if you forgot to put ‘iburst’ after your favourite server), you should see something like the following in your system log: 

Jul 17 16:50:22 hostname ntpd[22402]: synchronized to 140.221.9.20, stratum 2 

 

If this message does not appear, you have not yet properly synchronized with the NTP server network. Check the list of NTP peers you are communicating with using the following: 

ntpq -c lpeer 

 

If the ‘delay’, ‘offset’, and ‘jitter’ fields are non-zero and you haven’t synchronized, it probably means that you need to wait a bit. Check again that you’ve inserted the ‘iburst’ argument to your servers list! Peer example: 

 

remote           refid      st t when poll reach   delay   offset  jitter==============================================================================*milo.mcs.anl.go 192.5.41.40      2 u    4   64   77   46.213   67.753   2.207 

-europium.canoni 193.79.237.14    2 u   63   64   37   97.375   71.020   1.875 

-dtype.org       69.25.96.13      2 u    2   64   77   86.956   69.178   1.804 

+smtp130.junkema 216.218.254.202  2 u    2   64   77   87.266   67.677   0.916 

+kechara.flame.o 216.218.254.202  2 u-   64   77   89.183   68.717   1.713 

-host2.kingrst.c 99.150.184.201   2 u    –   64   77   24.306   62.121   2.608  

LOCAL(0)        .LOCL.          10 l   59   64   37    0.000    0.000   0.002 

 

STEP 6: Once ntpd is running and synchronized with the time servers you have selected, you may set it up in order to act as a time server for other machines. To do so, add a section like the following to /etc/ntp.conf 

 

# Allow LAN machines to synchronize with this ntp server 

restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap 

restrict 192.168.2.0 mask 255.255.255.0 nomodify notrap 

restrict 192.168.3.1  

 

STEP 7: You may add as many (or few) CIDR address blocks to allow to synchronize with your machine as you’d like, you might have noticed restrict 192.168.3.1 by itself, a default mask of 255.255.255.255 is applied if none are specified. 

 

STEP 8: Restart your NTP daemon. 

sudo systemctl daemon-reload ntp 

 

That’s it! Your NTP server is now set up. Let us know if you have any questions in the comments below.