Ubuntu – Setting multiple NTP servers in /etc/systemd/timesyncd.conf

ntpsystemd-timesyncd

The man page for timesyncd.conf(5) indicates that the setting for NTP is a space-separated list of NTP server host names or IP addresses.

We have two internal NTP servers in our network, both on the same subnet (10.10.10 0/24). On an Ubuntu 18.04 server, if I set NTP to NTP="10.10.10.100 10.10.10.101", timesyncd will not synchronize with those time servers. If I just set NTP to one of them (NTP=10.10.10.100 or NFS=10.10.10.101), time is synchronized as expected.

Is anyone else seeing the same behavior? Or is this a bug that should be (or has been) submitted?

Addendum: Instead of one line, I tried using multiple "NTP=" lines. Instead of:

NTP="10.10.10.100 10.10.10.101"

I changed it to:

NTP=10.10.10.100
NTP=10.10.10.101

After restarting systemd-timesyncd the status now shows the time being synchronized to the first time server.

$ systemctl status systemd-timesyncd.service

● systemd-timesyncd.service - Network Time Synchronization
   Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/systemd-timesyncd.service.d
           └─disable-with-time-daemon.conf
   Active: active (running) since Fri 2018-06-22 14:41:36 MDT; 3s ago
     Docs: man:systemd-timesyncd.service(8)
 Main PID: 2774 (systemd-timesyn)
   Status: "Synchronized to time server 10.10.10.100:123 (10.10.10.100)."
    Tasks: 2 (limit: 2322)
   CGroup: /system.slice/systemd-timesyncd.service
           └─2774 /lib/systemd/systemd-timesyncd

Jun 22 14:41:36 bpsubuntu18.sling.com systemd[1]: Starting Network Time Synchronization...
Jun 22 14:41:36 bpsubuntu18.sling.com systemd[1]: Started Network Time Synchronization.
Jun 22 14:41:36 bpsubuntu18.sling.com systemd-timesyncd[2774]: Synchronized to time server 10.10.10.100:123 (10.10.10.100).

As an addition test I added a bogus time server line before the two good ones:

NTP=10.10.10.99
NTP=10.10.10.100
NTP=10.10.10.101

After another restart of the service, and watching port 123 traffic using tcpdump, I saw that after failing to get the time from the bogus NTP server, timesyncd then used the next one.

So is the man page incorrect? Or is not parsing the space-separated list a bug?

I'd also like to apologize for typing NFS instead of NTP when I first posted. Distracted by another task I was working on…

Best Answer

this is by design of timesyncd. TL;DR it is only capable to use one at a time.

Details: If you look very hard at the timesyncd man page you will see that is say in the section about multiple NTP servers:

... until one is found that responds ...

If you dig deeper you'll find issues like timesyncd: talks only to one NTP server at a time and systemd-timesyncd manual should explain it uses SNTP, not NTP.

So it will take the first one out of the NTP= list that works, and if all in there fail try the list in FallbackNTP=.

If you want real cross server checks for better sync you should take a look at NTPd (<18.04) / Chrony (>=18.04) quoting the systemd issue on that:

Yeah, systemd-timesyncd implements SNTP, not NTP, hence multi-server support is out of focus. If you want a full NTP implementation, please use ntpd or chrony.

Related Question