Re: Instructing dhclient to set hostname of client



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
_______________________________________________
freebsd-net@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "freebsd-net-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: hostname in title of gnome-terminal
    ... Is there a way to configure it so that the hostname will be the title ... be it's hostname (you can assume that I have the remote machine ... Keep Europe free from software patents, ...
    (GNOME)
  • Re: hostname in title of gnome-terminal
    ... Is there a way to configure it so that the hostname will be the title ... be it's hostname (you can assume that I have the remote machine ... Keep Europe free from software patents, ...
    (GNOME)
  • Re: hostname comes up as "unknown" with cheap-o cable modem router
    ... > DHCP server that is giving you a bogus hostname. ... Server 2003 DHCP Server presently. ... # Later, in inetsvc, we create a name "unknown" and create a entry ... Note that the name of this init script is vital -- you must put the ...
    (comp.unix.solaris)
  • Re: sun dhcp on multihomed machine
    ... > Dave Miner wrote: ... >> Using the fixed address as the primary interface is what we suggest ... If your DSL provider's DHCP server doesn't supply a hostname in the DHCP ...
    (comp.unix.solaris)
  • SUMMARY: Solaris 9 DHCP client hostname / DNS Update
    ... echo "Setting hostname to $HOSTNAME... ... The Solaris DHCP client will not directly send updates to a DNS server; ... DNS on its behalf. ... hostname from the DHCP server, and most DHCP servers won't provide it. ...
    (SunManagers)