Time server setup

From snippet wiki
Jump to navigation Jump to search

Some steps to remember when setting up a Raspberry Pi based network time server.

Boot setup files

Add to /etc/modules


Add to /boot/config.txt


Add to /boot/cmdline.txt at end of single line



Install several extra tools

  • ntp-utils
  • ntpsec
  • minicom
  • gpsd
  • pps
  • pps-tools
  • ptpd

Disable serial login on AMA0 device.

systemctl mask serial-getty@ttyAMA0.service

Disable unused services like cupsd.


Update /etc/defaults/gpsd to

# Default settings for the gpsd init script and the hotplug wrapper.

# Start the gpsd daemon automatically at boot time

# Use USB hotplugging to add new USB devices automatically to the daemon

# Devices gpsd should collect to at boot time.
# They need to be read/writeable, either by user gpsd or the group dialout.

# Other options you want to pass to gpsd

Update /etc/defaults/ntpsec to


# Set to "yes" to ignore DHCP servers returned by DHCP.

Update /etc/defaults/ptpd to

# /etc/default/ptpd

# Set to "yes" to actually start ptpd automatically

# Add command line options for ptpd
PTPD_OPTS="-c /etc/ptpd2.conf"

Service setup files

Update /etc/ntpsec/ntp.conf to

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

driftfile /var/lib/ntpsec/ntp.drift
leapfile /usr/share/zoneinfo/leap-seconds.list

# You must create /var/log/ntpsec (owned by ntpsec:ntpsec) to enable logging.
statsdir /var/log/ntpsec/
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

# Comment this out if you have a refclock and want it to be able to discipline
# the clock by itself (e.g. if the system is not connected to the network).
#tos minclock 4 minsane 3

# Specify one or more NTP servers.

# 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: <https://www.pool.ntp.org/join.html>
pool 0.de.pool.ntp.org iburst maxpoll 5
#pool 1.de.pool.ntp.org iburst
#pool 2.de.pool.ntp.org iburst
#pool 3.de.pool.ntp.org iburst

# Access control configuration; see /usr/share/doc/ntpsec-doc/html/accopt.html
# for details.
# 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 nopeer noquery limited

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

# GPS Serial data reference (NTP0)
fudge time1 +0.100 refid GPS

# GPS PPS reference (NTP1)
server prefer
fudge refid PPS

Update /etc/ptpd2.conf to

# config




Final result

With some luck and reboots the ntpq -p command should show:

root@clock:/etc# ntpq -p
     remote                                   refid      st t when poll reach   delay   offset   jitter
 0.de.pool.ntp.org                       .POOL.          16 p    -   32    0   0.0000   0.0000   0.0010
+SHM(0)                                  .GPS.            0 l   59   64  377   0.0000  -2.5372   0.6387
*SHM(1)                                  .PPS.            0 l   58   64  377   0.0000   0.0027   0.0020
-static.    2 u    4   32  377  23.0398   5.2349   2.0621
-ntp1.sul.t-online.de              2 u   29   32  377  24.0259   2.1013   3.3369
-kuehlich.com                      2 u   19   32  377  28.6138   4.2736   5.8902
-ntp2.wtnet.de                       2 u   26   32  377  28.5456  -9.2126   4.9001
+time.cloudflare.com                   3 u   19   32  377  18.1886   6.0767   5.8235
-telesto.hot-chilli.net            2 u   26   32  277  24.0233   2.5571   5.9801
-nono.com                         2 u   10   32  377  25.0837   3.8292   3.0114

Which is good enough for me to play with.