[lug] Converting IPs to Domain Names and Vice Versa via Bash

David Morris lists at morris-clan.net
Wed Jan 26 17:33:30 MST 2005


On Wed, Jan 26, 2005 at 05:38:42PM -0700, Bill Thoen wrote:
> On Wed, 26 Jan 2005, David Morris wrote:
> 
> > If the system isn't too old try the 'host' command and pipe
> > the result through awk or sed to extract the information you
> > need.  On an older system try nslookup, but there is a lot
> > more information to filter out.
> > 
> > As an example:
> > 
> >     export IP=`host $1 | awk '{print $4}'`
> 
> For grins, I tried this but don't understand the results. Check this out.
> One IP resolves to two different domains. Then looking up each of those
> domains separately I get different IPs from the one I started with. What's
> going on?
> 
> # host 65.212.140.3
> 3.140.212.65.in-addr.arpa domain name pointer fw1.cellularonewest.com.
> 3.140.212.65.in-addr.arpa domain name pointer fw1.wwirelessintl.com.
> 
> # host cellularonewest.com
> cellularonewest.com has address 65.212.140.11
> 
> # host wwirelessintl.com
> wwirelessintl.com has address 12.129.20.143

Welcome to the land of DNS and all its confusing tangle of
nightmares. =D

Ordinarily a hostname can be mapped to any number of IP
addresses but an IP address can be mapped to only one
hostname.  This is why you are getting a different IP
address on the forward lookup than on the reverse lookup.
Use 'host -a <whatever>' to get a more detailed report.

I'm not certain why the reverse lookup gave you two replies,
I'm guessing that the system is a configuration error but I
don't know enough about DNS to say.

As for the IP address being reviersed in the reply of the
reverse lookup....that is just the way it is done.  I'm
certain there was a good reason at one time but its mostly
tradition now I suspect.

Running 'host -a' on a few items leads me to suspect that
one hostname was added to the same server as is handling the
other and whoever did it had no clue as to what they were
doing...several strange things in the reply.

--David



More information about the LUG mailing list