NetBSD Problem Report #55011

From tsutsui@ceres.dti.ne.jp  Mon Feb 24 08:19:22 2020
Return-Path: <tsutsui@ceres.dti.ne.jp>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 602011A9213
	for <gnats-bugs@gnats.NetBSD.org>; Mon, 24 Feb 2020 08:19:22 +0000 (UTC)
Message-Id: <202002240819.01O8JC8c004411@ceres.dti.ne.jp>
Date: Mon, 24 Feb 2020 17:19:12 +0900 (JST)
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
Reply-To: tsutsui@ceres.dti.ne.jp
To: gnats-bugs@NetBSD.org
Cc: tsutsui@ceres.dti.ne.jp
Subject: dhcpcd(8) sets "localhost" as hostname
X-Send-Pr-Version: 3.95

>Number:         55011
>Category:       bin
>Synopsis:       dhcpcd(8) sets "localhost" as hostname
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Feb 24 08:20:00 +0000 2020
>Last-Modified:  Tue Apr 21 11:10:01 +0000 2020
>Originator:     Izumi Tsutsui
>Release:        NetBSD 9.0
>Organization:
>Environment:
System: NetBSD 9.0 (GENERIC) #0: Fri Feb 14 00:06:28 UTC 2020 mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/cobalt/compile/GENERIC
Architecture: mipsel
Machine: cobalt (but maybe affects all)
>Description:
With the default installation settings
(no /etc/dhcpcd.conf and default /libexec/dhcpcd-hooks scripts),
dhcpcd(8) uses "loalhost" for hostname, while man page says
as the following:
---
     If the hostname is currently blank, (null) or
     localhost, or force_hostname is YES or TRUE or 1 then dhcpcd sets the
     hostname to the one supplied by the DHCP server.
---

---
# ifconfig tlp0
tlp0: flags=0x8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        ec_capabilities=1<VLAN_MTU>
        ec_enabled=0
        address: 00:10:e0:00:09:46
        media: Ethernet 10baseT
        status: active
        inet6 fe80::210:e0ff:fe00:946%tlp0/64 flags 0x0 scopeid 0x1
# hostname

# dhcpcd 
DUID 00:01:00:01:25:e6:a0:56:00:10:e0:00:09:46
tlp0: IAID e0:00:09:46
tlp0: soliciting an IPv6 router
tlp0: rebinding lease of 10.0.0.150
tlp0: leased 10.0.0.150 for 600 seconds
tlp0: adding route to 10.0.0.0/8
tlp0: adding default route via 10.0.0.254
tlp0: Setting hostname: localhost
forked to background, child pid 681
# hostname
localhost
# 
---

>How-To-Repeat:
See above

>Fix:
No idea.
Tweak /libexec/dhcp-hooks/30-hostname ?

---
Izumi Tsutsui

