Edit Hosts Files to view website on test server

If you are moving a site to a new server, or building a new site for a client, you will want to be able to test it before updating the name servers. This task is very simple to do on both Linux and Windows PCs.

All you need to do is add a line in the etc/hosts file like this:

00.00.000.000 www.test_the_domain.com

Where 00.00.000.000 is the IP address of the new / test server.

From now on whenever you look at www.test_the_domain.com in a browser you will see the version on the specified server rather than the version where the name servers at the registrar point to.

This is possibly one of the most useful and yet most basic testing tools when rebuilding a website for a client, as it gives you an easy way to view and test the site while you are building it without comprimising the live version. The new site can be built and tested fully before updating the name servers and putting the new site into the “production environment”.

It can also be done on a Windows machine, you may need to reboot the pc after amending the hosts file (there is no need for a server restart on Linux). Location the hosts file in Windows (Windows NT/2000/XP/2003/Vista/7);

%SystemRoot%\system32\drivers\etc\ – this is the default location, which may be changed. The actual directory is determined by the Registry key \HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DataBasePath.

Remember to always test thoroughly before passing a new site to a client.

Fun fact: Earl hackers and phishers used create viruses / Trojans to edit the hosts files. They would create a website that looked the same as one you use (e.g. your bank or Amazon) and direct you to that site when you enter the address. New anti-virus software and better security in Windows makes an extra effort to stop this activity.

3 Comments on “Edit Hosts Files to view website on test server”

  1. Oh, some Windows OS do not need a reboot after the hosts file is changed.

    Also, remember to delete the line in your hosts file after testing etc. as this can cause confusion later on for you!

Leave a Reply

Your email address will not be published. Required fields are marked *