[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Setting hostname with DHCP



Michael Ash wrote:
> However, my results with setting the hostname and domain
> were no better with dhcp3 than with dhcp (v2).  Are there
> parameters not listed in dhclient.conf that I should be
> setting?  (Again, my desired behavior is that the DHCP
> server set the hostname and the domain for my computer.)

In that case then probably the easiest thing would be to modify the
client script.  It is a conffile and so won't be overwritten when you
upgrade in the future.  But you should probably keep up with future
upgrades and just merge in your changes then.

Let me suggest the following patch.  I just wrote this on the fly a
few moments ago so it should be treated with some caution.  But it
worked for me and I think will give you a good idea of how to do
this.  Basically after networking is started, so this must go in after
the ifconfig commands earlier in the script, use dig to get the
hostname back from DNS.  Use that to set the hostname.

Test the dig command manually first.  I am using bind9.  It reports
the hostname with a trailing dot.  Different versions may have
different output.  Verify this for you before installing this patch.
If you have an older version the +short terse answer mode may be
missing.  If you have an older version you should use the bind9-host
command instead then or perhaps a different command.  The important
thing is to be able to reverse map your IP address and extract your
DNS hostname.  You may need to modify this quick hack for your
particular configuration.

  dig -x 192.168.1.2 ptr +short

  host -t ptr 192.168.1.2 | awk '{print$NF}'

--- dhclient-script.original    Sun Oct 26 23:30:46 2003
+++ dhclient-script     Sun Oct 26 23:54:48 2003
@@ -172,6 +172,11 @@
     route add -host $alias_ip_address $interface:0
   fi
   make_resolv_conf
+  new_host_name=$(dig -x $new_ip_address ptr +short)
+  new_host_name=${new_host_name%.}
+  if [ x$new_host_name != x$current_host_name ]; then
+    hostname $new_host_name
+  fi
   exit_with_hooks 0
 fi

I am not really sure what other running daemon services such as your
postfix or exim program or other things will handle it when the
hostname changes under them.  Those services might need to be
restarted too.  You will need to keep an eye on those.

Bob

Attachment: pgpIqwKFbZUPm.pgp
Description: PGP signature


Reply to: