Subject: dhclient - obtain hostname
To: None <netbsd-help@NetBSD.ORG>
From: MLH <MLH@goathill.org>
List: netbsd-help
Date: 10/16/2002 21:29:37
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.

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.

$new_ip_address is so far *always* non-null and valid.

-- 2) How can I get /usr/bin/host to work under bootup?

This is a generic 1.6 build with lm and apm turned on.

Thanks