DHCP client assigns an invalid hostname (RH9) -Solution!

Aubrey Barnard aubreys_key at yahoo.com
Wed Sep 8 02:58:45 UTC 2004


To whomever this may help:
     I feel obligated to send my solution as a thank you to those who
helped me earlier. I'm sorry my reply was not sooner, but things get out
of hand...

Situation recap:
     My ISP was not assigning me a hostname via DHCP.

Solution:
     After calling Charter and receiving contradictory answers, including
people at district headquarters, someone eventually confirmed with
certainty that they do not issue hostnames to residential cable internet
clients, although they could not give me a good reason why.
     The next step was to write a script to 'manually' assign myself the
proper hostname. The following is that script, such as it is: (I placed it
in root's home, an arbitrary location.)
/root/manually-set-hostname.sh:
#!/bin/bash
 
# Get the ip address
ipAddress=$(ifconfig | egrep 'inet addr:.*Bcast:' | sed -r -e 's/.*inet
addr:(\W*)  .*/\1/')
#echo "The IP address is '$ipAddress'."
 
# Get the hostname from a DNS server
dnsReply=$(host $ipAddress)
 
# See if the reply from the DNS server found a hostname for this IP
address
if [[ $(expr "$dnsReply" : '.*not found') = 0 ]]
then
    # Things are OK, as the IP address was found
    #echo "A hostname was found!"
 
    # Extract the hostname from the reply
    hostname=$(expr "$dnsReply" : '.*domain name pointer \(.*\)\.')
    #echo "Hostname is $hostname"
 
    # Set the hostname
    echo "Setting hostname '$hostname' for address '$ipAddress'"
    hostname $hostname
else
    # host did not find the IP address -error
    echo "Could not manually set the hostname because the IP address was
not found."
fi

The script will work on its own, but it would be much more convenient to
be done automatically at boot. (Like, duh!) I don't know anything about
how linux boots, but I dug around and placed a call to my script in
/etc/init.d/network. I placed the call after the network interfaces were
started, but before the CIPE VPN interfaces, like this:
/etc/init.d/network:
...
        # bring up all other interfaces configured to come up at boot time
        for i in $interfaces; do
...
                action $"Bringing up interface $i: " ./ifup $i boot
        done
                                                                          
     
        # Manually set the hostname -for compatibility with Charter
internet
        # Added by barnard, 08/15/04
        /root/manually-set-hostname.sh
                                                                          
     
        # Bring up CIPE VPN interfaces
        for i in $cipeinterfaces ; do
...

This may not be the best solution, and my bash script isn't pretty, but it
worked, and thus I pass it along. Comments and feedback are welcome. I
hope this can help somebody, maybe someday. I doubt too many Charter
customers are Linux users, though.

Happy Linux trails, y'all,
     Aubrey


		
__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail





More information about the Redhat-install-list mailing list