[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to get an IP address



Clive Standbridge wrote:
> Kind people have already suggested dig and host,

'dig' and 'host' are the portable way to look things up since those
either already exist or can exist on any Unix-like system.

> but may I make another suggestion:
> 
>    getent hosts $hostname | awk '{print $1}'
> 
> It appears that host and dig only look at DNS, whereas you may be
> using other name resolution methods e.g. a hosts file. "getent hosts"
> takes account of that.
> 
> Also, getent is always installed (as far as I can tell), whereas host
> and dig may not be installed.

The 'getent' utility is part of GNU glibc and is present on any GNU
glibc based system but not present on others.  It won't work on HP-UX
for example.  Certainly if you only care about GNU/Linux machines then
you should be safe using it.  A good suggestion.

Bob

Attachment: signature.asc
Description: Digital signature


Reply to: