diff options
author | Ted Lemon <source@isc.org> | 1999-10-04 23:01:27 +0000 |
---|---|---|
committer | Ted Lemon <source@isc.org> | 1999-10-04 23:01:27 +0000 |
commit | 5e3960b64a5432d4c432602a170eddfeb8a9309e (patch) | |
tree | 2b16c9a32e9819ea80f516501a11aa0332ef0312 /contrib | |
parent | 7d7a35faabc22ea9629f9b0d38abb62e3a0221a5 (diff) | |
download | isc-dhcp-5e3960b64a5432d4c432602a170eddfeb8a9309e.tar.gz |
Set hostname from value sent by DHCP server
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/sethostname.sh | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/contrib/sethostname.sh b/contrib/sethostname.sh new file mode 100644 index 00000000..7088c00a --- /dev/null +++ b/contrib/sethostname.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +# This script can be installed in /etc/dhclient-enter-hooks to set the client's +# hostname based either on the hostname that the DHCP server supplied or the +# hostname in whatever ptr record exists for the assigned IP address. + +if [ x$new_host_name = x ]; then + ptrname=`echo $new_ip_address \ + |sed -e \ + 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\4.\3.\2.\1.in-addr.arpa/'` + (echo "set type=ptr"; echo "$ptrname") |nslookup >/tmp/nslookup.$$ + set `sed -n -e "s/$ptrname[ ]*\(canonical \)*name *= *\(.*\)/\2 \1/p" \ + < /tmp/nslookup.$$` _ + if [ x$1 = x_ ]; then + new_host_name="" + else + if [ $# -gt 1 ] && [ x$2 = xcanonical ]; then + new_host_name=`sed -n -e "s/$1[ ]*name *= *\(.*\)/\1/p" \ + </tmp/nslookup.$$` + else + new_host_name=$1 + fi + fi + rm /tmp/nslookup.$$ +fi +if [ x$new_host_name != x ]; then + hostname $new_host_name +fi + |