Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I see on wikipedia that a host file maps IP addresses to human-readable hostnames, much like a DNS server. But does a local computer need to resolve IP addresses? Is the idea that you configure the hosts file for all of the computers on a network so as to customize/configure the network? (Kind of like for a local machine name in windows).

share|improve this question

2 Answers 2

See the manpage of the hosts file, there are some interessting parts.

man hosts
...
   Historical Notes
       RFC 952 gave the original format for the host table, though it has since changed.

       Before  the  advent  of  DNS, the host table was the only way of resolving hostnames on the fledgling Internet.  Indeed, this
       file could be created from the official host data base maintained at the Network Information  Control  Center  (NIC),  though
       local  changes  were  often  required  to  bring it up to date regarding unofficial aliases and/or unknown hosts.  The NIC no
       longer maintains the hosts.txt files, though looking around at the  time  of  writing  (circa  2000),  there  are  historical
       hosts.txt files on the WWW.  I just found three, from 92, 94, and 95.
...

The file is read before a DNS or any other lookup is made (order defined in /etc/nsswitch.conf). Is is also needed to map the hostname and the localhost to the loopback address (127.0.0.1).

One can summarize it as follows:

It is a burden of the last computer decade, but still usefull.

share|improve this answer

Chaos's answer is perfectly accurate, but there are a couple additional use case which I felt worthy of mentioning.

Aside from containing localhost, it's also a generally good idea to put the machine's hostname in the file as well. This is so that connecting to the local machine via it's hostname is fast and doesn't need a trip out to the network. Some programs can do this operation a lot, and so the performance is highly beneficial.

Another use case is for fault tolerance. Whenever I build clusters I always put entries for all machines in the cluster in each machine's hosts file. This is so that if there's some sort of network connectivity issue or DNS failure, the nodes in the cluster will still be able to communicate with eachother.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.