DHCP exit hook for setting systemd-timesyncd NTP servers doesn't work

Bug #1685484 reported by slodki
30
This bug affects 5 people
Affects Status Importance Assigned to Milestone
network-manager (Ubuntu)
Confirmed
Undecided
Dimitri John Ledkov
systemd (Debian)
Fix Released
Unknown
systemd (Ubuntu)
Won't Fix
Low
Unassigned

Bug Description

I think it's regression for https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1578663 in zesty.

1. NTP servers are send via DHCP and seen by NM:

$ nmcli con show connection1 | grep ntp
DHCP4.OPTION[30]: requested_ntp_servers = 1
DHCP4.OPTION[31]: ntp_servers = 80.50.231.226 217.96.29.26 212.160.106.226

2. timesyncd is using hardcoded default NTP server:

$ systemctl -n 200 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 Sat 2017-04-22 13:12:23 CEST; 16min ago
     Docs: man:systemd-timesyncd.service(8)
 Main PID: 576 (systemd-timesyn)
   Status: "Synchronized to time server 91.189.89.199:123 (ntp.ubuntu.com)."
    Tasks: 2 (limit: 4915)
   Memory: 1.5M
      CPU: 20ms
   CGroup: /system.slice/systemd-timesyncd.service
           `-576 /lib/systemd/systemd-timesyncd

Apr 22 13:12:23 slodki systemd[1]: Starting Network Time Synchronization...
Apr 22 13:12:23 slodki systemd[1]: Started Network Time Synchronization.
Apr 22 13:12:53 slodki systemd-timesyncd[576]: Synchronized to time server 91.189.89.199:123 (ntp.ubuntu.com).

3. There are not other time sync deamons installed:

$ cat /lib/systemd/system/systemd-timesyncd.service.d/disable-with-time-daemon.conf
[Unit]
# don't run timesyncd if we have another NTP daemon installed
ConditionFileIsExecutable=!/usr/sbin/ntpd
ConditionFileIsExecutable=!/usr/sbin/openntpd
ConditionFileIsExecutable=!/usr/sbin/chronyd
ConditionFileIsExecutable=!/usr/sbin/VBoxService

$ ls -l /usr/sbin/{ntpd,openntpd,chronyd,VBoxService}
ls: cannot access '/usr/sbin/ntpd': No such file or directory
ls: cannot access '/usr/sbin/openntpd': No such file or directory
ls: cannot access '/usr/sbin/chronyd': No such file or directory
ls: cannot access '/usr/sbin/VBoxService': No such file or directory

4. There is only one default timesyncd.conf file with default values:

$ sudo find / -iname \*timesync\*
/etc/systemd/timesyncd.conf
/etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service
/etc/dhcp/dhclient-exit-hooks.d/timesyncd
/usr/share/man/man5/timesyncd.conf.d.5.gz
/usr/share/man/man5/timesyncd.conf.5.gz
/usr/share/man/man8/systemd-timesyncd.8.gz
/usr/share/man/man8/systemd-timesyncd.service.8.gz
/tmp/systemd-private-d029f63116924e99b9fc44caf622e299-systemd-timesyncd.service-6NwdRT
/lib/systemd/systemd-timesyncd
/lib/systemd/system/systemd-timesyncd.service
/lib/systemd/system/systemd-timesyncd.service.d
/var/tmp/systemd-private-d029f63116924e99b9fc44caf622e299-systemd-timesyncd.service-jz0q47

$ cat /etc/systemd/timesyncd.conf
# 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

5. DHCP hook installed as /etc/dhcp/dhclient-exit-hooks.d/timesyncd is not working, TIMESYNCD_CONF=/run/systemd/timesyncd.conf.d/01-dhclient.conf is not created.

6. After manually executing steps from hook all works as expected:

$ sudo mkdir -p /run/systemd/timesyncd.conf.d/
$ sudo cat <<EOF >/run/systemd/timesyncd.conf.d/01-dhclient.conf
> [Time]
> NTP=80.50.231.226 217.96.29.26 212.160.106.226
> EOF
$ sudo systemctl try-restart systemd-timesyncd.service
$ sudo 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 Sat 2017-04-22 13:47:28 CEST; 2min 6s ago
     Docs: man:systemd-timesyncd.service(8)
 Main PID: 3094 (systemd-timesyn)
   Status: "Synchronized to time server 80.50.231.226:123 (80.50.231.226)."
    Tasks: 2 (limit: 4915)
   Memory: 764.0K
      CPU: 19ms
   CGroup: /system.slice/systemd-timesyncd.service
           `-3094 /lib/systemd/systemd-timesyncd

