Some Bits: Nelson's log

6 posts about ntp

Starlink adds an NTP server

This is very cool: Starlink’s dish now has an NTP server serving GPS time. That should be highly accurate. If they implemented it right, it’s going to be your best source of time short of specialty hardware you installed yourself. Certainly better than anything you’ll get from the Internet. See discussion here.

The server advertises itself as stratum 1. Thta’s a bold promise of high accuracy but is appropriate for a GPS receiver. It also means most NTP clients will prefer it as the time source to anything from the Internet. Which seems right to me.

(FWIW, I’ve synced hosts with chrony for years now over Starlink using the default Ubuntu pool config. Despite the high jitter Chrony does a good job synchronizing, it estimates it’s got accurate time to within 2ms despite 50ms of root delay. )

I added the server a few minutes ago and my machine is already syncing to it. Will update new stats after it has run awhile.

Update 1

3 hours later and it’s definitely running nicely. Here’s a graph of root mean square offset, a measure of clock accuracy. Over the last month, setting clocks over Starlink Internet with the Ubuntu pool got me an RMS of about 275µs ... Now it’s more like 100 µs since using Starlink. Here’s a graph of the last 24 hours, the line is where I switched to Starlink’s clock.

Honestly I’m surprised at how well chronyc synced time over Starlink Internet. The servers are all 40-80ms away varying every few minutes, a huge amount of jitter. I think chronyc has special algorithms to estimate that kind of thing.

Also impressed with how Starlink has improved. A year ago, before the latency improvements, my RMS averaged 427µs. Here’s a graph of the RMS for the last two years, mostly on Starlink ISP.

Honestly all this stuff is astonishingly good timekeeping. 1ms accuracy with consumer parts and slightly wonky Internet connections. It’s nice now to have access to GPS time though!

Update 2

running for about 24 hours now and doing well. One issue with Dishy as a time server is it often reboots around 3am. Mine rebooted last night and while Chrony coped it definitely threw off time accuracy. The offset went from under 100µs to fluctuating between -1ms and 2ms. The RMS had converged as low as 30µs (very impressive) but reset to 800µs after the 3am reboot. Oddly I don’t see any evidence Chrony gave up on syncing to the clock entirely, but the root delay to it stopped being a steady 2ms and spiked up to 4ms for a couple of hours after the reboot. All of this is well within the bounds of an NTP client to cope but is an example of how it’s not quite as good as having a fully dedicated GPS time receiver. OTOH it’s free!

Some stats after a few hours

chronyc> tracking
Reference ID    : C0A86401 (192.168.100.1)
Stratum         : 2
Ref time (UTC)  : Tue Sep 17 20:16:58 2024
System time     : 0.000011511 seconds slow of NTP time
Last offset     : +0.000012743 seconds
RMS offset      : 0.000090009 seconds
Frequency       : 30.078 ppm slow
Residual freq   : +0.000 ppm
Skew            : 0.121 ppm
Root delay      : 0.001979256 seconds
Root dispersion : 0.002787174 seconds
Update interval : 512.1 seconds
Leap status     : Normal
chronyc> sourcestats
Name/IP Address            NP  NR  Span  Frequency  Freq Skew  Offset  Std Dev
==============================================================================
alphyn.canonical.com       48  28   13h     -0.020      0.111  +2013us  3097us
prod-ntp-3.ntp1.ps5.cano>  55  28   15h     -0.080      0.080    +66us  2833us
prod-ntp-4.ntp1.ps5.cano>  18   8  293m     +0.090      0.651  +2919us  3553us
prod-ntp-5.ntp4.ps5.cano>  64  30   18h     -0.053      0.069   +946us  2962us
ntp3.radio-sunshine.org    64  35   18h     -0.082      0.054  -2298us  2382us
rn5.quickhost.hk           18   8  310m     +0.075      0.326  +2550us  1875us
LAX.CALTICK.NET            34  22  569m     +0.051      0.100   +934us  1678us
time.cloudflare.com        24  17  413m     +0.103      0.153  +1269us  1407us
192.168.100.1              15  10  103m     +0.000      0.118   +173ns   167us

Lightweight NTP clients for Unix

NTP is important, it sets your system clock. A proper Unix machine with an ordinary network connection should be within 10ms of true time. The problem is the traditional software we use to do this, ntpd, is old and complicated and has had a lot of security problems. It also does way more than your typical server needs, supporting obscure protocols and funky hardware you’ll never access.

I think a modern Unix machine just needs a simple network only time setter. Poll the time from ~4 NTP servers, discipline the clock to ~10ms, implement leap seconds correctly. That’s about it. I’m on the fence about client-only; if it’s not a big deal to be a simple server, that’d be better. I’m also ignorant about security, the historical crypto stuff in ntpd is pretty woolly.

