How can Ubuntu 16.04 LTS be forced to use the manually configured list of NTP servers in /etc/ntp.conf
even if DHCP tries to provide a different one?
On Ubuntu 16.04 LTS (and probably all later releases), when an interface is configured via DHCP and the DHCP server response contains NTP server information, dhclient
creates a configuration file /var/lib/ntp/ntp.conf.dhcp
which overrides the configuration in /etc/ntp.conf
and contains only the NTP server(s) received via DHCP, not the ones configured explicitly.
This happens even if (as recommended over on Server Fault) the request
directive in /etc/dhcp/dhclient.conf
is set explicitly to a list not containing the ntp-servers
keyword.
In my case, a set of servers distributed worldwide receives its IP addresses via DHCP from each site's ISP access router but are required to synchronize their clocks to a common set of NTP servers.
This is https://bugs.launchpad.net/ubuntu/+source/ntp/+bug/1823098
I can't remember the exact version where this was changed, but until they fixed a bug where the DHCP-provided servers were not always picked up (I can't find the bug reference at the moment), one workaround was to put a tab in front of the
peer
,pool
, orserver
directives in your/etc/ntp.conf
. This doesn't fully solve the problem, because the DHCP-provided NTP servers are still included in the configuration, but at least it doesn't get rid of the ones you've explicitly configured. Depending on your patch level, this may not work.To fully fix this, you'll need to patch or remove
/etc/dhcp/dhclient-exit-hooks.d/ntp
. I'm not sure which change would survive upgrades better. If removing the file works, that's probably the cleanest solution. Otherwise, a patch like this might do the trick: