NTP Server Functions

Mar 2017

If you just wanted a clock, then you don't have to worry about this section, however if you want your clock to act as an NTP (Network Time Protocol) server, so that all of the computers in your house are synchronised in time to the time of your Raspberry Pi Clock, then read on.
There are two parts for this:
Firstly we need our Raspberry Pi to get the correct time from an Internet Time Server, this will keep the time on our Raspberry Pi very accurate (to within a few 10s on milliseconds).
Secondly, we want our computers to speak to the Raspberry Pi to ask for the time, so everything on the network has the same time, but only one device (the Raspberry Pi) needs to check the Internet for the time (thus guaranteeing that all computers will be the same).

Install NTP

First we need to install the NPT software, this may already be installed, just run the command below.

sudo apt-get install ntp

If NTP is not installed then the installation will start, if NTP is already installed you will the following message.

ntp is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

This may already be installed, but just in case.
<sxh [txt][; options for SyntaxHighlighter]> Reading package lists… Done Building dependency tree Reading state information… Done Suggested packages:

ntp-doc

The following NEW packages will be installed:

ntp

0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 334 kB of archives. After this operation, 988 kB of additional disk space will be used. Get:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main ntp armhf 1:4.2.6.p5+dfsg-7+deb8u2 [334 kB] Fetched 334 kB in 5s (57.7 kB/s) Selecting previously unselected package ntp. (Reading database … 31977 files and directories currently installed.) Preparing to unpack …/ntp_1%3a4.2.6.p5+dfsg-7+deb8u2_armhf.deb … Unpacking ntp (1:4.2.6.p5+dfsg-7+deb8u2) … Processing triggers for man-db (2.7.0.2-5) … Processing triggers for systemd (215-17+deb8u6) … Setting up ntp (1:4.2.6.p5+dfsg-7+deb8u2) … update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults </sxh>

Edit NTP Configuration File

Now that NTP is installed, we need to set it up, this is done via a configuration file called ntp.conf.

sudo nano ntp.conf

Find the section that looks like the following:

# You do need to talk to an NTP server or two (or three).
#server ntp.your-provider.example
# pool.ntp.org maps to about 1000 low-stratum NTP servers. Your server will
# pick a different set every time it starts up. Please consider joining the
# pool: <http://www.pool.ntp.org/join.html>
server 0.debian.pool.ntp.org iburst
server 1.debian.pool.ntp.org iburst
server 2.debian.pool.ntp.org iburst
server 3.debian.pool.ntp.org iburst

And comment out ALL of the servers in this section so that it looks like the following:

# pool.ntp.org maps to about 1000 low-stratum NTP servers. Your server will
# pick a different set every time it starts up. Please consider joining the
# pool: <http://www.pool.ntp.org/join.html>
# server 0.debian.pool.ntp.org iburst
# server 1.debian.pool.ntp.org iburst
# server 2.debian.pool.ntp.org iburst
# server 3.debian.pool.ntp.org iburst

Now we can add our own NTP servers that we wish to use.
I am in the UK, so I wanted UK time servers, for a list of servers I just did a Google search for UK time servers. Using this Google search I found the (first result) was this site pool.ntp.org
The site lists the following four UK based time 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

Paste these files in to the same section that you just commented out the original server list from.

# You do need to talk to an NTP server or two (or three).
#server ntp.your-provider.example
# pool.ntp.org maps to about 1000 low-stratum NTP servers. Your server will
# pick a different set every time it starts up. Please consider joining the
# pool: <http://www.pool.ntp.org/join.html>
# server 0.debian.pool.ntp.org iburst
# server 1.debian.pool.ntp.org iburst
# server 2.debian.pool.ntp.org iburst
# server 3.debian.pool.ntp.org iburst
server 0.uk.pool.ntp.org
server 1.uk.pool.ntp.org
server 2.uk.pool.ntp.org
server 3.uk.pool.ntp.org

Now save and close the file (Ctrl-X and then S to save)

Restart NTP

To get the Raspberry Pi to sync, we can restart the NTP service. Use the following to restart the NTP server.

sudo service ntp restart

Now check the current time and date using the date command.

date
Fri 17 Mar 18:38:59 UTC 2017

If the time and date are correct, then you are good to go.

Check NTP Servers

You can test to see if NTP on the Raspberry Pi is actually using any external time servers by using the ntpq -pn command.

ntpq -pn
remote refid st t when poll reach delay offset jitter
==============================================================================
*130.159.196.118 193.62.22.90 2 u 78 64 36 61.470 -17.318 15.763
78.129.190.21 85.199.214.102 2 u 9 64 37 13.979 0.712 0.680
87.124.126.49 195.66.241.10 2 u 9 64 37 15.417 1.572 3.078
192.146.137.13 82.148.230.254 2 u 8 64 37 42.823 -1.197 2.624

After running the command ntpq -pn you should see a list of time servers (by IP) that the NTP service on the Raspberry Pi has connected to. The IP Address with the asterisk * next to it is the last server the Raspberry Pi did a time sync with.

Synchronising Clients

to do

wireless dropping out on ntp server

clients over 1000seconds out

“NTP won’t normally reset the clock if it’s off by more than 1000s. If you run ‘ntpd -gq’ it ignores the clock being way adrift from ntp time and will force it to be correct then close. The old ntpdate program does the same thing.” credit: I found it here earlier today when I was searching on some raspi NTP issues http://www.raspberrypi.org/phpBB3/viewtopic.php?f=91&t=16058 Reply