benandrews54
Posts: 14
Joined: Mon Oct 21, 2013 1:55 pm

RPi as NTP server

Thu Sep 24, 2015 2:07 pm

Hi,

I am trying to set up my network so that one Pi is a time server with a PiFace RTC attached with 10 other Pis all retrieving the time from the server.

At the moment I am setting up the time server as an NTP server but I cannot seem to get it to work. The whole system will be without internet connection when I launch it so i needs to be a completely closed system.

Thanks

EDIT:

My two ntp.conf files are below:

NTP server:

Code: Select all

# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help

driftfile /var/lib/ntp/ntp.drift


# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable


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

#Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
# might also be helpful.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.
#restrict default kod nomodify notrap nopeer noquery
#restrict -6 default kod notrap nomodify nopeer noquery
#restrict -4 default kod notrap nomodify nopeer noquery

# Local users may interrogate the ntp server more closely.
#restrict 127.0.0.1
#restrict ::1

# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict 192.168.10.1 mask 255.255.255.0 nomodify notrap

fudge 127.127.1.0 stratum 1

# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
broadcast 192.168.10.255

# If you want to listen to time broadcasts on your local subnet, de-comment the
# next lines.  Please do this only if you trust everybody on the network!
#disable auth
#broadcastclient
NTP Client:

Code: Select all

# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help

tinker panic 0

driftfile /var/lib/ntp/ntp.drift


# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable


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

# 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


# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
# might also be helpful.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery

# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1

# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict 192.168.123.0 mask 255.255.255.0 notrust


# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
#broadcast 192.168.123.255

# If you want to listen to time broadcasts on your local subnet, de-comment the
# next lines.  Please do this only if you trust everybody on the network!
#disable auth
#broadcastclient

User avatar
bobstro
Posts: 193
Joined: Wed Feb 05, 2014 6:48 am
Location: Central Massachusetts, US
Contact: Website

Re: RPi as NTP server

Thu Sep 24, 2015 3:01 pm

I am not an ntp expert by any means, but I've played with ntp in other environments.

Does sudo ntpq -p show that ntp is synchronizing properly on the server? You should see at least one with "*" in the status column at left indicating the selected server and (hopefully) some with "+" indicating selection candidates. Here's my Internet-connected server's output:

Code: Select all

% ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+resolver1.level 10.67.0.18       3 u   41   64  177   12.816   -4.765   2.136
+int42.org       131.107.13.100   2 u   38   64  177   62.788   -0.115   0.695
*time-b.nist.gov .ACTS.           1 u   36   64  177   19.725    4.881  11.799
 142.54.181.202  .INIT.          16 u    -   64    0    0.000    0.000   0.000
 10.16.16.255    .BCST.          16 u    -   64    0    0.000    0.000   0.001
I notice that you have the server set to broadcast, but the client is not set to act as a broadcast client. I believe you need to uncomment the disable auth and broadcast client lines if using broadcast. I'd still expect it to work using unicast.

On my client, I have the following in /etc/ntp.conf:

Code: Select all

server 10.16.16.254 iburst
[...]
#disable auth
#broadcastclient
Here's the output of ntpq -p on the client:

Code: Select all

% ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*raspi09.local   204.9.54.119     2 u    -   64    1    5.728    1.448   0.886
A few notes:
* raspi09.local is my ntp server at 10.16.16.254
* The server connects to the Internet via wired Ethernet, and clients attach via wifi directly to the server
* Routing is not enabled on the server. Clients can only access the local (10.16.16.0/24) subnet

I think this mirrors what you are trying to do.

benandrews54
Posts: 14
Joined: Mon Oct 21, 2013 1:55 pm

Re: RPi as NTP server

Thu Sep 24, 2015 3:11 pm

Thanks for the advice. I ran ntpq -p again so I could copy the output into this response and it has started working. I am not sure what has made it work but I'm not going to complain!

I will keep an eye on it and see if it stays this way. I will uncomment the broadcast lines as well to ensure that I can use both broadcast and unicast.

User avatar
bobstro
Posts: 193
Joined: Wed Feb 05, 2014 6:48 am
Location: Central Massachusetts, US
Contact: Website

Re: RPi as NTP server

Thu Sep 24, 2015 9:41 pm

I never got broadcast working, so really can't say what the issues there might be. Unicast is working well though. Do keep in mind it can take some time (10s of seconds) for timesources to synchronize, so give it a few minutes. Also, it may change throughout the day if you're using multiple servers.

Glad you got it working! Your post reminded me I need to add ntp to my network testing configuration.

Return to “Networking and servers”