>Audit-Trail:
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
To: gnats-bugs@netbsd.org
Cc: tsutsui@ceres.dti.ne.jp
Subject: Re: bin/55011: dhcpcd(8) sets "localhost" as hostname
Date: Mon, 24 Feb 2020 20:02:49 +0900

 > >Synopsis:       dhcpcd(8) sets "localhost" as hostname
  :
 > Tweak /libexec/dhcp-hooks/30-hostname ?

 Replacing all /libexec/dhcpcd-hooks scripts with NetBSD 6.1.5 ones
 makes dhcpcd(8) use hostname provided by DHCP server:

 ---
 Mon Feb 24 18:48:48 UTC 2020
 Feb 24 18:48:51  getty[527]: /dev/tty00: Device not configured

 NetBSD/cobalt (Amnesiac) (ttyZ0)

 login: root
 Feb 24 18:48:53  login: ROOT LOGIN (root) on tty ttyZ0
 Last login: Mon Feb 24 18:40:37 2020 on ttyZ0
 Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
     2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
     2018, 2019, 2020 The NetBSD Foundation, Inc.  All rights reserved.
 Copyright (c) 1982, 1986, 1989, 1991, 1993
     The Regents of the University of California.  All rights reserved.

 NetBSD 9.0 (GENERIC) #0: Mon Feb 24 03:01:07 JST 2020

 Welcome to NetBSD!

 We recommend that you create a non-root account and use su(1) for root access.
 # rm -f /var/db/dhcpcd/*
 # ifconfig tlp0 up
 # dhcpcd -d
 dhcpcd-8.1.6 starting
 tlp0: executing `/libexec/dhcpcd-run-hooks' PREINIT
 tlp0: executing `/libexec/dhcpcd-run-hooks' CARRIER
 DUID 00:01:00:01:25:e6:d7:2b:00:10:e0:00:09:46
 tlp0: IAID e0:00:09:46
 tlp0: delaying IPv6 router solicitation for 0.0 seconds
 tlp0: delaying IPv4 for 0.5 seconds
 tlp0: soliciting an IPv6 router
 tlp0: sending Router Solicitation
 tlp0: soliciting a DHCP lease
 tlp0: sending DISCOVER (xid 0xa6d2fd80), next in 3.9 seconds
 tlp0: offered 10.0.0.155 from 10.0.0.254 `10.0.0.254'
 tlp0: sending REQUEST (xid 0xa6d2fd80), next in 3.6 seconds
 tlp0: acknowledged 10.0.0.155 from 10.0.0.254 `10.0.0.254'
 tlp0: adding IP address 10.0.0.155/8 broadcast 10.255.255.255
 tlp0: sending Router Solicitation
 tlp0: DAD completed for 10.0.0.155
 tlp0: leased 10.0.0.155 for 600 seconds
 tlp0: renew in 300 seconds, rebind in 525 seconds
 tlp0: writing lease `/var/db/dhcpcd/tlp0.lease'
 tlp0: IP address 10.0.0.155/8 already exists
 tlp0: adding route to 10.0.0.0/8
 tlp0: adding default route via 10.0.0.254
 tlp0: executing `/libexec/dhcpcd-run-hooks' BOUND
 forking to background
 forked to background, child pid 644
 # hostname
 q-155.netbsd.org
 # ls -l /libexec/dhcpcd-hooks
 total 18
 -rw-r--r--  1 root  wheel   202 Sep 29  2014 01-test
 -rw-r--r--  1 root  wheel   108 Sep 29  2014 02-dump
 -rw-r--r--  1 root  wheel   981 Sep 29  2014 10-mtu
 -rw-r--r--  1 root  wheel  3850 Sep 29  2014 20-resolv.conf
 -rw-r--r--  1 root  wheel   649 Sep 29  2014 29-lookup-hostname
 -rw-r--r--  1 root  wheel  1050 Sep 29  2014 30-hostname
 -rw-r--r--  1 root  wheel  2487 Sep 29  2014 50-ntp.conf
 # 
 ---

 On the other hand 7.2 ones set localhost:
 ---
 Mon Feb 24 18:56:47 UTC 2020
 Feb 24 18:56:50  getty[573]: /dev/tty00: Device not configured

 NetBSD/cobalt (Amnesiac) (ttyZ0)

 login: root
 Feb 24 18:57:42  login: ROOT LOGIN (root) on tty ttyZ0
 Last login: Mon Feb 24 18:48:53 2020 on ttyZ0
 Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
     2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
     2018, 2019, 2020 The NetBSD Foundation, Inc.  All rights reserved.
 Copyright (c) 1982, 1986, 1989, 1991, 1993
     The Regents of the University of California.  All rights reserved.

 NetBSD 9.0 (GENERIC) #0: Mon Feb 24 03:01:07 JST 2020

 Welcome to NetBSD!

 We recommend that you create a non-root account and use su(1) for root access.
 # rm -f /var/db/dhcpcd/*
 # ifconfig tlp0 up
 # dhcpcd -d
 dhcpcd-8.1.6 starting
 tlp0: executing `/libexec/dhcpcd-run-hooks' PREINIT
 tlp0: executing `/libexec/dhcpcd-run-hooks' CARRIER
 DUID 00:01:00:01:25:e6:d9:3b:00:10:e0:00:09:46
 tlp0: IAID e0:00:09:46
 tlp0: delaying IPv6 router solicitation for 0.7 seconds
 tlp0: delaying IPv4 for 0.8 seconds
 tlp0: soliciting an IPv6 router
 tlp0: sending Router Solicitation
 tlp0: soliciting a DHCP lease
 tlp0: sending DISCOVER (xid 0x55bbbf62), next in 3.0 seconds
 tlp0: offered 10.0.0.156 from 10.0.0.254 `10.0.0.254'
 tlp0: sending REQUEST (xid 0x55bbbf62), next in 3.8 seconds
 tlp0: acknowledged 10.0.0.156 from 10.0.0.254 `10.0.0.254'
 tlp0: adding IP address 10.0.0.156/8 broadcast 10.255.255.255
 tlp0: sending Router Solicitation
 tlp0: DAD completed for 10.0.0.156
 tlp0: leased 10.0.0.156 for 600 seconds
 tlp0: renew in 300 seconds, rebind in 525 seconds
 tlp0: writing lease `/var/db/dhcpcd/tlp0.lease'
 tlp0: IP address 10.0.0.156/8 already exists
 tlp0: adding route to 10.0.0.0/8
 tlp0: adding default route via 10.0.0.254
 tlp0: executing `/libexec/dhcpcd-run-hooks' BOUND
 tlp0: Setting hostname: localhost
 forking to background
 forked to background, child pid 663
 # hostname
 localhost
 # ls -l /libexec/dhcpcd-hooks
 total 18
 -rw-r--r--  1 root  wheel   300 Aug 29  2018 01-test
 -rw-r--r--  1 root  wheel   120 Aug 29  2018 02-dump
 -rw-r--r--  1 root  wheel  5471 Aug 29  2018 20-resolv.conf
 -rw-r--r--  1 root  wheel  3733 Aug 29  2018 30-hostname
 -rw-r--r--  1 root  wheel  3432 Aug 29  2018 50-ntp.conf
 # 
 ---

 ---
 Izumi Tsutsui

