{"id":726,"date":"2014-12-22T20:39:32","date_gmt":"2014-12-22T20:39:32","guid":{"rendered":"http:\/\/ava.upuaut.net\/?p=726"},"modified":"2018-11-30T13:45:02","modified_gmt":"2018-11-30T13:45:02","slug":"not-quite-5-minute-guide-to-making-an-ntp-server","status":"publish","type":"post","link":"https:\/\/ava.upuaut.net\/?p=726","title":{"rendered":"Not quite 5 minute guide to making an NTP Server"},"content":{"rendered":"<p><strong>THIS ARTICLE HAS BEEN DEPRECIATED AND INSTRUCTIONS CONTAINED BELOW NO LONGER WORK WITH LATEST RASPBIAN. HOWEVER GOOD NEWS &#8211; ITS MUCH EASIER NOW SEE HERE:<\/strong><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/ava.upuaut.net\/?p=951\">https:\/\/ava.upuaut.net\/?p=951<\/a><\/p>\n<p>This is an article on making a network attached Stratum 1 NTP Server using a Raspberry Pi+ Model 2 or 3 and the Uputronics Raspberry Pi+ GPS Expansion Board. If you need a standalone ready to go solution or need more performance please consider the <a href=\"https:\/\/store.uputronics.com\/index.php?route=product\/product&amp;path=60_70&amp;product_id=92\" target=\"_blank\" rel=\"noopener\">LeoNTP Networked Time server unit which is available here<\/a>.<\/p>\n<p>As of May 2016 this was heavily reworked due to a new version of Raspbian which did all sorts of wonderful things like disabling the serial ports etc. This guide assumes Raspbian Jessie Lite June 2017 2017-06-21. No other version or distribution is supported.<\/p>\n<p>I&#8217;ve also removed the off grid\/standalone instructions as NTP isn&#8217;t designed to work off grid using just the NMEA derived time and PPS to discipline it.<\/p>\n<p><a href=\"https:\/\/store.uputronics.com\/index.php?route=product\/product&amp;path=60_64&amp;product_id=81\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-728 size-large\" src=\"\/\/ava.upuaut.net\/wp-content\/uploads\/2014\/12\/ntpboard-1024x643.jpg\" alt=\"HAB Supplies Raspberry Pi+ GPS Expansion Board\" width=\"620\" height=\"389\" srcset=\"https:\/\/ava.upuaut.net\/wp-content\/uploads\/2014\/12\/ntpboard-1024x643.jpg 1024w, https:\/\/ava.upuaut.net\/wp-content\/uploads\/2014\/12\/ntpboard-300x188.jpg 300w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><\/a><\/p>\n<p>Uputronics\u00a0Raspberry Pi+ GPS Expansion Board<\/p>\n<p>Ideally rather than supplying a premade image I would have a set of concise instructions on making your own install from scratch so you could use the latest versions of the software. With assistance from <a href=\"http:\/\/satsignal.eu\/ntp\/Raspberry-Pi-NTP.html%20\">David Taylor<\/a> who did lots of background work on this here I present the following instructions on making a cheap PPS disciplined NTP Time server using one of the <a href=\"https:\/\/store.uputronics.com\/index.php?route=product\/product&amp;path=60_64&amp;product_id=81\">Raspberry Pi+ GPS<\/a> boards sold\u00a0on <a href=\"https:\/\/store.uputronics.com\/\">Uputronics<\/a>.<\/p>\n<p>The guide assumes you have a cursory knowledge of Linux, enough to install Raspbian and login should do.<\/p>\n<p>You will need a Raspberry Pi 2 or 3 B+, the Uputronics\u00a0<a href=\"https:\/\/store.uputronics.com\/index.php?route=product\/product&amp;path=60_64&amp;product_id=81\">Raspberry Pi+ GPS Expansion Board<\/a>\u00a0and a suitable GPS antenna.<\/p>\n<p>This guide is assuming you\u2019re using <a href=\"http:\/\/www.raspberrypi.org\/downloads\/\">Raspbian<\/a>\u00a0Jessie Lite installed from\u00a0the June 2017 image.\u00a0Download and write this to an SD card (See <a href=\"http:\/\/www.raspberrypi.org\/documentation\/installation\/installing-images\/README.md\">http:\/\/www.raspberrypi.org\/documentation\/installation\/installing-images\/README.md<\/a>). Other distributions may work but these instructions are known to work with Raspbian Jessie Lite.<\/p>\n<p>Attach the Uputronics\u00a0Raspberry Pi+ GPS Expansion Board to the Pi, insert the SD card, connect the antenna and network cable and boot the Pi up. Either connect locally or via SSH to the Pi. Follow the instructions carefully if you miss steps things won&#8217;t work.<\/p>\n<p>Text in <em>italics<\/em> is what you type.<br \/>\nText in <span style=\"color: #ff0000;\">red<\/span> indicates editing inside a file.<\/p>\n<p><strong>Prerequisite Settings<\/strong><\/p>\n<p><em>sudo raspi-config<br \/>\n<\/em>5 Interfacing Options <em><br \/>\n<\/em>P2 SSH -&gt; Would you like the SSH server to be enabled<em> &#8211; YES (Recommended)<br \/>\n<\/em>P6 Serial -&gt; Login Shell<em> (no) <\/em>Hardware<em> (yes)<\/em><em><br \/>\n<\/em>Quit but no need to reboot at this point.<\/p>\n<p><em>sudo nano \/boot\/config.txt<\/em><br \/>\nAdd at the bottom :<br \/>\n<span style=\"color: #ff0000;\"># Allow the normal UART pins to work<\/span><br \/>\n<span style=\"color: #ff0000;\">dtoverlay=pi3-miniuart-bt<br \/>\ndtoverlay=pps-gpio,gpiopin=18<br \/>\n<\/span>Save and Quit Nano.<\/p>\n<p><em>sudo apt-get update<\/em><em><br \/>\nsudo apt-get dist-upgrade<\/em><\/p>\n<p><em>sudo systemctl disable hciuart<br \/>\nsudo systemctl mask serial-getty@ttyAMA0.service<br \/>\n<\/em><\/p>\n<p><em>sudo apt-get install pps-tools<br \/>\nsudo apt-get install libcap-dev<br \/>\n<\/em><em>sudo reboot<\/em><\/p>\n<p><strong>Verifying PPS Is Working<\/strong><\/p>\n<p>Ensure the GPS has a lock and the Green PPS LED on the\u00a0Uputronics\u00a0Pi+ GPS Expansion Board is blinking once a second.<\/p>\n<p><em>dmesg | grep pps<\/em><\/p>\n<p>Output should be similar to :<br \/>\n<pre class=\"preserve-code-formatting\">[ 2.443494] pps_core: LinuxPPS API ver. 1 registered\n[ 2.446699] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti &amp;lt;giometti@linux.it&amp;gt;\n[ 2.471796] pps pps0: new PPS source pps.-1\n[ 2.471886] pps pps0: Registered IRQ 498 as PPS source\n[ 6.965166] pps_ldisc: PPS line discipline registered\n[ 6.966569] pps pps1: new PPS source ttyAMA0\n[ 6.966664] pps pps1: source &quot;\/dev\/ttyAMA0&quot; added<\/pre><br \/>\n<em>sudo ppstest \/dev\/pps0<\/em><\/p>\n<p>Output should be similar to:<br \/>\n<pre class=\"preserve-code-formatting\"> trying PPS source &quot;\/dev\/pps0&quot;\n found PPS source &quot;\/dev\/pps0&quot;\n ok, found 1 source(s), now start fetching data...\n source 0 - assert 1418933982.998042450, sequence: 970 - clear\u00a0 0.000000000, sequence: 0\n source 0 - assert 1418933983.998045441, sequence: 971 - clear\u00a0 0.000000000, sequence: 0<\/pre><br \/>\n(Press CTRL+C to quit). This indicates the PPS Module is loaded (top example) and is working (bottom).<\/p>\n<div id=\"attachment_826\" style=\"width: 1010px\" class=\"wp-caption alignright\"><a href=\"https:\/\/store.uputronics.com\/index.php?route=product\/product&amp;path=66_67&amp;product_id=76\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-826\" class=\"wp-image-826 size-full\" src=\"\/\/ava.upuaut.net\/wp-content\/uploads\/2014\/12\/dogbone.jpg\" alt=\"GPS board mounted in Geaux Robot Dog Bone Case for Raspberry Pi B+ also available from HAB Supplies\" width=\"1000\" height=\"761\" srcset=\"https:\/\/ava.upuaut.net\/wp-content\/uploads\/2014\/12\/dogbone.jpg 1000w, https:\/\/ava.upuaut.net\/wp-content\/uploads\/2014\/12\/dogbone-300x228.jpg 300w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/a><p id=\"caption-attachment-826\" class=\"wp-caption-text\">GPS board mounted in Geaux Robot Dog Bone Case for Raspberry Pi B+ also available from Uputronics<\/p><\/div>\n<p><strong>Enabling PPS\/ATOM Support in NTPD<\/strong><\/p>\n<p>The supplied version of NTPD on the Raspberry Pi doesn\u2019t support PPS so we need to recompile it (Please note that some of these steps may take up to 30 minutes).<\/p>\n<p><a href=\"https:\/\/www.eecis.udel.edu\/~ntp\/ntp_spool\/ntp4\/ntp-4.2\/ntp-4.2.8p10.tar.gz\"><em>wget https:\/\/www.eecis.udel.edu\/~ntp\/ntp_spool\/ntp4\/ntp-4.2\/ntp-4.2.8p10.tar.gz<\/em><\/a><br \/>\n<em>tar zxvf ntp-4.2.8p10.tar.gz<\/em><br \/>\n<em>cd ntp-4.2.8p10<\/em><br \/>\n<em>.\/configure\u00a0\u00a0&#8211;enable-lcap<\/em><br \/>\n<em>make -j4<\/em><br \/>\n<em>sudo make install<\/em><br \/>\n<em>sudo service ntp stop<\/em><br \/>\n<em>sudo cp \/usr\/local\/bin\/ntp* \/usr\/bin\/ &amp;&amp; sudo cp \/usr\/local\/sbin\/ntp* \/usr\/sbin\/<\/em><br \/>\n<em>sudo nano \/etc\/ntp.conf <\/em><\/p>\n<p>Add<br \/>\n<span style=\"color: #ff0000;\">server 127.127.22.0 minpoll 4 maxpoll 4<\/span><br \/>\n<span style=\"color: #ff0000;\"> fudge 127.127.22.0\u00a0 flag3 1\u00a0 refid PPS<\/span><\/p>\n<p>Amend<\/p>\n<p><span style=\"color: #ff0000;\">server 0.debian.pool.ntp.org iburst prefer<\/span><\/p>\n<p><span style=\"color: #000000;\">You may also want to add your local lan to so you can query the NTP Server by adding:<\/span><br \/>\nrestrict 192.168.1.0 mask 255.255.255.0<\/p>\n<p>Note You MUST add a preferred server or PPS doesn\u2019t work. Its worth at this point seeing if you&#8217;re ISP has its own NTP server you can use and adding that but for the purposes of this exercise adding prefer to the Debian pool one will do.<\/p>\n<p>Save and close nano.<\/p>\n<p><em>sudo nano\u00a0\/etc\/init.d\/ntp<br \/>\nFind the line\u00a0NTPD_OPTS=&#8221;$NTPD_OPTS -u $UGID&#8221;<br \/>\nAmend it to say\u00a0NTPD_OPTS=&#8221;$NTPD_OPTS&#8221;<\/em><\/p>\n<p><em>sudo systemctl daemon-reload<\/em><\/p>\n<p><em>sudo service ntp restart<\/em><\/p>\n<p>After a few minutes run<\/p>\n<p><em>ntpq \u2013p<\/em><\/p>\n<p>if you get oPPS(0) this indicates source selected, Pulse Per Second (PPS) used and everything is working.<\/p>\n<p>If you aren&#8217;t seeing the settings its possible the NTP server is picking up the NTP information via DHCP which is over riding your settings above. Do this :<\/p>\n<p><em>rm \/etc\/dhcp\/dhclient-exit-hooks.d\/ntp<br \/>\nrm \/var\/lib\/ntp\/ntp.conf.dhcp<br \/>\n<\/em><\/p>\n<p>At this point you have a NTP server which will use an external time source and use your local PPS to discipline it.<\/p>\n<p><strong>Setting Stationary Mode<\/strong><\/p>\n<div class=\"comment-text\">\n<p>Grab this small program code here : <a href=\"https:\/\/pastebin.com\/YTc9Nd3D\">https:\/\/pastebin.com\/YTc9Nd3D<\/a><br \/>\nCompile + link:<br \/>\n<pre class=\"preserve-code-formatting\">gcc -o gpsControl gpsControl.c<\/pre><br \/>\n<pre class=\"preserve-code-formatting\">sudo .\/gpsControl -p -d \/dev\/ttyAMA0 = Portable Mode\nsudo .\/gpsControl -s -d \/dev\/ttyAMA0 = Stationary Mode<\/pre><br \/>\nMay take a few goes to set it.<\/p>\n<p>pi@hypatia:~ $ sudo .\/gpsControl -s -d \/dev\/ttyAMA0<br \/>\nSet GPS for stationary mode<br \/>\nConfiguring device \/dev\/ttyAMA0<br \/>\n&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; SENDING &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; SENDING &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br \/>\nGPS mode set OK<\/p>\n<p><strong>Static IP + Hostname<\/strong><\/p>\n<p>If you want to fix your LAN IP you do it by amending \/etc\/dhcpcd.conf adding the following lines:<\/p>\n<p><span style=\"color: #ff0000;\">interface eth0<\/span><br \/>\n<span style=\"color: #ff0000;\">static ip_address=192.168.1.7\/24<\/span><br \/>\n<span style=\"color: #ff0000;\">static routers=192.168.1.254<\/span><br \/>\n<span style=\"color: #ff0000;\">static domain_name_servers=8.8.8.8 8.8.4.4<\/span><\/p>\n<p>Amend your hostname by editing \/etc\/hostname and then adding this to \/etc\/hosts as well. I.e if you call your machine &#8216;eleanor&#8217; add this after localhost in \/etc\/hosts:<\/p>\n<p><span style=\"color: #ff0000;\">127.0.0.1 localhost eleanor<\/span><\/p>\n<p><strong>Further Reading<\/strong><\/p>\n<\/div>\n<p>David Taylor\u2019s website here <a href=\"http:\/\/satsignal.eu\/ntp\/Raspberry-Pi-NTP.html\">http:\/\/satsignal.eu\/ntp\/Raspberry-Pi-NTP.html<\/a> goes into much further detail about the process above and covers graphing, remote access monitoring etc and I highly recommend you read it.<\/p>\n<p>References from this draft document by Eric S. Raymond <a href=\"https:\/\/www.ntpsec.org\/white-papers\/stratum-1-microserver-howto\/\">https:\/\/www.ntpsec.org\/white-papers\/stratum-1-microserver-howto\/<\/a><\/p>\n<p>Hope this helps, let me know how you get on with these instructions and I&#8217;ll try keep them up to date.<\/p>\n<p>Thanks to:<\/p>\n<p>David Taylor<br \/>\nDave Akerman<br \/>\nChris Stenton for the new kernel fix.<br \/>\nTris Mabbs for the DHCP issue heads up.<br \/>\nMichiel Kanis for testing DHCP fix.<br \/>\nPhil Heron for the GPSD Autostart fix.<\/p>\n<p>Updated : 27\/06\/17 Fixed for new June 2017 Raspbian. Updated links to ntp-4.2.8p10.<br \/>\nUpdated : 25\/05\/16 Fixed for Pi3\/May Raspbian. Removed Standalone mode (NTP isn&#8217;t designed for this)<br \/>\nUpdated : 22\/03\/16 Added Pi3\/Standalone etc<br \/>\nUpdated : 24\/02\/16 Added Code to set stationary mode.<br \/>\nChecked : 29\/09\/15 Works with Raspian Jessie &#8211; Thx Ciaran!<br \/>\nUpdated : 03\/07\/15 NTP version and location amended &#8211; Thx Greg!<br \/>\nChecked : 13\/06\/15 Works with 2015-05-05-raspbian-wheezy.img<br \/>\nUpdated : 13\/04\/15 ntp-4.2.8p2.tar.gz links updated.<br \/>\nUpdated : 23\/02\/15 Verified these instructions are good with 2015-02-16-raspbian-wheezy.img as a base<br \/>\nUpdated : 20\/02\/15\u00a0ntp-4.2.8p1.tar.gz links updated.<br \/>\nUpdated : 28\/01\/15 DHCP Client can pick up NTP from DHCP server and override all your good work. See below.<br \/>\nUpdated : 27\/01\/15 New kernel breaks previous instructions. Updated.<br \/>\nUpdated : 26\/12\/14 Updated NTP to 4.2.8 and tested with Raspbian 2014-12-14<\/p>\n","protected":false},"excerpt":{"rendered":"<p>THIS ARTICLE HAS BEEN DEPRECIATED AND INSTRUCTIONS CONTAINED BELOW NO LONGER WORK WITH LATEST RASPBIAN. HOWEVER GOOD NEWS &#8211; ITS MUCH EASIER NOW SEE HERE: https:\/\/ava.upuaut.net\/?p=951 This is an article on making a network attached Stratum 1 NTP Server using &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/ava.upuaut.net\/?p=726\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-726","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/ava.upuaut.net\/index.php?rest_route=\/wp\/v2\/posts\/726","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ava.upuaut.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ava.upuaut.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ava.upuaut.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ava.upuaut.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=726"}],"version-history":[{"count":50,"href":"https:\/\/ava.upuaut.net\/index.php?rest_route=\/wp\/v2\/posts\/726\/revisions"}],"predecessor-version":[{"id":955,"href":"https:\/\/ava.upuaut.net\/index.php?rest_route=\/wp\/v2\/posts\/726\/revisions\/955"}],"wp:attachment":[{"href":"https:\/\/ava.upuaut.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=726"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ava.upuaut.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=726"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ava.upuaut.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}