Setting up and using windows HOST file

Host files used in windows to describe many-to-one mapping of device names to IP addresses. Using this file is helpful when developing locally as it allows you to assign the URL of the site to a local IP.

First, find you host file:
Windows NT/2000/XP Pro c:\\winnt\\system32\\drivers\\etc\\hosts
Windows XP Home c:\\windows\\system32\\drivers\\etc\\hosts

The HOST file doesn't have an extention and can be opened with notepad.

** Before we go any further make sure you back this up - just in case ***

You should see something like:

......# Additionally, comments (such as these) may be inserted on individual# lines or following the machine name denoted by a '#' symbol.# For example:# # source server# # x client host127.0.0.1 localhost

As with SQL '#' mean comments, so the only active line there is localhost

What does that mean. Well everytime you access localhost (like in a browser, or PING'd from a command line) you are acutally accessing the IP address So lets say i'm developing a new blog. In Apache (or any web server) i'd set up the IP address to look at my document root. Then in the HOST file i'd have

Alternatively I could just point the host to instead of setting up a new IP. What you cannot do is map to a IP and port i.e.

By the way, if you're wondering why i've changed the URL to have www2 as the prefix? It's that the HOST file is used first when going to a domain. For example try out the following

then goto

N.B. If you use a proxy then you will need to bypass the proxy server for local addresses

comments powered by Disqus