From: Roy Marples <roy@marples.name>
To: gnats-bugs@NetBSD.org, Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
Cc: 
Subject: re: bin/55011 dhcpcd(8) sets "localhost" as hostname
Date: Tue, 31 Mar 2020 16:46:04 +0100

 Is this report about the manpage being slightly inaccurate - if an invalid 
 hostname it will set a default hostname of localhost even if no hostname option 
 in the dhcp message and the current hostname is "invalid" (ie blank, (null) or 
 localhost)?

 OR is it about changing the default behaviour to not change hostname if blank or 
 (null) to localhost?

 Roy

From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
To: roy@marples.name
Cc: gnats-bugs@NetBSD.org, tsutsui@ceres.dti.ne.jp
Subject: Re: bin/55011 dhcpcd(8) sets "localhost" as hostname
Date: Wed, 1 Apr 2020 01:10:10 +0900

 > Is this report about the manpage being slightly inaccurate - if an invalid 
 > hostname it will set a default hostname of localhost even if no hostname option 
 > in the dhcp message and the current hostname is "invalid" (ie blank, (null) or 
 > localhost)?

 > OR is it about changing the default behaviour to not change hostname if blank or 
 > (null) to localhost?

 Well I don't know what is "accurate" behavior.

 There are two points:

 - As noted in the PR, replacing /libexec/dhcpcd-hooks/30-hostname
   with 29-lookup-hostname and 30-hostname from NetBSD 6.1.5 makes
   dhcpcd(8) use "expected" hostname even in sysinst.
   dhclient(8) in NetBSD 8.1 also uses an expected hostname.
   (I'm not sure if it's provided from dhcpd or not)

 - The default name of "localhost" is annoying for me because
   it's also used by sysinst as default settings in /etc/hosts.
   Blank is still better for me.

 Is there any intentional changes (lookup removal?) from 6.1.5 one?

 ---
 Izumi Tsutsui

