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

Rick Stevens rstevens at vitalstream.com
Wed Sep 8 17:24:48 UTC 2004


Aubrey Barnard wrote:
> 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

Good solution, Aubrey.  Actually, most ISPs don't give out host names.
When they do, it's often a fixed host name that has some permutation of
the IP address in it, and that's so they can provide a fixed reverse DNS
lookup.  For example, Road Runner typically has something like:

	cpe-66-75-xxx-yyy.socal.rr.com.

which indicates that the IP address was 66.75.xxx.yyy.  They just have
a bunch of these configured in their DNS.  Some ISPs will even accept
a hostname from the client, set it up and do a dynamic DNS update for
reverse DNS lookups.  Unfortunately, those are few and far between

Under Linux, it's not generally a good idea to set the hostname to some
DHCP-provided hostname.  It will break a lot of the authentication stuff
used in X, the printing system and ssh.  You can configure the DHCP
client to ignore the hostname provided.  It's often better to simply
ignore the provided hostname and stick with localhost or some other
fixed host name.
----------------------------------------------------------------------
- Rick Stevens, Senior Systems Engineer     rstevens at vitalstream.com -
- VitalStream, Inc.                       http://www.vitalstream.com -
-                                                                    -
-                  Heisenberg _may_ have slept here                  -
----------------------------------------------------------------------





More information about the Redhat-install-list mailing list