dhcpcd-discuss

Re: Question about NTP via DHCP - RFC 2132

Roy Marples

Tue Jan 21 22:49:18 2020

	Hi

On 21/01/2020 09:23, Stefano Cappa wrote:
Hi Roy,
I'm not an expert about this topic and I have a question about NTP via DHCP as described in RFC 2132. Basically, my device with dhcpcd 8.1.x (or later when released) must use a NTP server via DHCP if provided, otherwise it must use an external server as a fallback. This behaviour is an external requirement and I have to check if it's currently working in this way, but I really don't know how.

How can I check if this behaviour is right? How can I specify a working NTP server via dhcpcd and check if it will have higher priority than external servers.

I'm sorry for the bad explanation, but I don't have other information, because for me this topic is totally new.

OK

All dhcpcd does is take a DHCP message, parse it's options and pass that to the hooks. dhcpcd supplies a NTP hook which adds any NTP server given to the system ntp.conf file. If a following message no longer supplies this then it is removed.

NTP decides the *best* server itself by measuring data from NTP servers in the config.

You might be able to achieve what you want by supplying no NTP servers in the default ntp.conf and in /etc/dhcpcd.enter-hook set the variable new_ntp_servers if it's not already set - something like this

# Default NTP servers if non supplied
# This ensures that if DHCP supplies some, only they are used
if [ -z "$new_ntp_servers" ]; then
	new_ntp_servers="192.168.0.1 10.0.0.1"
fi

But this means the servers can't be used as a fallback if the ones given by NTP don't work. If that's critical then you have to convince NTP in ntp.conf, which is outside the scope of dhcpcd.

Good luck!

Roy

Follow-Ups:
Re: Question about NTP via DHCP - RFC 2132Neal P. Murphy
References:
Question about NTP via DHCP - RFC 2132Stefano Cappa
Archive administrator: postmaster@marples.name