Allow setting NTP servers in manual configuration
Description of the feature
I think it'd make sense to be able to configure NTP servers like DNS servers through connection properties e.g. something like (made up, works up to ipv4.ntp) nmcli c mod 'Wired connection 1' ipv4.method manual ipv4.addresses 10.0.0.2/24 ipv4.gateway 10.0.0.1 ipv4.dns 10.0.0.1 ipv4.ntp 10.0.0.1
Ideally NetworkManager would then handle NTP servers through a mechanism better defined than the current dispatched script and then configure servers obtained through DHCP the same way, but just piggy-backing on the DHCP env vars in the manual case would be good enough.
Description of the use cases
NetworkManager currently indirectly allows configuring NTP servers in DHCP configuration through the DHCP4_NTP_SERVERS and DHCP6_NTP_SERVERS environment variables in dispatched scripts.
It'd be consistent to also allow setting servers manually through nmcli like we can associate DNS servers to a specific interface: it's quite likely that NTP servers announced through DHCP are local to that interface and not reachable from outside, so we should have a mechanism to add or remove servers based on which connections are up in static configuration as well.
References and other resources
- part of nmcli c show output with dhcp including ntp:
...
DHCP4.OPTION[5]: domain_name_servers = x.y.z.t x2.y2.z2.t2
...
DHCP4.OPTION[18]: requested_ntp_servers = 1
...
- dispatcher script I'm using for chrony that works with DHCP (note servers are never removed, default servers also are left present even if some are configured - I tried adding a similar loop with
chronyc delete $ntp
in the down block but varaibles don't seem to be set... I'm not sure what's best here to be honest but that's also beside this issue unless you want to discuss a proper configuration mechanism):
# cat /etc/NetworkManager/dispatcher.d/chrony
#!/bin/sh
case "$2" in
up|vpn-up)
for ntp in $DHCP4_NTP_SERVERS $DHCP6_NTP_SERVERS; do
chronyc add server "$ntp" iburst >/dev/null
done
chronyc onoffline >/dev/null
;;
down|vpn-down)
chronyc onoffline >/dev/null
;;
esac
Thanks!