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:# 220.127.116.11 rhino.acme.com # source server# 18.104.22.168 x.acme.com # x client host127.0.0.1 localhost
As with SQL '#' mean comments, so the only active line there is
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 127.0.0.1. So lets say i'm developing a new blog. In Apache (or any web server) i'd set up the IP address 127.0.0.2 to look at my document root. Then in the HOST file i'd have
Alternatively I could just point the host to 127.0.0.1 instead of setting up a new IP. What you cannot do is map to a IP and port i.e. 127.0.0.1:8080
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 www.google.co.uk.
N.B. If you use a proxy then you will need to bypass the proxy server for local addresses