How to use time.cloudflare.com on Linux

Cloudflare released an NTP service recently. This guide will show you how to start using Cloudflare's NTP service on Ubuntu Linux.

How to use time.cloudflare.com on Linux

As part of their crypto week, Cloudflare announced a suite of time-related products.

RoughtimeA protocol to get very secure time synchronization with a penalty to how accurate it is ( +- a few seconds )
NTSSupport for NTP over tls, a new protocol with limited support.
NTPTraditional NTP served over cloudflare's any-cast network

Cloudflare NTP on Linux

Although you'll have to wait a while to use NTS or Roughtime on your computer, you can use their NTP service today. The link above shows you how to use Cloudflare NTP on OSX and Windows, but they do not provide how-to for Linux. So here it is.

  1. First, check that your system is using timedatectl. Were going to change it's config to use time.cloudflare.com.
zwrawr@sol ~ $ timedatectl status
               Local time: Sat 2019-06-22 13:08:55 BST
           Universal time: Sat 2019-06-22 12:08:55 UTC
                 RTC time: Sat 2019-06-22 12:08:55
                Time zone: Europe/London (BST, +0100)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
  1. Second, check which NTP service you're currently using. On my Ubuntu machine, this was ntp.ubuntu.com.
zwrawr@sol ~ $ sudo systemctl status systemd-timesyncd
● systemd-timesyncd.service - Network Time Synchronization
   Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2019-06-21 22:28:23 BST; 2min 6s ago
     Docs: man:systemd-timesyncd.service(8)
 Main PID: 18484 (systemd-timesyn)
   Status: "Synchronized to time server 91.189.94.4:123 (ntp.ubuntu.com)."
    Tasks: 2 (limit: 4915)
   Memory: 1.7M
   CGroup: /system.slice/systemd-timesyncd.service
           └─18484 /lib/systemd/systemd-timesyncd

Jun 21 22:28:23 sol systemd[1]: Starting Network Time Synchronization...
Jun 21 22:28:23 sol systemd[1]: Started Network Time Synchronization.
Jun 21 22:28:23 sol systemd-timesyncd[18484]: Synchronized to time server 91.189.94.4:123 (ntp.ubuntu.com).
  1. Update timesyncd's config by adding time.cloudflare.com as they primary NTP server and uncommenting it.
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See timesyncd.conf(5) for details.

[Time]
#NTP=
#FallbackNTP=ntp.ubuntu.com
#RootDistanceMaxSec=5
#PollIntervalMinSec=32
#PollIntervalMaxSec=2048

becomes

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See timesyncd.conf(5) for details.

[Time]
NTP=time.cloudflare.com
FallbackNTP=ntp.ubuntu.com
#RootDistanceMaxSec=5
#PollIntervalMinSec=32
#PollIntervalMaxSec=2048

  1. Then restart the service
zwrawr@sol /etc/systemd $ sudo systemctl restart systemd-timesyncd
zwrawr@sol /etc/systemd $ sudo systemctl status systemd-timesyncd
● systemd-timesyncd.service - Network Time Synchronization
   Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2019-06-21 22:33:47 BST; 6s ago
     Docs: man:systemd-timesyncd.service(8)
 Main PID: 19785 (systemd-timesyn)
   Status: "Synchronized to time server 162.159.200.123:123 (time.cloudflare.com)."
    Tasks: 2 (limit: 4915)
   Memory: 1.6M
   CGroup: /system.slice/systemd-timesyncd.service
           └─19785 /lib/systemd/systemd-timesyncd

Jun 21 22:33:46 sol systemd[1]: Starting Network Time Synchronization...
Jun 21 22:33:47 sol systemd[1]: Started Network Time Synchronization.
Jun 21 22:33:47 sol systemd-timesyncd[19785]: Synchronized to time server 162.159.200.123:123 (time.cloudflare.com).

Now your using systems time is synced with a time.cloudflare.com server in one of Cloudflare's 180+ locations worldwide.