What's new

Route all ntp traffic to my ntp raspberry pi serverHow

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

something to look at - add the ntp-server to the /etc/dnsmasq.conf file

first - confirm if your dnsmasq supports option 42 (ntp-server) - dnsmasq -w dhcp - I've confirmed that the dnsmasq that is included with AsusWRT-RMerlin definitely supports the option...

now - add the line below at the tail end of the dnsmasq.conf file...

# add the LAN Network Time Server
dhcp-option=42,hostip
# example - dhcp-option=42,192.168.1.53

then either reboot the router, or do a killhup on the dnsmasq process.

Most DHCP clients should support the option - as belt and suspenders, one can add the iptables rule as discussed above.


I noticed on my AC86U that every time I reboot the router dsnmasq.conf get replaced? So I added it to dnsmasq.conf.add file.
 
Looks good. Now, if your GPS module is suddenly disconnected from the Pi, does the Pi still serve time to clients? Does it fail over to a reasonable time source and continue even when there's a GPS blackout? Consider adding an Undisciplined Local Clock to your ntp.conf, and give it a high stratum number. https://www.eecis.udel.edu/~mills/ntp/html/drivers/driver1.html

Code:
admin@RT-AC68U-XXXX:/# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
oGPS_NMEA(0)     .GPS.            0 l    1   16  377    0.000   -0.029   0.042
 LOCAL(0)        .LOCL.          15 l    -   64    0    0.000    0.000   0.000

There's also something called 'orphan mode', but I don't understand it. I worry about my enemy shooting the satellites out of orbit.

I never seen any blackout from the gps. So it's stable. I should most like try to squeeze in a RTC. It's PPS disciplined.

I find the ntp configuration stuff extremely difficult to setup and understand. why is it so complicated. People really need to be shot...
 
Looks like Diversion is replacing dnsmasq.conf each time I reboot or kill dnsmasq.

wow...
The firmware regenerates dnsmasq.conf every time it is restarted.
You use a /jffs/scripts/dnsmasq.postconf script to alter the configuration, or a /jffs/configs/dnsmasq.conf.add to add something to it.
 
The firmware regenerates dnsmasq.conf every time it is restarted.
You use a /jffs/scripts/dnsmasq.postconf script to alter the configuration, or a /jffs/configs/dnsmasq.conf.add to add something to it.

Thanks. I did the /jffs/configs/dnsmasq.conf.add restarted and its there now.

Ok logging on the ntp server seening if more devices will go to the server.
 
I should most like try to squeeze in a RTC.
Connect the battery-backed RTC to the Pi, and then run "hwclock -s" during Linux boot time, to set the System Clock from the RTC. Great, now you've got the correct time in your system logs.

Once your GPS is locked on to the satellites, you can do "hwclock -w" to keep the battery-backed RTC in sync with the atomic clocks, very accurate time.

Lastly, consider adding an Undisciplined Local Clock (a.k.a. "the clock of last resort") to your NTP server, just in case the USAF comes.
 
I noticed on my AC86U that every time I reboot the router dsnmasq.conf get replaced? So I added it to dnsmasq.conf.add file.

For AsusWRT, like mentioned, changes would apply to the dnsmasq.conf.add file, not directly to dnsmask.conf - the net effect should be the same I would think.
 
I checked the syslog and only devices which I have setup to 192.168.1.88 (raspberry pi ntp server) are working. All the rest of my devices that have hard code ntp settings are still not getting router to the raspberry pi...

Any suggestions?
 
Any suggestions?

/jffs/scripts/nat-start
Code:
#!/bin/sh
iptables -t nat -I PREROUTING -i br0 -s 192.168.1.0/24 -p udp --dport 123 -j DNAT --to-destination 192.168.1.88


AND, resolve the DNS name locally, so that NTP clients function properly when there is no Internet connection or your upstream DNS server is down:

