[ntp:questions] Reference 'sntp' utility: how do you set the destination port number
agcarver+ntp at acarver.net
Tue Jul 2 14:50:41 UTC 2019
On 2019-06-29 19:09, stuartl at longlandclan.id.au wrote:
> Hi all,
> This will seem like a silly request, but how do you set the sntp client (distributed with the 'ntp' package in Debian) port number?
> The reason I need this is that I need to synchronise time with clients whose only link to the outside world is a 1200-baud AX.25 packet radio network. Running TCP/IP over this is an impossibility at present.
> The devices (partly due to an oversight on my part), do not have an RTC. When first booted, they think the time is 2016.
> The boards have been manufactured, it's too late to suggest that as the solution. (The next revision *does* have a space for an RTC.) The devices have two serial ports, one connected to an RFID reader, the other to an AX.25 TNC. There is no room for a GPS, and no time to order one.
> Hindsight is 20/20, so I'm looking for a quick software solution.
> I have therefore written a program that can bind to an arbitrary UDP port, and can relay the NTP client requests and server responses over the AX.25 network. It is written in Python 3 and implements all of the AX.25 logic along with the data collection function it is meant to perform.
> Basically, UDP datagram (containing NTP payload) goes in, APRS-formatted AX.25 "un-numbered information frame" comes out. APRS UI frame comes in, UDP datagram gets sent back to the (S)NTP client.
> I do not need, nor want, this script to run as 'root'. So there goes binding to port 123/udp. I am instead using 3123/udp. I'd like 'sntp' to talk to that.
> 'chrony' can talk on an alternate port, but it takes many measurements to synchronise the time, which is not ideal, it often takes many minutes to synchronise. I don't need millisecond precision, I just need stations to be within 60 seconds of each other ('ntp' can take over and fine tune it from there). I don't care that the date suddenly jumps from 2016 to 2019 -- I care more that the device "lives in 2016" for more than a few minutes.
> I really just need a one-shot tool like 'ntpdate'. I understand that 'sntp' is that tool. What is the command line option I use to make it talk to a NTP server that is on a different port to the standard?
Clients don't bind to ports. sntp will connect outbound on UDP 123 as a
normal user just fine (I just tested it myself on a Debian system).
However, if you don't run as root you won't be able to set the system clock.
$ sntp -d 10.0.0.1
2 Jul 07:48:55 sntp: Started sntp
2 Jul 07:48:55 sntp: kod_init_kod_db(): Cannot open KoD db file
sntp sendpkt: Sending packet to 10.0.0.1... Packet sent.
sntp recvpkt: packet received from 10.0.0.1 is not authentic.
Authentication not enforced.
sntp handle_pkt: Received 48 bytes from 10.0.0.1
sntp offset_calculation: t21: -0.000545 t34: -0.011008
delta: 0.010462 offset: -0.005776
2019-07-02 07:48:55.219316 (+0800) -0.005776 +/- 0.031540 secs
2 Jul 07:48:55 sntp: Can't open KOD db file /var/db/ntp-kod for
You can also look at the fake-hwclock package which keeps a timestamped
file updated and reads the timestamp at boot to get the clock close to
current time. That will at least solve your 2016/2019 problem.
More information about the questions