Instructing dhclient to set hostname of client

Doug Barton dougb at FreeBSD.org
Mon Oct 23 05:30:55 UTC 2006


Joe Holden wrote:
> Hi all,
> 
> Is it possible to get dhclient to resolve the ip its been given, and set
> that as the hostname? (6.2-PRE)

For future reference, this really belongs on freebsd-questions. If you 
know for sure that the DHCP server is going to send you a hostname, 
then you can put this in your /etc/dhclient.conf:

request subnet-mask, routers, broadcast-address,
         domain-name, host-name,
         domain-name-servers;

(obviously those aren't all related to your hostname, but probably a 
good idea anyway).

If you're talking about a laptop where you're not sure what the DHCP 
server is going to send you, then I have this in /etc/rc.local:

for ip in `ifconfig | awk '/inet / {print $2}'`; do
         case "${ip}" in
         127.0.0.1|0.0.0.0) ;;
         *)      newhost=`host ${ip} | cut -f5 -d ' '`
                 case "${newhost}" in
                 ''|*NXDOMAIN*) ;;
                 *\.*)   hostname ${newhost%.}
                         sleep 1
                         break
                         ;;
                 esac
		;;
	esac
done

Combine that with a default hostname in /etc/rc.conf[.local] and 
you're good to go.

hth,

Doug

-- 

     This .signature sanitized for your protection


More information about the freebsd-net mailing list