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:

set_hostname() {
    local current_hostname=$(hostname)
    if [ -z "$current_hostname" -o "$current_hostname" = "(none)" ]; then
        hostname "$new_host_name"
    fi
}

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
#!/bin/sh

# if we got a new lease with a hostname, set the hostname

if [ "$reason" = 'BOUND' ] && [ "$new_host_name" ]
then
        hostname "$new_host_name"
fi


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
is straight-forward:

/etc/ethers:

00:11:22:33:44:55:66 ian


/etc/hosts:

192.168.0.130   ian

-- 
               Tzafrir Cohen
icq#16849755              jabber:[email protected]
+972-50-7952406           mailto:[email protected]
http://www.xorcom.com  iax:[email protected]/tzafrir


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to