/jffs/configs/dnsmasq.conf.add
Code:
#!/bin/sh
address=/ntp.ubuntu.com/192.168.1.88
address=/ntp.canonical.com/ntp1.canonical.com/ntp2.canonical.com/ntp3.canonical.com/ntp4.canonical.com/192.168.1.88
address=/time-a.timefreq.bldrdoc.gov/time-b.timefreq.bldrdoc.gov/time-c.timefreq.bldrdoc.gov/192.168.1.88
address=/utcnist2.colorado.edu/192.168.1.88
address=/nist1-chi.ustiming.org/nist1-lv.ustiming.org/nist1-ny.ustiming.org/192.168.1.88
address=/time.nist.gov/time-nw.nist.gov/time-a.nist.gov/time-b.nist.gov/time-c.nist.gov/time-d.nist.gov/192.168.1.88
address=/time.windows.com/192.168.1.88
address=/tick.usno.navy.mil/tock.usno.navy.mil/ntp.usno.navy.mil/ntp2.usno.navy.mil/tick.usnogps.navy.mil/tock.usnogps.navy.mil/192.168.1.88
address=/ntp.rokutime.com/192.168.1.88
address=/pool.ntp.org/0.pool.ntp.org/1.pool.ntp.org/2.pool.ntp.org/3.pool.ntp.org/192.168.1.88
address=/1-pool.ntp.org/2-pool.ntp.org/3-pool.ntp.org/4-pool.ntp.org/5-pool.ntp.org/6-pool.ntp.org/7-pool.ntp.org/8-pool.ntp.org/9-pool.ntp.org/10-pool.ntp.org/11-pool.ntp.org/12-pool.ntp.org/13-pool.ntp.org/14-pool.ntp.org/15-pool.ntp.org/16-pool.ntp.org/17-pool.ntp.org/18-pool.ntp.org/19-pool.ntp.org/20-pool.ntp.org/21-pool.ntp.org/22-pool.ntp.org/23-pool.ntp.org/24-pool.ntp.org/25-pool.ntp.org/26-pool.ntp.org/27-pool.ntp.org/28-pool.ntp.org/29-pool.ntp.org/30-pool.ntp.org/31-pool.ntp.org/32-pool.ntp.org/192.168.1.88

OR

/jffs/configs/hosts.add
Code:
192.168.1.88 ntp.ubuntu.com
192.168.1.88 ntp.canonical.com ntp1.canonical.com ntp2.canonical.com ntp3.canonical.com ntp4.canonical.com
192.168.1.88 time-a.timefreq.bldrdoc.gov time-b.timefreq.bldrdoc.gov time-c.timefreq.bldrdoc.gov
192.168.1.88 utcnist2.colorado.edu
192.168.1.88 nist1-chi.ustiming.org nist1-lv.ustiming.org nist1-ny.ustiming.org
192.168.1.88 time.nist.gov time-nw.nist.gov time-a.nist.gov time-b.nist.gov time-c.nist.gov time-d.nist.gov
192.168.1.88 time.windows.com
192.168.1.88 tick.usno.navy.mil tock.usno.navy.mil ntp.usno.navy.mil ntp2.usno.navy.mil tick.usnogps.navy.mil tock.usnogps.navy.mil
192.168.1.88 ntp.rokutime.com
192.168.1.88 pool.ntp.org 0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org 3.pool.ntp.org
192.168.1.88 1-pool.ntp.org 2-pool.ntp.org 3-pool.ntp.org 4-pool.ntp.org 5-pool.ntp.org 6-pool.ntp.org 7-pool.ntp.org 8-pool.ntp.org
192.168.1.88 9-pool.ntp.org 10-pool.ntp.org 11-pool.ntp.org 12-pool.ntp.org 13-pool.ntp.org 14-pool.ntp.org 15-pool.ntp.org 16-pool.ntp.org
192.168.1.88 17-pool.ntp.org 18-pool.ntp.org 19-pool.ntp.org 20-pool.ntp.org 21-pool.ntp.org 22-pool.ntp.org 23-pool.ntp.org 24-pool.ntp.org
192.168.1.88 25-pool.ntp.org 26-pool.ntp.org 27-pool.ntp.org 28-pool.ntp.org 29-pool.ntp.org 30-pool.ntp.org 31-pool.ntp.org 32-pool.ntp.org
 
Last edited:
During a GPS blackout, my NTP server transitions to the System Clock. How?

/jffs/configs/ntp.conf
Code:
# Undisciplined Local Clock
server 127.127.1.0
fudge 127.127.1.0 stratum 15