Apr 22 13:47:27 slodki systemd[1]: Starting Network Time Synchronization...
Apr 22 13:47:28 slodki systemd[1]: Started Network Time Synchronization.
Apr 22 13:47:28 slodki systemd-timesyncd[3094]: Synchronized to time server 80.50.231.226:123 (80.50.231.226).

So hook is not triggered and NTP servers configuration not passed from DHCP/NM to timesyncd.
Kubuntu zesty amd64, systemd 232-21ubuntu3, network-manager 1.4.4-1ubuntu3

slodki (slodki)
description: updated
Changed in systemd (Ubuntu):
assignee: nobody → Balint Reczey (rbalint)
tags: added: rls-aa-incoming
Balint Reczey (rbalint)
Changed in systemd (Ubuntu):
status: New → In Progress
Revision history for this message
Balint Reczey (rbalint) wrote :

I tried reproducing the issue, but without NM it worked.
Seems to be LP: #293139, but I dig further and test in a VM with NM.

Balint Reczey (rbalint)
summary: - DHCP exit hook for setting NTP servers doesn't work
+ DHCP exit hook for setting systemd-timesyncd NTP servers doesn't work
Revision history for this message
Balint Reczey (rbalint) wrote :

Submitted patch in the bug for Debian, waiting for comments.

Changed in systemd (Ubuntu):
status: In Progress → Confirmed
Changed in systemd (Debian):
status: Unknown → New
Revision history for this message
slodki (slodki) wrote :

I think new NM dispatcher script for timesyncd should be executed not only on up/down actions, but on dhcp4/dhcp6 change to (and connectivity change to maybe - see https://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/src/nm-dispatcher.h#n27). It should be possible to update NTP servers on each DHCP options change.

Changed in systemd (Debian):
status: New → Fix Released
Changed in systemd (Debian):
status: Fix Released → New
Steve Langasek (vorlon)
Changed in systemd (Ubuntu):
importance: Undecided → Medium
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

in Artful we are migrating away from ifupdown to netplan. Meaning we will not be using dhcp hooks by default, and only use networkd/network-manager. I believe networkd has native support to push NTP servers to timesyncd, and I think networkmanager should natively push ntp servers direct to timesync too - without using the dhcp hooks. Adding a task for networkmanager to check this.

Native support in networkmanager would be nice; dhcp hook is thus in itself is low priority.

Changed in network-manager (Ubuntu):
status: New → Confirmed
assignee: nobody → Dimitri John Ledkov (xnox)
milestone: none → ubuntu-17.09
Balint Reczey (rbalint)
Changed in systemd (Ubuntu):
assignee: Balint Reczey (rbalint) → nobody
importance: Medium → Low
tags: removed: rls-aa-incoming
Changed in systemd (Debian):
status: New → Fix Released
Revision history for this message
Dan Streetman (ddstreet) wrote :

please reopen if this is still an issue

Changed in systemd (Ubuntu):
status: Confirmed → Won't Fix
Revision history for this message
Martin (ub71-martin) wrote :

Hello,

On Ubuntu desktop 22.04 LTS, it seems that the hook is not executed. I'm not sure how to verify that but sure thing is the DHCP is well announcing the ntp server.

DHCP4.OPTION[8]: ntp_servers = X.X.X.X
DHCP4.OPTION[18]: requested_ntp_servers = 1

Could someone help ?

Revision history for this message
Alfred (alf-redyoung) wrote (last edit ):

To ubuntu 22.04, I refer to https://roll.urown.net/desktop/network/time-sync.html.
Using NM's dispatch scripts, NetworkManager can talk with timesyncd when configuring to use internal dhcp client.

If want to use dhclient's hook, I think you should configure NetworkManager to use dhclient.
[main]
dhcp=dhclient

I don't test it, just for your reference.

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.