Click to search Andy Jarrett.co.uk RSS feed

Loading Twitter

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:

view plain print about
1......
2# Additionally, comments (such as these) may be inserted on individual
3# lines or following the machine name denoted by a '#' symbol.
4# For example:
5# 102.54.94.97 rhino.acme.com # source server
6# 38.25.63.10 x.acme.com # x client host
7
8127.0.0.1    localhost

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

view plain print about
1127.0.0.1    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 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

view plain print about
1127.0.0.2    www2.andyjarrett.co.uk

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

view plain print about
1127.0.0.1    www.google.co.uk

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

Comments Comments (0) | Print Print | Send Send | 12221 Views

If you like what you see on the website and/or this post has helped you out in some way please consider donating to help keep me in beer vodka. The donations are made through Paypal, which accepts almost any credit card or eCheck.

(Comment Moderation is enabled. Your comment will not appear until approved.)
BlogCFC by Raymond Camden + Twitter @AndyJ + ColdFusion jobs + Contact Me + Snippets/Downloads + RSS .