1#!/bin/sh 2 3# This script can be installed in /etc/dhclient-enter-hooks to set the client's 4# hostname based either on the hostname that the DHCP server supplied or the 5# hostname in whatever ptr record exists for the assigned IP address. 6 7if [ x$new_host_name = x ]; then 8 ptrname=`echo $new_ip_address \ 9 |sed -e \ 10 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\4.\3.\2.\1.in-addr.arpa/'` 11 (echo "set type=ptr"; echo "$ptrname") |nslookup >/tmp/nslookup.$$ 12 set `sed -n -e "s/$ptrname[ ]*\(canonical \)*name *= *\(.*\)/\2 \1/p" \ 13 < /tmp/nslookup.$$` _ 14 if [ x$1 = x_ ]; then 15 new_host_name="" 16 else 17 if [ $# -gt 1 ] && [ x$2 = xcanonical ]; then 18 new_host_name=`sed -n -e "s/$1[ ]*name *= *\(.*\)/\1/p" \ 19 </tmp/nslookup.$$` 20 else 21 new_host_name=$1 22 fi 23 fi 24 rm /tmp/nslookup.$$ 25fi 26if [ x$new_host_name != x ]; then 27 hostname $new_host_name 28fi 29 30