1

I have several machines running 16.10, both servers and laptops, all on the same network. All of them occasionally have the same problem with NTP. The clock drifts slightly out of sync and when I check the NTP peers there is only one and it's not being used.

> ntpstat 
unsynchronised
   polling server every 8 s

> sudo ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 10.x.x.x        .INIT.          16 u    -   64    0    0.000    0.000   0.000

I've tried with the default Ubuntu ntp.conf server list (from 0 to 3) of

pool 0.ubuntu.pool.ntp.org iburst
...

And also with the standard ntp list (also from 0 to 3) like so:

server 0.pool.ntp.org
...

But the issue is the same. The IP address of the unused server is always the same on all the machines, regardless of their ntp.conf.

I can temporarily solve it by making a change to ntp.conf and restarting ntpd but would like to fix the source of the problem so that useful peers are found automatically.

What can I try to fix this?

1 Answer 1

6

The servers and pools in /etc/ntp.conf were being ignored because the default Ubuntu configuration gives precedence to NTP servers found via DHCP.

There is a script, /etc/dhcp/dhclient-exit-hooks.d/ntp which creates a copy of /etc/ntp.conf at /var/lib/ntp/ntp.conf.dhcp, removes any specific servers and pools requested in the original and substitutes servers found via DHCP.

When /etc/init.d/ntp is run, if it finds a newer configuration at /run/ntp.conf.dhcp it will launch NTP with that. This can be disabled in many ways, but I chose to comment out that behaviour in /etc/init.d/ntp like so:

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

Then delete the DHCP script, reload daemon scripts and restart NTP:

sudo rm /run/ntp.conf.dhcp
sudo systemctl daemon-reload
sudo systemctl restart ntp

Now when NTP is started, the DHCP-discovered NTP servers are ignored and the pools are used to find working NTP servers.

Edit: Updated file paths for Ubuntu 20.04

1
  • 18.04 > /run/ntp.conf.dhcp is what init looks for. Which it yet another copy of /var/lib file. SMH. if [ -e /run/ntp.conf.dhcp ]; then NTPD_OPTS="$NTPD_OPTS -c /run/ntp.conf.dhcp" fi
    – B. Shea
    Sep 15, 2018 at 21:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .