What is the HOSTS file?
The HOSTS file is used by your computer’s Operating System (Windows, OS X, Linux, etc) to map hostnames to IP Addresses. In layman’s terms your computer will check this file for any domain it needs to resolve to an IP Address prior to querying public DNS resolvers. The HOSTS file can be used to point a domain name to an IP Address regardless of the DNS settings for the domain.
An example of a HOSTS entry to load “www.example.com” and “example.com” from the IP address “126.96.36.199“:
188.8.131.52 www.example.com example.com
Windows may require two separate lines like so:
When the above records are added to your HOSTS file the result is that if you try to load that domain in your browser it will connect to that IP to make the request. If you try pinging the domain you will find that it pings that IP as well. What this means is that you can use this to test your site on a new server before you point your world-wide DNS there. Continue reading “What is the HOSTS file & when should I use it?”