NTP servers from DHCP are not propagated to timesyncd

Bug #1933828 reported by Jean-Baptiste Lallement
28
This bug affects 5 people
Affects Status Importance Assigned to Milestone
OEM Priority Project
New
Critical
Cyrus Lien
network-manager (Ubuntu)
Confirmed
High
Heather Ellsworth
Focal
Confirmed
High
Heather Ellsworth

Bug Description

Network manager gets NTP servers from DHCP but do not update timesyncd to use it which keeps using ntp.ubuntu.com.

This is a problem on private networks which do not have access to public internet. On this type of network the configuration of timesyncd must be updated manually instead of inheriting the conf from the dhcp servers.

This can be integrated with a NM dispatcher script such as below:

etc/NetworkManager/dispatcher.d/10-update-timesyncd for example:

==8<=====8<=====8<=====8<=====8<==
#! /usr/bin/bash

[ -n "$CONNECTION_UUID" ] || exit

INTERFACE=$1
ACTION=$2

case $ACTION in
    up | dhcp4-change | dhcp6-change)
        [ -n "$DHCP4_NTP_SERVERS" ] || exit
        mkdir -p /etc/systemd/timesyncd.conf.d/
        cat<<EOF > /etc/systemd/timesyncd.conf.d/$CONNECTION_UUID.conf
[Time]
NTP=$DHCP4_NTP_SERVERS
RootDistanceMaxSec=15
EOF
        systemctl restart systemd-timesyncd
       ;;
    down)
        rm -f /etc/systemd/timesyncd.conf.d/$CONNECTION_UUID.conf
        systemctl restart systemd-timesyncd
        ;;
esac
==8<=====8<=====8<=====8<=====8<==

ProblemType: Bug
DistroRelease: Ubuntu 21.10
Package: network-manager 1.30.0-1ubuntu3
ProcVersionSignature: Ubuntu 5.11.0-18.19+21.10.1-generic 5.11.17
Uname: Linux 5.11.0-18-generic x86_64
NonfreeKernelModules: zfs zunicode zavl icp zcommon znvpair
ApportVersion: 2.20.11-0ubuntu67
Architecture: amd64
CasperMD5CheckResult: unknown
CurrentDesktop: ubuntu:GNOME
Date: Mon Jun 28 14:08:52 2021
InstallationDate: Installed on 2020-05-31 (393 days ago)
InstallationMedia: Ubuntu 20.10 "Groovy Gorilla" - Alpha amd64 (20200527)
RebootRequiredPkgs:
 linux-image-5.11.0-20-generic
 linux-base
SourcePackage: network-manager
UpgradeStatus: No upgrade log present (probably fresh install)
nmcli-nm:
 RUNNING VERSION STATE STARTUP CONNECTIVITY NETWORKING WIFI-HW WIFI WWAN-HW WWAN
 running 1.30.0 connected started full enabled enabled disabled enabled enabled

Revision history for this message
Jean-Baptiste Lallement (jibel) wrote :
Changed in network-manager (Ubuntu):
importance: Undecided → High
Revision history for this message
Jean-Baptiste Lallement (jibel) wrote :

Updates version of the script.

summary: - NTP servers from DCHP are not propagated to timesyncd
+ NTP servers from DHCP are not propagated to timesyncd
Changed in network-manager (Ubuntu):
assignee: nobody → Heather Ellsworth (hellsworth)
tags: added: rls-ii-incoming
Changed in network-manager (Ubuntu Focal):
importance: Undecided → High
assignee: nobody → Heather Ellsworth (hellsworth)
Cyrus Lien (cyruslien)
tags: added: oem-priority originate-from-1933586 wenshan
Jamie Chang (jamie315)
Changed in oem-priority:
importance: Undecided → Critical
Cyrus Lien (cyruslien)
Changed in oem-priority:
assignee: nobody → Cyrus Lien (cyruslien)
Revision history for this message
Heather Ellsworth (hellsworth) wrote :

