Re: dhcp v4 set hostname clobbered by slaac
Roy Marples
Mon Apr 20 11:35:26 2020
Hi Mark
On 20/04/2020 02:33, Mark Davies wrote:
Hi,
I've been meaning to report this for a while:
ArchLinux running dhcpcd-8.1.2 (but also happened in older versions and
looks like may still happen in 9.0.1).
Machines getting config, including hostname, via ipv4 dhcp (so running
the 30-hostname hook) and getting ipv6 addressing via slaac.
The hostname is successfully set on receipt of the dhcp packets, but
then is reset to "localhost" each time a routeradvertisment packet is
received.
The following patch to hooks/30-hostname fixes the issue for me.
--- dhcpcd-hooks/30-hostname 2019-11-15 05:34:16.000000000 +1300
+++ dhcpcd-hooks/30-hostname 2019-12-11 10:40:47.935238981 +1300
@@ -156,6 +156,6 @@
;;
esac
-if $if_up; then
+if $if_up && [ "$reason" != ROUTERADVERT ]; then
set_hostname
fi
I don't understand how this can happen.
Look here:
https://roy.marples.name/cgit/dhcpcd.git/tree/hooks/30-hostname.in#n63
need_hostname decides if we want to set a hostname or not, using these rules:
1) Is the hostname a default hostname? If so, return 0
2) Is user variable force_hostname YES or TRUE? If so, return 0
3) Does the current hostname match the old hostname from the DHCP lease? If so,
return 0
4) Return non zero.
Assuming you start with a valid hostname then the only way the 30-hostname
script can clobber the hostname is if force_hostname is true.
If this is correct, does this patch work instead?
diff --git a/hooks/30-hostname.in b/hooks/30-hostname.in
index 579c73d3..6dc1b4f5 100644
--- a/hooks/30-hostname.in
+++ b/hooks/30-hostname.in
@@ -67,7 +67,9 @@ need_hostname()
is_default_hostname "$hostname" && return 0
case "$force_hostname" in
- [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) return 0;;
+ [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1)
+ [ -n "$new_fqdn" ] || [ -n "$new_host_name" ]
+ return $?;;
esac
if [ -n "$old_fqdn" ]; then
If this does not work, could you put set -x before if $if_up; then
and set +x after the if block and post back the output.
Thanks
Roy
Archive administrator: postmaster@marples.name