Package: isc-dhcp-client<br>Version: 4.1.1-P1-15<br><br>The logic to set the hostname on boot when that hostname is supplied via dhcp is not working. Looking at the code in dhclient-script, it appears flawed. Testing reveals unexpected content in the variables.<br>
<br>My environment: the dhcp server is sending 'option host-name' to send the hostname to the client. Examining /var/lib/dhcp/dhclient.eth0.leases shows that the hostname is present. The same environment successfully hands out a hostname when the system is booted with Lenny; it fails when the system is booted with Squeeze. Note that I removed /etc/hostname to force it to get the hostname from dhcp. The hostname is being handed out by a system running Debian Etch and dhcp3-server 3.0.4-13+etch2<br>
<br>The code that sets the hostname on lenny is as follows:<br><br>/sbin/dhclient-script from dhcp3-client version 3.1.1-6+lenny4, lines 102 to 107<br>set_hostname() {<br> local current_hostname=$(hostname)<br> if [ -z "$current_hostname" -o "$current_hostname" = "(none)" ]; then<br>
hostname "$new_host_name"<br> fi<br>}<br><br>The code that sets the hostname on squeeze is as follows:<br><br>/sbin/dhclient-script from isc-dhcp-client version 4.1.1-P1-15, lines 155 to 158<br> if [ -n "$old_host_name" -a -n "$host_name" -a \<br>
"$host_name" != "$old_host_name" ]; then<br> hostname "$new_host_name"<br> fi <br><br>The first thing that I believe is a bug is that the if clause tests against $old_host_name and $host_name, but the hostname is set to $new_host_name.<br>
<br>I put some print statements around this clause to show the contents of the three variables. <br><br>On boot, $old_host_name is empty, $host_name is empty, and $new_host_name has the hostname given to the machine from dhcp. Since this if clause tests that both $old_host_name and $host_name are non-empty, the statement to set the hostname is not executed. <br>
<br>If, after the system has booted, I run '/etc/init.d/networking restart', the contents of the variables are $old_host_name = the host name assigned by dhcp, $host_name is empty, and $new_host_name is the hostname assigned by dhcp. Since $host_name is empty, the statement to set the hostname is not executed. Note that even though $old_host_name contains the hostname given out by dhcp, the hosts' name (as shown by running 'hostname') is "(none)". $old_host_name seems to be incorrectly populated.<br>
<br>I believe the previous behavior of setting current_hostname=$(hostname) and testing it against "(none)" will cause the system to behave as I expect. I don't understand why the previous hostname must have content in order for the new hostname to be set, and it seems as though testing $host_name instead of $new_host_name is a typo.<br>
<br>Thank you,<br><br>-ben<br>