0

I found variations to my question but I'm not sure those other topics answer my question specifically.

I have several smart switches on which I have flashed custom firmware. One of the primary reasons for having taken this step is so the devices operate without having to contact a cloud service external to my home network. The operation of the switches is no fully dependent on a live connection to the Internet.

I just realized that I did not address one issue that still requires that they reach the Internet - syncing their time with an NTP server. I would like to set up a time server on my LAN that I can point my IoT devices to to obtain their time sync.

I can configure the devices to any NTP server URL I wish. Currently each device has three NTP entries. I'd like to change the primary entry to point to a Raspberry Pi that can service the devices' time sync requests. I know it's possible to set my Raspberry Pi as an NTP server.

Release = Raspbian GNU/Linux 9 (stretch) Kernel = Linux 4.14.79-v7+ Platform = Raspberry Pi 3 Model B Rev 1.2

My question is this... Can the Raspberry Pi be set up to set it's clock by making Internet NTP requests (i.e., its an NTP client behaving as usual), and then it acts as an NTP server to my LAN devices using the time it obtains from the Internet?

Are there any issues with synchronization of timestamps the devices received from the Raspberry Pi vs. the timestamps that they receive from the DHCP server when the device requests its IP address? Is there going to be a conflict with my router?

I may not even be thinking of all the ramifications. Regardless, net-net, can the RPi serve up its clock time which it obtains from an Internet NTP server to my LAN devices? I want to avoid adding an RTC or GPS device as a prerequisite to just pointing my smart switches to a local time server.

Thank you in advance.

Mike

1

Get NTP installed everywhere with sudo apt update; sudo apt install ntp. Tell timesyncd that you're using NTP with sudo timedatectl set-ntp 1.

Run this config on your master time server (at 192.168.3.14 in my example):

driftfile /var/lib/ntp/ntp.drift
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
server 0.ubuntu.pool.ntp.org burst iburst maxpoll 11
server 1.ubuntu.pool.ntp.org burst iburst maxpoll 11
server 2.ubuntu.pool.ntp.org burst iburst maxpoll 11
server 3.ubuntu.pool.ntp.org burst iburst maxpoll 11
server ntp.ubuntu.com
restrict 127.0.0.1
restrict -6 ::1
restrict 192.168.3.0 mask 255.255.255.0
restrict -6 2001:pppp:pppp:pppp:: mask fffff:fffff:fffff:ffff::
broadcast 192.168.3.255
broadcast ff05::101
keysdir /etc/ntp
crypto

Set up NTP crypto on every machine with: sudo mkdir /etc/ntp; cd /etc/ntp; sudo ntp-keygen

Run this config on each slave machine

driftfile /var/lib/ntp/ntp.drift
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
server 192.168.3.14
server 2001:pppp:pppp:pppp:ba27:ebff:feed:cafe
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery
restrict 127.0.0.1
restrict ::1
keysdir /etc/ntp
crypto
broadcastclient

That's running on my network with one master machine and seventeen slave machines. I've masked the globally unique IPv6 addresses for security reasons.

  • Expanding... my "slaves" are not Linux nodes. They are ESP8266 based wireless smart switches. I do have a couple of Windows PCs on the LAN, but I had not intended on pointing them to this local time server. In fact, one of them has its admin policies locked (corporate PC) so I can't change its NTP settings. So, given the extensive detail you provided, coupled with my inexperience. Is it sufficient to have my RPi setup as indicated and then just point my smart switches to its NTP "URL"? – Mike Ingraham Jan 7 at 17:33
  • Same basic principle applies, but you'll need to disable the crypto pieces. It should work with a library like github.com/gmag11/NtpClient installed on your ESP8266. – Dougie Jan 7 at 17:35
  • I've sync'd my laptop to my RPi NTP server. I can't remember if that's working because I've also got CIFS/Samba installed on that Raspberry. – Dougie Jan 7 at 17:38
  • The firmware installed on my devices already understands how to sync its time from an NTP server. All I need now is that the RPi on my LAN can get it's time sync from a public NTP server, use that as the time source of requests made to it by my local devices, and respond only to explicit NTP requests (i.e., those directed to it via its specific URL). I am just trying to ensure that if I set up an NTP server on my RPi that I don't cause chaos elsewhere in my environment. – Mike Ingraham Jan 7 at 19:41
  • The stuff I've given you for an NTP server should meet your needs. Time will be available to 192.168.3.0/24 (in my example) on port 123 for any LAN device in the same subnet. – Dougie Jan 7 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.