From: Roy Marples <roy@marples.name>
To: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
Cc: gnats-bugs@NetBSD.org
Subject: Re: bin/55011 dhcpcd(8) sets "localhost" as hostname
Date: Tue, 31 Mar 2020 19:05:46 +0100

 On 31/03/2020 17:10, Izumi Tsutsui wrote:
 > 
 >> Is this report about the manpage being slightly inaccurate - if an invalid
 >> hostname it will set a default hostname of localhost even if no hostname option
 >> in the dhcp message and the current hostname is "invalid" (ie blank, (null) or
 >> localhost)?
 > 
 >> OR is it about changing the default behaviour to not change hostname if blank or
 >> (null) to localhost?
 > 
 > Well I don't know what is "accurate" behavior.
 > 
 > There are two points:
 > 
 > - As noted in the PR, replacing /libexec/dhcpcd-hooks/30-hostname
 >    with 29-lookup-hostname and 30-hostname from NetBSD 6.1.5 makes
 >    dhcpcd(8) use "expected" hostname even in sysinst.
 >    dhclient(8) in NetBSD 8.1 also uses an expected hostname.
 >    (I'm not sure if it's provided from dhcpd or not)

 The default behaviour since dhcpcd-6.10 has been to install the 
 29-lookup-hostname as an example script rather than include it as a default script.

 Without the default dhcpcd.conf, the hostname option will not be requested.

 So this is expected.

 > 
 > - The default name of "localhost" is annoying for me because
 >    it's also used by sysinst as default settings in /etc/hosts.
 >    Blank is still better for me.

 I've attached a patch below to address this.
 Let me know if it works for you!

 > Is there any intentional changes (lookup removal?) from 6.1.5 one?

 The 29-lookup-hostname hook was removed from the default installation due to a 
 lot of user complaints.
 It's also IPv4 specific, although that could be improved.
 I have no intention of restoring it as a default hook.

 If you want a DHCP client to set the hostname, use the default dhcpcd.conf and 
 ensure the hostname is set in the DHCP message.

 OR, set this in /etc/dhcpcd.enter-hook

 . /usr/share/examples/dhcpcd/hooks/29-lookup-hostname

 Roy

  From 645d14292178c4f6a6f7d359ff8eeb87998f7a35 Mon Sep 17 00:00:00 2001
 From: Roy Marples <roy@marples.name>
 Date: Tue, 31 Mar 2020 18:23:05 +0100
 Subject: hostname: Default to blank instead of localhost

 No kernel sets a default value of localhost.
 ---
   hooks/30-hostname | 53 +++++++++++++++++++++++++----------------------------
   1 file changed, 25 insertions(+), 28 deletions(-)

 diff --git a/hooks/30-hostname b/hooks/30-hostname
 index 53ae6b11..3ac73ea4 100644
 --- a/hooks/30-hostname
 +++ b/hooks/30-hostname
 @@ -17,16 +17,16 @@

   # If we used to set the hostname, but relinquish control of it, we should
   # reset to the default value.
 -: ${hostname_default=localhost}
 +: ${hostname_default=}

   # Some systems don't have hostname(1)
   _hostname()
   {
   	if [ -z "${1+x}" ]; then
 -		if type hostname >/dev/null 2>&1; then
 -			hostname
 -		elif [ -r /proc/sys/kernel/hostname ]; then
 +		if [ -r /proc/sys/kernel/hostname ]; then
   			read name </proc/sys/kernel/hostname && echo "$name"
 +		elif type hostname >/dev/null 2>/dev/null; then
 +			hostname
   		elif sysctl kern.hostname >/dev/null 2>&1; then
   			sysctl -n kern.hostname
   		elif sysctl kernel.hostname >/dev/null 2>&1; then
 @@ -37,48 +37,39 @@ _hostname()
   		return $?
   	fi

 -	# Always prefer hostname(1) if we have it
 -	if type hostname >/dev/null 2>&1; then
 -		hostname "$1"
 -	elif [ -w /proc/sys/kernel/hostname ]; then
 +	if [ -w /proc/sys/kernel/hostname ]; then
   		echo "$1" >/proc/sys/kernel/hostname
 +	elif [ -n "$1" ] && type hostname >/dev/null 2>&1; then
 +		hostname "$1"
   	elif sysctl kern.hostname >/dev/null 2>&1; then
 -		sysctl -w "kern.hostname=$1"
 +		sysctl -w "kern.hostname=$1" >/dev/null
   	elif sysctl kernel.hostname >/dev/null 2>&1; then
 -		sysctl -w "kernel.hostname=$1"
 +		sysctl -w "kernel.hostname=$1" >/dev/null
   	else
 -		# We know this will fail, but it will now fail
 -		# with an error to stdout
 +		# May fail to set a blank hostname
   		hostname "$1"
   	fi
   }

 -set_hostname_vars()
 +is_default_hostname()
   {
 -	hfqdn=false
 -	hshort=false
 -	case "$hostname_fqdn" in
 -	[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1)	hfqdn=true;;
 -	""|[Ss][Ee][Rr][Vv][Ee][Rr])		;;
 -	*)					hshort=true;;
 +	case "$1" in
 +	""|"(none)"|localhost|localhost.localdomain|"$hostname_default")
 +		return 0;;
   	esac
 +	return 1
   }

   need_hostname()
   {
   	# Always load the hostname variable for future use
   	hostname="$(_hostname)"
 -	case "$hostname" in
 -	""|"(none)"|localhost|localhost.localdomain|"$hostname_default")
 -		return 0;;
 -	esac
 +	is_default_hostname "$hostname" && return 0

   	case "$force_hostname" in
   	[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) return 0;;
   	esac

 -	set_hostname_vars
 -
   	if [ -n "$old_fqdn" ]; then
   		if ${hfqdn} || ! ${hshort}; then
   			[ "$hostname" = "$old_fqdn" ]
 @@ -119,9 +110,15 @@ try_hostname()

   set_hostname()
   {
 -	need_hostname || return
 +	hfqdn=false
 +	hshort=false
 +	case "$hostname_fqdn" in
 +	[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1)	hfqdn=true;;
 +	""|[Ss][Ee][Rr][Vv][Ee][Rr])		;;
 +	*)					hshort=true;;
 +	esac

 -	set_hostname_vars
 +	need_hostname || return

   	if [ -n "$new_fqdn" ]; then
   		if ${hfqdn} || ! ${hshort}; then
 @@ -143,7 +140,7 @@ set_hostname()
   		else
   			try_hostname "$new_host_name"
   		fi
 -	elif [ -n "${hostname_default+x}" ]; then
 +	elif ! is_default_hostname "$hostname"; then
   		try_hostname "$hostname_default"
   	fi
   }
 -- 
 cgit v1.2.3

