NTP config for dhcpcd
While exploring how to configure multiple WiFi access points, routing IP subnets, WAP bridging and the consequences, I noticed that when I switched my laptop from one WiFi access point to another, the NTP configuration stayed the same.
I finally figured out how to get dhcpcd to set the NTP server for a given WiFi access point.
I run Arch linux on my laptop. You should too, by the way, but that’s for another day.
NTP Hook
The Arch dhcpcd
package does not include an NTP “hook” file.
A hook file is a shell script that dhcpcd
runs when it receives
a specific DHCP option.
I believe the Arch dhcpcd
package currently installs DNS resolver configs,
hostname, and timesyncd
hook files in /usr/lib/dhcpcd/dhcpcd-hooks/
The Arch dhcpcd
package includes a few other hook files in
/usr/share/dhcpcd/hooks/
,
but none of them relate to setting an NTP server if the DHCP server offers it.
You have to get a file named 50-ntp.conf
directly from the dhcpcd
source repository
Copy the file 50-ntp.conf
to /usr/lib/dhcpcd/dhcpcd-hooks/
.
You’ll have to use sudo
or switch user to root
to do this.
50-ntp.conf
is a shell script but it can have read-only permissions.
I left it at 0444 permissions.
dhcpcd configuration
You have to tell dhcpcd
to run the NTP hook.
Add a line to file /etc/dhcpcd.conf
:
# Most distributions have NTP support.
option ntp_servers
I believe I deleted the #
comment leader character on a pre-existing line
like that.
You have to restart dhcpcd
process to get that change to take effect.
systemctl restart dhcpcd.service
Root Cause
I needed long time to figure this out,
including trying to understand the enterprise-style script
50-ntp.conf
.
I believe my trouble was not reading the dhcpcd
documentation on
hooks closely enough to recognize that not only does a hook file
have to be in place, but the dhcpcd
process has to be configured
to run the hook file.
That’s the option ntp_servers
line in /etc/dhcpcd.conf
.