How to use hosts file to override DNS for local testing

From time to time you need to test a website locally by domain name without actually changing the live DNS entry.  Fortunately there is an easy way to do this.  When you make a request to the Internet using your local computer it first checks your hosts file for an entry and if one isn’t present it goes out to the Internet DNS servers.

Because of that you can override the DNS servers for your local machine by adding an entry to the hosts file.  To do this open up your hosts file with notepad.  It is located at C:\Windows\System32\drivers\etc.

Once you have it opened, go to the bottom of the file and add a new line.  You will first add the IP address that you want it to resolve to, a space, and then the domain name.  For example, if you are testing a website that you are developing on your local machine that has an internal IP address of and you want to test you would add the following line to your hosts file:

Save the file and you’re all set!  You should note that if you want to also test you also need to add an entry for it.  Based on the example above it would be:

Rick is a Senior Support Lead at OrcsWeb, a hosted server company providing managed hosting solutions.