From: Robert Elz <kre@munnari.OZ.AU>
To: Roy Marples <roy@marples.name>
Cc: gnats-bugs@netbsd.org
Subject: Re: bin/55011 dhcpcd(8) sets "localhost" as hostname
Date: Wed, 01 Apr 2020 01:57:45 +0700

     Date:        Tue, 31 Mar 2020 18:10:02 +0000 (UTC)
     From:        Roy Marples <roy@marples.name>
     Message-ID:  <20200331181002.161241A921E@mollari.NetBSD.org>

   |  If you want a DHCP client to set the hostname, use the default
   |  dhcpcd.conf and ensure the hostname is set in the DHCP message.
   |  
   |  OR, set this in /etc/dhcpcd.enter-hook

 Roy, I think you're missing much of the point.   What is being requested
 is that for a host running sysinst (ie: 100% unconfigured, using a stock
 distribution UCB stick/CD/network-install (whatever)) should be able, if
 the DHCP server is so configured, to discover its hostname from the DHCP
 server, and set it.

 I used to use that kind of thing a lot at Melbourne U for systems in
 student labs (where it was never really sure what some previous student
 might have managed to do to the system).

 There were a set of (identical) boot CDs (it was before the days of USB,
 and while net booting would have worked for sun class systems, that was
 rare for PCs of the time) and anyone, anytime, could stick an install CD
 in the system's drive, and boot from it - a few minutes later they had
 a freshly installed NetBSD complete with hostname (unique for the host)
 and everything else needed to work the system (these weren't TNF type
 boot CDs but local ones we made, and included relevant packages, etc
 to provide everything that was deemed necessary for students of the time).
 (User files, and lots more, all came from NFS of course, the systems were,
 to an extent, not a lot more than slightly fancy X-terminals).

 It seems to me there are 3 ways that people want to treat the hostname
 wrt DHCP, and we ought to be making it trivially easy to select any one
 of those three.

 1. Use the hostname I configure on my host, always (tell the DHCP server
 what it is in case it wants to use it for reverse DNS (PTR) record updates).
 Never request, and ignore if sent, any hostname from the DHCP server.

 2. If I have a (sane) hostname set, use it, otherwise if the DHCP server
 can provide one, use that, otherwise fall back on an insane hostname
 (ie: localhost or similar).   Tell the DHCP server the hostname I have if
 I had one and am using that.

 3. Ignore any hostname configured locally, request a hostname from the DHCP
 server, and if it sends one, use that, always.   If it doesn't, then
 (probably) set localhost or something (just perhaps allow a pre-existing
 configured hostname to be used, but probably not).

 If the stock config isn't capable of trivially being configued into any
 of those three modes, it ought to be.   The default in CVS (so it gets
 used for distribution builds) should probably be mode 3.   Once installed
 users will easily be able to change it, but for install systems, other than
 asking the user to type a name (which would always be an option anyway)
 in sysinst, there is no other place from which the hostname can come.

 kre