I tried to reproduce this, to test the fix, but I am stuck trying to figure out how to manually set the ntp server. I can't see any difference between when the vm (with no network) has this /etc/NetworkManager/dispatcher.d/10-update-timesyncd file in place or not. I think that's good but maybe not so relevant without “seeing” the problem. I've been looking at the commands:
   ◇ systemctl status systemd-timesyncd
   ◇ timedatectl show
   ◇ timedatectl status
I believe timedatectl is the way a user would interact with timesyncd and there's a timedatectl command to set the time zone or even time, but nothing to set the server. So how the heck do you change the NTP server to something other than ntp.ubuntu.com?

Revision history for this message
Jean-Baptiste Lallement (jibel) wrote :

The server is set via a configuration file. The default config file is /etc/systemd/timesyncd.conf and it can be overridden by dropping files in /etc/systemd/timesyncd.conf.d/.
There is a pool of free ntp servers available on https://www.ntppool.org/en/.

To test this fix you also need a DHCP server that returns NTP records.

With VMs, you can use dnsmasq to provide NTP records by changing the values in dnsmasq.conf
# Set the NTP time server addresses to 192.168.0.4 and 10.10.0.5
#dhcp-option=option:ntp-server,192.168.0.4,10.10.0.5

Or if you're using libvirt, edit the configuration with "virsh net-edit default" (or the name of the network your VMs are attached to) then pass the option directly to dnsmasq (cf https://libvirt.org/formatnetwork.html for reference)

Revision history for this message
Sebastien Bacher (seb128) wrote :

The bug is assigned and targetted to focal, it's import for the LTS but we don't believe it should be a release issue for impish

tags: added: rls-ii-notfixing
removed: rls-ii-incoming
Revision history for this message
Jean-Baptiste Lallement (jibel) wrote :

@Seb this fix has to go to focal for a customer project and must land in the dev release first.

Revision history for this message
Heather Ellsworth (hellsworth) wrote :

I've got this setup between two vms, where the server vm is hosting dnsmasq with ntp and the client synchronizes from the server (on a private network). This issue of the timesync conf needing to be updated exists in systemd-timesyncd too. But tackling the NetworkManager case as this is the customer issue.. we could put this fix in either networkd-dispatcher or network-manager. I've got a local build of network-manager that drops the file in place.. but needs to be tweaked.

Should the 10-update-timesyncd file be put in place by networkd-dispatcher or network-manager?

Revision history for this message
Jean-Baptiste Lallement (jibel) wrote :

IMHO having the fix in network-dispatcher makes more sense.

Revision history for this message
Jean-Baptiste Lallement (jibel) wrote :

There is also an additional requirement. The package must install successfully and replace an existing file that would have been created manually (we had to ship the file on the image for the customer since we don't have this fix in a package yet)

Revision history for this message
Heather Ellsworth (hellsworth) wrote :

Here is a networkd-dispatcher fix:
https://launchpad.net/~hellsworth/+archive/ubuntu/networkd-dispatcher/+build/22316215

And here is a network-manager fix:
https://launchpad.net/~hellsworth/+archive/ubuntu/network-manager/+build/22316944

Both should work, so please test the networkd-dispatcher fix first and network-manager if needbe.

Revision history for this message
Sebastien Bacher (seb128) wrote :

was the issue reported and discussed upstream yet? those scripts added to the package sound like downstream workaround we will have to carry and should be a backup plan if the issue can't be properly fixed upstream. And even if a distro hack makes sense it would be better to have it in Debian to reduce or maintainance

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in network-manager (Ubuntu Focal):
status: New → Confirmed
Changed in network-manager (Ubuntu):
status: New → Confirmed
Revision history for this message
Bogus (bogus22) wrote :

Hi,
Here I found a better version of this script. It implements DHCPv6 and handles directory and file creation better f.ex when IF goes down.

https://roll.urown.net/desktop/network/time-sync.html

Unfortunately the variable $DHCP6_NTP_SERVERS is always empty in my case. Even I have correct NTP and SNTP server addresses in my DHCPv6 options. I checked them with Wireshark.

Revision history for this message
Jonathan (xeosjonathan) wrote :

This issue is also present on Bionic. Is there a chance that the network manager would be fixed in Bionic, as part of Ubuntu Pro?

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.