Re: dhcp v4 set hostname clobbered by slaac
Mark Davies
Tue Apr 21 22:41:17 2020
On 20/04/20 10:35 pm, Roy Marples wrote:
> 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
Sorry for the delay replying - perils of trying to test something
remotely in a lockdown. I made the change on a remote machine and
rebooted it and for some reason it didn't come back and I won't be able
to get in and see why for at least a week. So rather than potentially
taking another remote machine out I had to reproduce the setup locally.
Having done that I can confirm that your patch works. And yes I have
force_hostname set to true, because if I don't do that the hostname ends
up being "archlinux" always.
cheers
mark
Archive administrator: postmaster@marples.name