From: Roy Marples <roy@marples.name>
To: gnats-bugs@NetBSD.org, Robert Elz <kre@munnari.OZ.AU>
Cc: 
Subject: Re: bin/55011 dhcpcd(8) sets "localhost" as hostname
Date: Mon, 13 Apr 2020 17:00:21 +0100

 Sorry for late reply, but this didn't hit my server for some unknown reason

 >  Roy, I think you're missing much of the point.   What is being requested
 >  is that for a host running sysinst (ie: 100% unconfigured, using a stock
 >  distribution UCB stick/CD/network-install (whatever)) should be able, if
 >  the DHCP server is so configured, to discover its hostname from the DHCP
 >  server, and set it.

 Robert, I think you missed the point of this bug.
 A 100% stock host does exactly this - the default dhcpcd.conf installed requests 
 the hostname from the DHCP server.

 This reported issue is that newer dhcpcd's no longer try to discover it by DNS 
 when there is no hostname supplied by the DHCP server. This is not being 
 reverted back to a default setting.

 The other reported issue is defaulting to localhost in the absence of a hostname 
 both in the DHCP message and the system - this has been now fixed.

 > 
 >  I used to use that kind of thing a lot at Melbourne U for systems in
 >  student labs (where it was never really sure what some previous student
 >  might have managed to do to the system).
 > 
 >  There were a set of (identical) boot CDs (it was before the days of USB,
 >  and while net booting would have worked for sun class systems, that was
 >  rare for PCs of the time) and anyone, anytime, could stick an install CD
 >  in the system's drive, and boot from it - a few minutes later they had
 >  a freshly installed NetBSD complete with hostname (unique for the host)
 >  and everything else needed to work the system (these weren't TNF type
 >  boot CDs but local ones we made, and included relevant packages, etc
 >  to provide everything that was deemed necessary for students of the time).
 >  (User files, and lots more, all came from NFS of course, the systems were,
 >  to an extent, not a lot more than slightly fancy X-terminals).
 > 
 >  It seems to me there are 3 ways that people want to treat the hostname
 >  wrt DHCP, and we ought to be making it trivially easy to select any one
 >  of those three.
 > 
 >  1. Use the hostname I configure on my host, always (tell the DHCP server
 >  what it is in case it wants to use it for reverse DNS (PTR) record updates).
 >  Never request, and ignore if sent, any hostname from the DHCP server.
 > 
 >  2. If I have a (sane) hostname set, use it, otherwise if the DHCP server
 >  can provide one, use that, otherwise fall back on an insane hostname
 >  (ie: localhost or similar).   Tell the DHCP server the hostname I have if
 >  I had one and am using that.
 > 
 >  3. Ignore any hostname configured locally, request a hostname from the DHCP
 >  server, and if it sends one, use that, always.   If it doesn't, then
 >  (probably) set localhost or something (just perhaps allow a pre-existing
 >  configured hostname to be used, but probably not).
 > 
 >  If the stock config isn't capable of trivially being configued into any
 >  of those three modes, it ought to be.   The default in CVS (so it gets
 >  used for distribution builds) should probably be mode 3.   Once installed
 >  users will easily be able to change it, but for install systems, other than
 >  asking the user to type a name (which would always be an option anyway)
 >  in sysinst, there is no other place from which the hostname can come.

 dhcpcd default is a mix of your options 1 and 2 and you can override that to 
 option 3 by setting this in dhcpcd.conf:
 static force_hostname=YES

 It's a mixture of 1 and 2 so that if you get a hostname from DHCP, the DHCP 
 server can then change it later as and when needed.

 Roy

From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: bin/55011 dhcpcd(8) sets "localhost" as hostname
Date: Tue, 14 Apr 2020 00:25:27 +0700

     Date:        Mon, 13 Apr 2020 16:05:02 +0000 (UTC)
     From:        Roy Marples <roy@marples.name>
     Message-ID:  <20200413160502.5F5ED1A924B@mollari.NetBSD.org>


   |  Robert, I think you missed the point of this bug.

   |  This reported issue is that newer dhcpcd's no longer try to discover
   | it by DNS when there is no hostname supplied by the DHCP server.

 You're right, if that's what the bug report was about, that isn't
 what I thought it was at all.

 kre

