As a side note to looking up hostnames from IP addresses for people who use
/etc/hosts
, note that
/etc/hosts
lookups work badly in the presence of hosts with multiple IP address, since most
gethostbyname()
implementations will only return the first IP address that they find in
/etc/hosts
. These days you really want a minimal
/etc/hosts
and a reliable DNS server, unless you have special concerns .
(The
gethostbyname()
behavior is sensible, since otherwise it would always have to scan the entire
/etc/hosts
file just to make sure that it had found all IP addresses for a host, even when most hosts only have one IP address.)
While there are workarounds for this issue, I think that the best way out is just to not have any entries for your multihomed hosts in
/etc/hosts
, even on the hosts themselves. This appears to work fine on at least modern Linuxes, and I can't imagine that the *BSDs do any worse here.
(You can have similar behavior with
gethostbyaddr()
, depending on how you give an IP address multiple names in
/etc/hosts
. Putting all the names on one line works out, but having multiple lines for one IP address has the same problem.)