Windows "hosts" file and rewriting the IP address

In Windows, a special file (called "hosts") is used to map IP addresses to host names (domains). This file is checked by Windows, Internet Explorer, etc. BEFORE a DNS server contacted.

By changing the "hosts" file, it is possible to change the IP address a hostname (domain name) "points to" - or in other words: change the IP address provided by the DNS server.

This is very handy in many situations, e.g. when developing a website which is currently running (placed) on another server / IP address. By changing the "hosts" file you can force your browser to go to an alternate IP address (e.g. your own VPS) when entering a domain in the browser.

Below is an example of a "hosts" file, where "www.mynewdomain.dk" and "mynewdomain.dk" is mapped to the IP address 91.250.81.85 - This means that when you type "http://www.mynewdomain.dk" in your browser, the request will be routed to the IP address 91.250.81.85, instead of what-ever might actually be listed in the DNS.

Windows hosts fil


Windows "hosts" file is located in the folder "c:\windows\system32\drivers\etc" - Note that this file is a protected file, so you have to run Notepad (or another editor) as Administrator ("Run as administrator")

Windows hosts fil placering

Tags