Multihomed hosts and /etc/hosts

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.)

These are my WanderingThoughts
(About the blog)

GettingAround
Full index of entries
Recent comments

This is part of CSpace, and is written by ChrisSiebenmann.

* * *

Atom feeds are available; see the bottom of most pages.

This is a DWiki.
(Help)

Categories: links, linux, programming, python, snark, solaris, spam, sysadmin, tech, unix, web

Search:
Written on 23 December 2007.
(Previous | Next)

Page tools: View Source, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Sun Dec 23 23:41:18 2007
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.