{"id":4553,"date":"2024-11-11T21:42:46","date_gmt":"2024-11-12T02:42:46","guid":{"rendered":"https:\/\/blogs.n1zyy.com\/n1zyy\/?p=4553"},"modified":"2024-11-11T21:42:46","modified_gmt":"2024-11-12T02:42:46","slug":"building-a-stratum-1-ntp-server-on-ec2","status":"publish","type":"post","link":"https:\/\/blogs.n1zyy.com\/n1zyy\/2024\/11\/11\/building-a-stratum-1-ntp-server-on-ec2\/","title":{"rendered":"Building a stratum 1 NTP server on EC2"},"content":{"rendered":"<p>I won&#8217;t even try to pretend I&#8217;m not a huge geek here&#8230;<\/p>\n<p>I&#8217;ve run public NTP servers for ages, and been somewhat intrigued ever since a dedicated server ended up misclassified as being in Brazil and got an enormous volume of traffic, but without impacting performance. I have a DigitalOcean droplet in Singapore that&#8217;s serving a few terabytes a month of NTP queries; the pool tells me it&#8217;s about 3% of pool traffic for all of Singapore.<\/p>\n<p>NTP servers are categorized into strata, essentially indicating how far down in the chain a clock is. A stratum 1 server gets its time directly from a (non-NTP) reference source, and a system syncing to a stratum 1 server becomes stratum 2, and so forth. (As an aside, strata don&#8217;t actually have enormous significance: a local stratum 3 is probably more accurate than a stratum 1 on the other side of the globe.)<\/p>\n<p>For years, EC2 instances have had <a href=\"https:\/\/aws.amazon.com\/about-aws\/whats-new\/2017\/11\/introducing-the-amazon-time-sync-service\/\">Time Sync<\/a> available over a link-local address. This, incidentally, has proven the point about server stratum not being everything: the Time Sync server is generally at stratum 3, but I infer that everything up to stratum 1 occurs within the availability zone, if not data center, level. Given the link-local Time Sync address and some good stratum 1 clocks within the country, my servers running in AWS typically end up syncing to Time Sync. I have a couple servers in the pool at stratum 4 as a result. It&#8217;s further down &#8220;the chain,&#8221; but it&#8217;s a particularly good chain.<\/p>\n<p>But more recently, Amazon has been <a href=\"https:\/\/docs.aws.amazon.com\/AWSEC2\/latest\/UserGuide\/configure-ec2-ntp.html#connect-to-the-ptp-hardware-clock\">making PTP available<\/a> on certain instance types in certain regions. While PTP can be succinctly described as a more precise version of NTP (it is, after all, the Precision Time Protocol), it&#8217;s a <em>lot<\/em> more precise, making use of hardware timestamping the whole way, and can therefore achieve sub-microsecond accuracy.<\/p>\n<p>And so, I spun up <a href=\"https:\/\/www.ntppool.org\/scores\/43.216.110.218\">an instance in Malaysia<\/a> and put it in the pool. I&#8217;ve kept it at only 512 kbps because there were only 3 IPv4 servers in all of Malaysia, and AWS bandwidth pricing is obscene. It has the PTP Hardware Clock (PHC) set up as a reference source, and is reporting offsets in the range of a handful of nanoseconds.<\/p>\n<p>I went a step further and configured it for <a href=\"https:\/\/www.internetsociety.org\/blog\/2020\/08\/everything-you-need-to-know-about-network-time-security\/\">NTS<\/a>. This required a hostname, and in trying to use Porkbun to find a novel domain name, I stumbled over the fact that ntpservers.org was open. Obviousy, I went ahead and registered it.<\/p>\n<p>So now there is <code>malaysia-1.ntpservers.org<\/code> online, as a stratum 1 NTP server in Malaysia supporting NTS.<\/p>\n<p>As an aside: I ended up bringing up <code>malaysia-2.ntpservers.org<\/code> as well in a (seemingly paradoxical) attempt to save money. It&#8217;s a cheap instance as a provider including 2TB of bandwidth for under $10\/month (USD). Amusingly, its default config synced to the pool and had selected my stratum 1 server. I cleaned the config up slightly to point to some stratum 1 clocks in Japan an Singapore, and it&#8217;s been fielding a lot more traffic from the pool at a higher bandwidth setting.<\/p>\n<p>I have not yet listed it anywhere outside registering it in the pool, because it&#8217;s currently more of a novelty than a long-term committment. I am tempted to eventually withdraw <code>malaysia-1<\/code> from the pool but list it as an available stratum 1 supporting NTS on the relevant sites to hopefully cut down bandwidth costs and make it reasonable to maintain long-term.<\/p>\n<p>Right now the other AWS regions supporting PTP instances are all areas well-served by stratum 1 clocks: Tokyo and the United States. It will be interesting to see if it becomes available in, say, India, where the available options are more limited.<\/p>","protected":false},"excerpt":{"rendered":"<p>I won&#8217;t even try to pretend I&#8217;m not a huge geek here&#8230; I&#8217;ve run public NTP servers for ages, and been somewhat intrigued ever since a dedicated server ended up misclassified as being in Brazil and got an enormous volume &hellip; <a href=\"https:\/\/blogs.n1zyy.com\/n1zyy\/2024\/11\/11\/building-a-stratum-1-ntp-server-on-ec2\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[],"class_list":["post-4553","post","type-post","status-publish","format-standard","hentry","category-ntp"],"_links":{"self":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts\/4553","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/comments?post=4553"}],"version-history":[{"count":0,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts\/4553\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/media?parent=4553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/categories?post=4553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/tags?post=4553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}