Got more questions? Find advice on: ASP | SQL | XML | Regular Expressions
in Search
Welcome to WindowsAdvice Sign in | Join | Help

Steven Smith

Windows Tips and Tricks

Editing the Hosts File

If you've ever wanted to work on a production site while in development and verify that all of the links work properly (even the ones that include absolute URLs), an easy way to do it is to alter the HOSTS file on your development computer.  Your HOSTS file lets you map domain names to IP addresses, just like a tiny DNS (Domain Name Service), but only for your computer.  You'll find the HOSTS file here:

C:\Windows\System32\Drivers\Etc\

If you're going to be doing a lot of editing, you can add a shortcut to your desktop pointing to the file.

Note that the HOSTS file does not have a file extension.  Do not add one.  You should edit the file with Notepad; just be sure it doesn't try to be helpful and add a '.txt' extension when you save it.

Your Hosts file has entries like this one:
127.0.0.1      localhost

The first number is an IP address.   127.0.0.1 is a loopback address -- it always refers to your computer.  By default, localhost always maps to your computer because of this entry in the HOSTS file.  Let's say you're working on a site called 'mysite.com' and you want to test a local instance of it using that domain name.  You would simply ensure that your local webserver was set up to handle requests for that domain and IP address, and then add this line to the HOSTS file:

127.0.0.1      mydomain.com

Now when you open your browser and go to 'mydomain.com' it will hit your local webserver.  Similarly, if you go to a command prompt and try to ping mydomain.com, you'll get 127.0.0.1 back as the IP address.  To remove the entry, you can comment it out by adding a '#' to the beginning of the line you wish to remove:

#127.0.0.1      mydomain.com

If you have questions, feel free to comment.
Published Monday, March 21, 2005 1:06 PM by ssmith
Anonymous comments are disabled

About ssmith

Enlisted in 1995. Basic at Ft Sill. AIT at Ft Jackson (75F). Served in Ohio National Guard. Went through ROTC program at Ohio State University and received 2LT commission in 1997, Engineer branch. Spent about 4 years in 16th Engineer Brigade in Ohio National Guard, then moved far from nearest unit and went into Inactive National Guard, and eventually Individual Ready Reserve. Called up from IRR in 2004 for duty in Iraq (Engineer Platoon Leader with 1st ID). Made it home in 2005. Resigned commission as a CPT in December 2005.