using hostname from dhcp
In our network we set host names for machines in the dhcp server.
When I use the live CD in our internal network, however, the host name
assigned to the host (or rather: MAC address) is overriden by "debian".
If I boot with 'nohosts' I merely get 'localhost.localdomain' , as this
is the default /etc/hostname file left there.
I figured that 'debian' is better than nothing. However I would still
prefer to get the hostname.
The hostname is set by the following in /sbin/dhclient-script:
if [ -z "$current_hostname" -o "$current_hostname" = "(none)" ]; then
I figure that the real fix for that may be to conditionally unset
'current_hostname' in a enter hook (only if we got a new hostname).
But for now I use a simple exit hook:
$ cat config/chroot_local-includes/etc/dhcp3/dhclient-exit-hooks.d/hostname
# if we got a new lease with a hostname, set the hostname
if [ "$reason" = 'BOUND' ] && [ "$new_host_name" ]
Results will naturally differ if you use a different dhcp client. I
recently tried udhcpc and it was actually functional :-)
Notes on testing this:
If you use qemu / kvm with its usernet, you can tell it to set the
hostname it its built-in dhcp server using something along the lines of:
kvm -net user,hostname=ian -net nic binary.img
In our network we use dnsmasq. Setting a "static" hostname entry there