Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

DNS resolves the domain names to IP address then why do we need hosts file in our machine with domain name -> IP address mapping? One disadvantage is that the ip address could change.

Is there any reason why we need hosts file?

share|improve this question
add comment

4 Answers

up vote 1 down vote accepted

Hosts files were used on those old days to provide an easier way of referring to a host: instead of decorating numbers you could create an alias to it.

Things got bigger, hard to maintain, specially when changes were made: you would have to update the host file of each computer in your network and problems could arise while some computers were updated and others weren't.

So DNS appeared and made everything a lot easier. But no one was obliged to eliminate the host file. There was no common definition of where the DNS server would be located, nor protocols specifications on how to broadcast requests to find those DNS servers. So it was possible to use the host file to indicate where to look for a DNS server, and then letting the DNS server handle all other inquires, for example.

Hosts files can also be thought as a security measure: it's under the control of the system administrator of the computer, and so it's thought to be secure: the one who alters it should know what he is doing. And even in the case of the compromise of the DNS server, the hosts file would remain trustful.

share|improve this answer
add comment

There are two important reasons. One is provide any local overrides that should take precedence over DNS. The other is to 100% ensure the ability to resolve critical IP address mappings under conditions where the machine might not be able to reach a DNS server.

Historically, the hosts file predates DNS. Way back before DNS, everyone downloaded the latest hosts file from a central repository.

share|improve this answer
add comment

Assuming that you already read the wikipedia link. I'd say having a plain text file that you can use to point any domain to whatever IP you like is a lot more convenient than, say, adding records to a DNS server. Think of you as a developer trying to make a fancy application that fakes example.com (or any other domain). It's easier to edit your local hosts file and change the hostname so when you point your browser to a sub-domain it goes to your own application:

127.0.1.1 www.example.com mobile.example.com etc.example.com
share|improve this answer
add comment

I'm sure there are some more obscure origins for the hosts file as most present day operating systems have one (*nix, BSD, Windows) however they are useful in situations where you need to override published (authoritative) DNS with a local record for testing, troubleshooting, or other similar tasks.

share|improve this answer
add comment

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.