My GPS device is up on the roof of the building, for the best satellite reception. However, the USAF can simulate wartime conditions with a GPS blackout. What happens during a GPS blackout?

Before the blackout everything is fine
Code:
admin@RT-AC68U-XXXX:/# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
oGPS_NMEA(0)     .GPS.            0 l   12   16  377    0.000   -0.033   0.043
 LOCAL(0)        .LOCL.          15 l    -   64    0    0.000    0.000   0.000


During the blackout, my NTP server switches to the System Clock as the clock of last resort, when all other time sources have gone away. Otherwise, all NTP client synchronization requests will fail here!
Code:
admin@RT-AC68U-XXXX:/# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 GPS_NMEA(0)     .GPS.            0 l  335   16    0    0.000   -0.024   0.000
 LOCAL(0)        .LOCL.          15 l   30   64    7    0.000    0.000   0.002


Once the blackout is lifted, my NTP server reverts back to the GPS clock
Code:
admin@RT-AC68U-XXXX:/# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
oGPS_NMEA(0)     .GPS.            0 l    7   16  377    0.000    0.217   0.017
 LOCAL(0)        .LOCL.          15 l 1686   64    0    0.000    0.000   0.000


I dare you to try this with your setup.
 
/jffs/scripts/nat-start
Code:
#!/bin/sh
iptables -t nat PREROUTING -i br0 -s 192.168.1.0/24 -p udp --dport 123 -j DNAT --to-destination 192.168.1.88

/jffs/configs/dnsmasq.conf.add
Code:
#!/bin/sh
address=/.pool.ntp.org/ntp.ubuntu.com/.timefreq.bldrdoc.gov/time.nist.gov/time-nw.nist.gov/time-a.nist.gov/time-b.nist.gov/time-c.nist.gov/time-d.nist.gov/time.windows.com/tick.usno.navy.mil/tock.usno.navy.mil/ntp.usno.navy.mil/ntp2.usno.navy.mil/tick.usnogps.navy.mil/tock.usnogps.navy.mil/ntp.rokutime.com/192.168.1.88

It's working now! All the devices are going to the raspberry pi ntp server now! Thanks everyone.

I tried the above iptables command but got an error:
admin@RT-AC86U-F210:/tmp/etc# iptables -t nat PREROUTING -i br0 -s 192.168.1.0/24 -p udp --dport 123 -j DNAT --to-destination 192.
168.1.88
Bad argument `PREROUTING'
Try `iptables -h' or 'iptables --help' for more information.


So I used the originals:

iptables -t nat -D PREROUTING -i !ppp0 -p udp --dport 123 -j DNAT --to 192.168.1.88 2>/dev/null
iptables -t nat -A PREROUTING -i !ppp0 -p udp --dport 123 -j DNAT --to 192.168.1.88

The Nest thermostat, sprinkler system, webcam are all going to the raspberry pi!
 
During a GPS blackout, my NTP server transitions to the System Clock. How?

Have the local source as gps in ntpd.conf

Use netowkr ntp sources as backup, because is generally good enough...

With Pi and Raspbian - remember that systemd is running - and systemd has timesyncd to keep things sorted - that's why Pi gets the right time once systemd is done on the boot process without ntp even installed.

One can always run ntpd for local time obviously for both local and network resources on Pi..
 
Got the GPS module working on my SBC the other night. It's been a few nights since but with different configs. The most recent 24 hrs seems getting reliable signals consistently at my poor location in urban canyons.

Accurate timing is still very interesting for me but I accidentally discovered a new hobby: tracing satellite orbits. Here is a skymap on top of my head. Dare not post a better one...fearing some smart kids will be able to reverse engineer my exact location..

l5Qhzeo.png


All the G's are GPS satellites. R's GLONASS by Russia. E's Galileo from EU. B's Beidou from China. At locations with poor signals, GPS still the main driving force. Everyone shall be grateful about that. Galileo really should receive more credit than the press coverage provides. GLONASS compliments GPS quite well (no surprise with decades of engineering?).

Beidou-2 frankly is a bit disappointing. Can't get any signals from the five geostationary satellites. So lost half of usable signals instantly. Beidou-3 however looks promising. I could see test signals shooting sky high but not usable at the moment.

Very interesting stuff.
 

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top