From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
To: roy@marples.name
Cc: gnats-bugs@NetBSD.org, tsutsui@ceres.dti.ne.jp
Subject: Re: bin/55011 dhcpcd(8) sets "localhost" as hostname
Date: Tue, 21 Apr 2020 20:05:11 +0900

 (sorry for a late response)
 > The default behaviour since dhcpcd-6.10 has been to install the 
 > 29-lookup-hostname as an example script rather than include it as a default script.
 > 
 > Without the default dhcpcd.conf, the hostname option will not be requested.
 > 
 > So this is expected.

 Ok, I see.

 > > - The default name of "localhost" is annoying for me because
 > >    it's also used by sysinst as default settings in /etc/hosts.
 > >    Blank is still better for me.
 > 
 > I've attached a patch below to address this.
 > Let me know if it works for you!

 I have not tested yet (sorry) but if it's changed to leave
 hostname empty, it's enough for me.

 > > Is there any intentional changes (lookup removal?) from 6.1.5 one?
 > 
 > The 29-lookup-hostname hook was removed from the default installation due to a 
 > lot of user complaints.
 > It's also IPv4 specific, although that could be improved.
 > I have no intention of restoring it as a default hook.
 > 
 > If you want a DHCP client to set the hostname, use the default dhcpcd.conf and 
 > ensure the hostname is set in the DHCP message.
 > 
 > OR, set this in /etc/dhcpcd.enter-hook
 > 
 > . /usr/share/examples/dhcpcd/hooks/29-lookup-hostname

 Now I've checked dhcpd.conf(5) manual and noticed "use-host-decl-names"
 entry:
 ---
            The use-host-decl-names statement

              use-host-decl-names flag;

              If the use-host-decl-names parameter is true in a given scope,
              then for every host declaration within that scope, the name
              provided for the host declaration will be supplied to the client
              as its hostname.  So, for example,

                  group {
                    use-host-decl-names on;

                    host joe {
                      hardware ethernet 08:00:2b:4c:29:32;
                      fixed-address joe.example.com;
                    }
                  }

              is equivalent to

                    host joe {
                      hardware ethernet 08:00:2b:4c:29:32;
                      fixed-address joe.example.com;
                      option host-name "joe";
                    }
 ---

 Then I've added "use-host-decl-names on;" to server's /etc/dhcpd.conf

 ---
 # Pass hostname to option host-name per each "host" declaration.
 use-host-decl-names on;

  [..]

 host roppa {
   hardware ethernet 00:c0:f6:xx:xx:xx;
   fixed-address roppa;
   server-name "mirage";
   option root-path "/r/export/NetBSD/x68k/root";
 }

 ---

 and now at least NetBSD/x68k 9.0 dhcpcd in sysinst can get
 an FQDN hostname as provided from the server.  Thanks.


 However, there are still two minor problems:

 (1) FQDN hostname

 As mentioned in hooks/30-hostname (or hooks/30-hostname.in in -current)
 it looks dhcpcd(8) sets FQDN hostname by default.
 (maybe using "domain-name" also provided by DHCP server?)

 ---
 # A value of server means just what the server says, don't manipulate it.
 # This could lead to an inconsistent hostname on a DHCPv4 and DHCPv6 network
 # where the DHCPv4 hostname is short and the DHCPv6 has an FQDN.
 # DHCPv6 has no hostname option.
 # RFC4702 section 3.1 says FQDN should be prefered over hostname.
 #
 # As such, the default is hostname_fqdn=true so that a consistent hostname
 # is always assigned.
 : ${hostname_fqdn:=true}
 ---

 However, it looks sysinst(8) in NetBSD 9.0 doesn't like FQDN hostname,
 so that it explicitly asks hostname again even after dhcpcd
 successfully gets an IP address and an FQDN hostname.

 Should sysinst(8) be fixed to handle FQDN name properly, or
 should we prepare customized "30-hostname" with "hostname_fqdn=false"
 for all installation media and specify it in
 src/distrib/common/list.dhcpcd?

 (2) description of dhcpd.conf(5) man page

 dhcpd.conf(5) from NetBSD 9.0 says the following in the
 "use-host-decl-names" section:
 ---
     It should be noted here that most DHCP clients completely ignore
     the host-name option sent by the DHCP server, and there is no way
     to configure them not to do this.  So you generally have a choice
     of either not having any hostname to client IP address mapping
     that the client will recognize, or doing DNS updates.  It is
     beyond the scope of this document to describe how to make this
     determination.
 ---

 I guess that's the reason why the dhclient(8) used a looked up hostname.

 Maybe we should patch (or send a request to change) this dhcpd.conf(5)
 description to reflect modern dhcpcd(8) behavior?

 Thanks,

 ---
 Izumi Tsutsui

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.