User Tools

Site Tools


the_ntp_functions

This is an old revision of the document!


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


<sxh [txt][; options for SyntaxHighlighter]>

129.250.35.250 249.224.99.213 2 u 17 64 1 14.476 -0.987 0.001 109.74.206.120 129.69.1.153 2 u 16 64 1 11.470 -2.075 0.001 46.101.52.119 81.174.136.35 2 u 15 64 1 12.037 -0.254 0.001 162.213.34.249 145.238.203.14 2 u 14 64 1 11.887 -0.114 0.001 pi@PiNTP:~ $ date +“%FT%T%Z” 2017-01-22T20:20:22UTC pi@PiNTP:~ $ date Sun 22 Jan 20:20:28 UTC 2017 pi@PiNTP:~ $ ntpq -pn

   remote           refid      st t when poll reach   delay   offset  jitter

129.250.35.250 249.224.99.213 2 u 17 64 3 12.131 -0.813 0.173 109.74.206.120 129.69.1.153 2 u 19 64 3 17.051 -5.251 3.175 46.101.52.119 81.174.136.35 2 u 17 64 3 12.437 -0.767 0.513 162.213.34.249 145.238.203.14 2 u 17 64 3 12.664 -0.506 0.392 pi@PiNTP:~ $ ntpq -pn

   remote           refid      st t when poll reach   delay   offset  jitter

*129.250.35.250 249.224.99.213 2 u 21 64 177 10.248 0.334 0.864 -109.74.206.120 129.69.1.153 2 u 23 64 177 10.696 -1.835 8.592 +46.101.52.119 81.174.136.35 2 u 18 64 167 11.125 0.393 0.716 +162.213.34.249 193.79.237.14 2 u 15 64 177 11.887 -0.114 2.181 </sxh>

the_ntp_functions.1489775526.txt.gz · Last modified: 2023/03/09 22:35 (external edit)