linux-users archive

Debian - setting hostname from DHCP result


New Message Reply Date view Thread view Subject view Author view

From: David Brodbeck (email_suppressed_at_lugwash.org)
Date: Tue 30-Dec-2003 03:44:20 PM EST


Thought I'd share this, since I spent a little while getting it to work. My
boss has a Comcast cable modem, and when he used RedHat his computer's
hostname was automatically set when DHCP negotiation was done. He wanted
the same behavior on his Debian install. I found a dhclient-exit-hooks
script online, but it assumed an older version of the 'host' program and
didn't work on his Debian 3.0 system. Here's one I scabbed up that does
work. I'll double-space it so wrapped lines are clear.

#!/bin/sh

# Set the hostname - put this in /etc/dhclient-exit-hooks

if [ x$reason != xBOUND ] && [ x$reason != xREBIND ] && [x$reason !=
xREBOOT]; then exit; fi

echo dhclient-exit-hooks: IP address is $new_ip_address

hostname=$( host $new_ip_address | perl -e '<STDIN> =~ / ([\w\.]*)\.$/;
print $1;' )

hostname $hostname

echo $hostname >/etc/hostname

echo dhclient-exit-hooks: hostname is $( hostname )

(I'll admit part of the reason I'm posting this to the list is so I can find
it again next time I need it. ;) )

---
David Brodbeck, System Administrator
InterClean Equipment, Inc.
3939 Bestech Drive Suite B
Ypsilanti, MI 48197
(734) 975-2967 x221
(734) 975-1646 (fax)
 
--
***  Sent from [e-mail suppressed]  ***  http://www.lugwash.org
to unsubscribe: `echo "unsubscribe" | mail [e-mail suppressed]`

New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.1.5 : Thu 01-Jan-2004 01:00:03 AM EST