A lot of other people think there should be a simpler time settings, there’s a bunch of alternatives now.

  • chrony is the best alternative I know of. It seems to do time correctly, and it has some clever accommodations for running in difficult environments like a VM or on a machine like a laptop that’s asleep a lot of time.
  • NTPSec, a big effort to first simplify the old ntpd code, then port it to a safe language like Rust or Go. The project has some problems but they are getting ambitious work done. Keep an eye on it.
  • systemd-timesyncd is everywhere now thanks to systemd. It’s too simple though, really just an SNTP client, and can’t discipline the clock nearly accurately enough to be useful for good time.
  • ntimed, see the blog. This project was looking promising but seems to have stalled out.
  • openntpd, the OpenBSD rewrite of an NTP daemon. It has a lot of problems including good clock discipline and leap seconds and is not really suitable.
  • ntpd! The venerable classic. Despite the problems the bugs are being fixed and it’s still the daemon I suspect powers most of the world’s Unix machines.

Chrony has a very useful comparison of chrony, ntp, and openntpd. The Performance numbers at the bottom are what’s most interesting to me (those numbers are microseconds).

End of the day, I think ntpd is still a decent choice. Chrony looks like the best alternative. I don’t have experience with it to comment on. I have no way of knowing if it’s more secure than ntpd. It’s also in C and has had some security problems.

Ubuntu 16 NTP notes

I love NTP. What’s it look like in Ubuntu 16? ntpd is pretty much the same, but some change or things I’ve never noticed before.

Debug mode 7 queries are now entirely disabled. The ntpdc program basically doesn’t work; you use ntpq instead. Given the number of times this protocol has been used in a UDP amplification DDOS, it’s a necessary change.

ntpd is started with the -g flag. This flag allows NTP to set the system clock once no matter how far out of sync it is. The default behavior is to never move the clock more than 1000s as a sort of sanity check. In practice it’s usually the client that’s insane, not the server.

servers are now configured like this

pool 0.ubuntu.pool.ntp.org iburst

“iburst” means the ntpd will try 8 times in 16 seconds to reach an unreachable server. The “pool” directive is not in the man pages, but these docs explain it. It tells ntpd to use DNS differently, to look up random new IP addresses every time. I’m not positive but I think ntpd still isn’t smart enough to look up a new pool IP address every few days or when a server goes offline. But at least it’ll get different IP addresses for the same hostname.

In addition to ntpdate/ntpd, Ubuntu also now provides timedatectl and systemd-timesyncd, part of the systemd hydra. It’s not very well documented; see Arch’s docs and this announcement. It’s a lightweight client-only time synchronizer. That seems like a good idea for security / client footprint. But it may be a bit too lightweight. It sounds like it only gets time from one server, for instance, and I wonder if they’re doing the PLL clock syncing that makes ntpd so good. systemd’s stuff gets out of the way if you are running ntpd.

NTP surveys

Way back in 1999 I did a survey of NTP. I spidered the whole Internet’s collection of NTP servers and published some statistics. From a desktop Linux box in my office at MIT, without permission, which raised a few eyebrows. But it was the 90s Internet and it was awesome.

These days NTP is much more widely deployed. It’s also been the cause of some security exploits and DDOS traffic, so I fear my kind of survey is much harder to do now. But I get requests about it occasionally, I think mostly from students. Here’s an email of answers I just sent today. Shodan’s view of NTP servers looks like an interesting place to start.

First of all,you use ntpq or ntpdc to do the query,is there any other method to do that now?

I mostly used ntpdc for access to the “monlist” command, which shows clients who are asking for the time (ie: downstream links). Both ntpq and ntpdc support “peers” to show where this particular server is asking for time (ie: upstream links). I also have used ntpdate to just query the time.

Secondly considering the Internet security,most of hosts are behind the firewalls,can the final result actually reflect to the true conditions?

Yes, you are right. It was a concern in 1999 when I did my survey and it’s only gotten much worse. I wonder now whether a survey like I did is even possible. There have been several high-profile security problems with NTP in the past few years, including an exploit in ntpd using monlist. Also NTP queries can be used for DDOS queries. The net result is that most servers are much more secure now and may not answer anything other than a basic “what time is it” query. Also I suspect a survey like mine would set off many alarms.

Finally,can I conduct the survey on a computer running Windows operating system?Can you give me some suggestions?

It should be possible on Windows, but I’m not sure how to do it. You want some way to make ~100 NTP requests simultaneously. It’s pretty easy since it’s just a UDP protocol, but I don’t know the best way to do that on Windows.
Two other things you should look into:
The NTP Pool is where most Internet clients get their time today. There’s about 4000 servers total and I’m sure there are plenty of opportunities to survey and research just those servers. The NTP pool developer community is friendly, you should talk to them before doing any significant survey work.
These days it is relatively easy to query every single IPv4 address in the world, all 4 billion of them. One site that does this regularly is Shodan. For example, here is their search result showing 835,000 NTP servers: https://www.shodan.io/search?query=ntp

NTP kibbitzing

This Metafilter discussion about the ntpd developer needing funding got me thinking more about NTP. I wrote a few comments on MeFi that have good content.

But the big revelation for me is NTimed, PHK’s project to write an ntpd replacement. His notes are very encouraging. The big excitement is that he’s explicitly building a client-only version of the code for 99.99% of users, and he thinks he can keep it to < 10,000 lines of code. That would be fantastic, both for security and for performance. I hope it’s a success. So far it looks very promising.