How to Change Host Files on Windows

Sometimes we need to change host files in windows because the domain name is not publicly pointing to the correct server.

So how does it work?

When we type and go to a domain name in browser, let’s say, your browser does not reach the server right away. There are the (simplified) steps:

  1. the browser will seek for the DNS information on the domain (usually through public sources)
  2. the DNS information will contain an IP address, which is the precise “address” for the server
  3. the browser contacts the IP address, requesting for the website.

So you can see if #1 – the DNS information is not available or not up-to-date or wrong, then the browser will never get to the correct server.

The DNS information is usually not wrong, but sometimes it is. For example, if the domain owners just updated the DNS information / change server, usually it takes hours or even half a day for new / correct information to be shown publicly. (The process is called DNS propagation) So during this time, any one trying to go onto the website will get an error.

So when we do web development, sometimes we will want to work on a website before the domain settings are correct. (Don’t want to wait!). To bypass this, we can give the computer direct instructions on what IP address to look when trying to go on a domain name. We do this by editing the host file to override public information. Any change will only affect our own computer. Other people will not be affected.

The above literally means if user want to go to “” , the browser shall contact IP address

(your browser will not use public DNS information, but will use your override instead.)

Steps on how to edit hosts file on Windows

  1. Search for notepad
  2. Right click on Notepad on the search result, then choose to run as administrator
  3. Once notepad is run as administrator, open up the file using the c:\windows\system32\drivers\etc\hosts
  4. Update the host file, add on the IP address and website address
  5. Click Save

This does not work, how do I fix?

If the host file is edited but still does not work, it is likely due to DNS cache. Your computer AND browser saves old DNS information and re-use it so it does not have to do a DNS look up every time. But this means you need to clear BOTH cache for this to work.

  1. Go to command prompt (dos), issue command – this clears computer dns cache
  2. ipconfig /flushdns
  3. Close ALL browser tabs and use private mode
  4. Or just use another browser that was not on website before (so old cache is not used)
  5. This clears browser dns cache

This should work 99% of the time


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>