Saturday, February 6, 2010

DNS Host Files

One of the most powerful tools available to somebody working on their site during a migration is their computer’s ‘hosts’ file. This file is especially useful when migrating a site between two servers, or any other time when DNS might not be working properly.

Lets start with an example of the the information that would be found in a typical hosts file: localhost

That is all you will generally see in a clean hosts file. Its layout is tab or space delimited. The first field in the line is the IP address that you would like the site to resolve to, and any additional fields after that should be domain names. For example, if I wanted to reroute to some other location I might put a line in my hosts file that looks something like this:

As you can see, this will redirect both and to the IP address of When moving a site to a new server, you can use this file to test out your sites to ensure that they work after the move, while still leaving your original site online. Simply point the desired IP address at the domain name in question and you computer will connect to the new IP whenever you type in the domain name.

This file is located in a few different places depending on your operating system. The file name is ‘hosts’ no matter what operating system you have.

On Windows XP/2003/Vista/7 this file is located in:

(Typically C:\Windows\System32\drivers\etc)

With Vista/Windows 7 you will need to edit this file with administrative privileges. You can do this by following one of these two sets of intructions:

1. Click on the Windows logo.
2. Search for ‘notepad’
3. Right click on the notepad launcher and select ‘Run As Administrator’
4. Click File, then Open
5. Browse to the folder mentioned above and select the hosts file


1. Click on the Windows logo.
2. Click on Search.
3. Search for the word “hosts” (Please be advised this search can take several minutes to complete)
4. Double click on the hosts file and choose notepad as the program to open the file once prompted


On Mac OS X, your hosts file is located here:


You will need administrative privileges to edit this file.

On Linux, you can find the hosts file here:


Depending on the distribution you may need administrative privileges to edit this file.
Please remember to revert the hosts file to its original state after the migration is complete.

Feel free to link to this post or write a comment if it has solved your problem. This way other people are more likely to find it :)  

No comments:

Post a Comment