hostname 892 Bytes
Newer Older
Dimitris Aragiorgis's avatar
Dimitris Aragiorgis committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#!/bin/sh

# Filename:     /etc/dhcp3/dhclient-exit-hooks.d/hostname
# Purpose:      Used by dhclient-script to set the hostname of the system
#               to match the DNS information for the host as provided by
#               DHCP.
# Depends:      dhcp3-client (should be in the base install)
#               hostname (for hostname, again, should be in the base)
#               bind9-host (for host)
#               coreutils (for cut and echo)
#

if [ "$reason" != BOUND ] && [ "$reason" != RENEW ] \
   && [ "$reason" != REBIND ] && [ "$reason" != REBOOT ]
then
        return
fi

echo dhclient-exit-hooks.d/hostname: Dynamic IP address = $new_ip_address

hostname=$(host $new_ip_address | sed 's/.$//' | cut -d ' ' -f 5)

echo $hostname > /etc/hostname

hostname $hostname

echo dhclient-exit-hooks.d/hostname: Dynamic Hostname = $hostname

# And that _should_ just about do it...