/etc/init.d/ntp prefers DHCP over configured /etc/ntp.conf

Bug #1823098 reported by Haw Loeung
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-images
New
Undecided
Unassigned
ntp (Ubuntu)
New
Undecided
Unassigned
Xenial
New
Undecided
Unassigned
Bionic
New
Undecided
Unassigned
Focal
New
Undecided
Unassigned

Bug Description

Hi,

On a few instances in a public cloud, mostly seen in GCE, ntp seems incorrectly set up with:

| ubuntu@juju-453c71-0:~$ ntpq -pn
| remote refid st t when poll reach delay offset jitter
| ==============================================================================
| *169.254.169.254 71.79.79.71 2 u 737 1024 377 0.657 0.136 0.147

We have /etc/ntp.conf configured to use ntp.ubuntu.com as a 'pool' host. Turns out, it seems the /etc/init.d/ntp prefers the DHCP version over our configured ntp.conf:

| if [ /var/lib/ntp/ntp.conf.dhcp -nt /etc/ntp.conf ]; then
| NTPD_OPTS="$NTPD_OPTS -c /var/lib/ntp/ntp.conf.dhcp"
| fi

| ubuntu@juju-453c71-0:/etc$ ls -la /var/lib/ntp/ntp.conf.dhcp /etc/ntp.conf
| -rw-r--r-- 1 root root 626 Feb 25 08:54 /etc/ntp.conf
| -rw-r--r-- 1 root root 897 Mar 29 21:00 /var/lib/ntp/ntp.conf.dhcp

I think this is wrong, if /etc/ntp.conf is configured, it should use that over what DHCP/dhclient provides.

| ubuntu@juju-453c71-0:~$ cat /etc/*release
| DISTRIB_RELEASE=16.04
| DISTRIB_DESCRIPTION="Ubuntu 16.04.6 LTS"
| VERSION_ID="16.04"

| ubuntu@juju-453c71-0:~$ dpkg-query -S /etc/init.d/ntp
| ntp: /etc/init.d/ntp

| ubuntu@juju-453c71-0:~$ apt-cache policy ntp
| ntp:
| Installed: 1:4.2.8p4+dfsg-3ubuntu5.9
| Candidate: 1:4.2.8p4+dfsg-3ubuntu5.9
| Version table:
| *** 1:4.2.8p4+dfsg-3ubuntu5.9 500
| 500 http://us-central1.gce.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages
| 500 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages

Thanks,

Haw

Tags: xenial
Revision history for this message
Haw Loeung (hloeung) wrote :

A hacky workaround is the constantly touch/update the timestamp of /etc/ntp.conf.

description: updated
tags: added: xenial
Revision history for this message
ubuntuluser (ubuntuluser) wrote :

It's still an issue, can we get a fix please?

Revision history for this message
Jeremy Chadwick (koitsu) wrote :

This is still a problem, even as of focal. I ran into this today and was shocked/surprised to find ntpq -p kept showing the NTP server set in option 42 (DHCP server options), rather than what was hard-coded into /etc/ntp.conf. I absolutely had this working a few days prior! Things broke when the DHCP client on the system renegotiated its lease.

The problem, in the case of the systemd unit, is that the systemd unit uses ExecStart=/usr/lib/ntp/ntp-systemd-wrapper. That wrapper is a shell script that contains:

if [ -e /run/ntp.conf.dhcp ]; then
        NTPD_OPTS="$NTPD_OPTS -c /run/ntp.conf.dhcp"
fi

What populates this file is /etc/dhcp/dhclient-exit-hooks.d/ntp, which runs after DHCP client exits (so on a renew, refresh, etc.). This file is provided by the ntp package itself (per dpkg -S). There doesn't seem to be a way to short-circuit the logic in the file via any kind of override, nor in the wrapper mentioned above.

This kind of problem is exactly what happens when people try to make software "smart", rather than just leaving things alone and letting sysadmins configure things properly.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.