Subject: Re: dhclient - obtain hostname
To: MLH <MLH@goathill.org>
From: Manuel Bouyer <bouyer@antioche.eu.org>
List: netbsd-help
Date: 10/16/2002 23:47:41
On Wed, Oct 16, 2002 at 09:29:37PM +0000, MLH wrote:
> I am trying to obtain a hostname from a dhcp server. The domain's
> DNS has a hostname associated with the ip it provides and I need
> to use that.
> 
> $ /usr/bin/host <ip>   works correctly
> 
> $ cat dhclient.conf
> interface "fxp0" {
>            send dhcp-client-identifier xx:xx:xx:xx:xx:xx;
>            request subnet-mask, broadcast-address, routers,
>                 domain-name, domain-name-servers, host-name;
>            require host-name, subnet-mask, domain-name-servers;
>        }
> 
> new_host_name is always null, despite the 'require host-name'
> 
> -- 1) What am I doing wrong here? Everything else is working.

Are you sure your dhcp server sends a host name ? Maybe
use tcpdump to make sure.

> 
> I added dhclient-exit-hooks (also tried dhclient-enter-hooks) :
> 
> $ cat dhclient-exit-hooks
> #!/bin/sh
> set_hostname(){
>   if [ -z "$new_host_name" -a ! -z "$new_ip_address" ]; then
>     new_host_name=`/usr/bin/host $new_ip_address | cut -f5 -d" "`
>     hostname $new_host_name
>     #echo using $new_ip_address as $new_host_name
>     #echo $new_host_name >| /etc/myname
>   fi
> }
> case "$reason" in
> BOUND|REBOOT|RENEW|REBIND)
>   set_hostname
>   ;;
> esac
> 
> Using this, /etc/rc.d/dhclient restart  works great, however,
> /usr/bin/host <ip> *usually* returns a null string on bootup.

Probably because resolv.conf or networking is not up at this point.

-- 
Manuel Bouyer <bouyer@antioche.eu.org>
--