Re: Setting Hostname after BOOPT/DHCP
Dave Whiteley <email@example.com> writes:
> What is the polite Debian way of automatically setting the hostname
> after booting using BOOTP/DHCP.
> ... /etc/hostname is identical on all
> the machines. The IP addresses are correctly discovered and set.
> I know that I could write a script that gets the host IP address, and
> then gets the name associated with that IP, and then updates the
> /etc/hostname; and that I could run this script "somewhere" in the
> bootup process, or even during the login process. ...
See the man page dhclient-script(8).
I've had success with a script /etc/dhclient-exit-hooks like this:
# Set the hostname
if [ x$reason != xBOUND ] && [ x$reason != REBIND ]; then exit; fi
echo dhclient-exit-hooks: IP address is $new_ip_address
hostname=$( host $new_ip_address | sed -ne 's/Name: //p' )
echo dhclient-exit-hooks: hostname is $( hostname )
You could update /etc/hostname too if you like.
School of Mathematics & Statistics, University of Sydney