How to test your website on another server without changing the DNS


How to test your website on another server

Can you test your website on another server without changing the DNS (domain name servers)?
Can you test your website by creating a fake DNS IP?

Recently a client asked if I could move his website to my servers to test if all the files (databases, scripts, contact forms) would function correctly before changing the DNS for his domain.

Explanation of hosts file

According to Wikipedia “The hosts file is a computer file used in an operating system to map hostnames to IP addresses….the hosts file is a plain-text file and is traditionally named hosts.”

How to find the hosts file on your computer

Windows 95 – C:windows
Windows 98 – C:\windows
Windows Me – C:\windows
Windows 2000 – C:windows\system32\drivers\etc
Windows XP – C:\windows\system32\drivers\etc
Windows Vista – C:\windows\system32\drivers\etc
Windows 7 – C:\windows\system32\drivers\etc

  • On my computer I found the hosts file by going to c:\windows\system32\drivers\etc\hosts (where “c:\windows” is the Windows directory).
  • Simply open up a folder and insert C:\WINDOWS\system32\drivers\etc
  • To view hidden files go to tools – folder options – view
  • Uncheck “hide extension for unknown file types”
  • Check “show hidden files and folders”
  • Click “OK” to apply the changes.
  • Now you should be able to view the hosts file

Alternatively go to:
My Computer – WINDOWS – system32 – drivers – etc

What the hosts file looks like

Here’s a sample of what the hosts file looks like:

****************************************************
# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a ‘#’ symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host

127.0.0.1 localhost
********************************************************
How to edit the hosts file

Below this line…
127.0.0.1 localhost
add the following line and save the file:
1.2.3.5 domain.com

1.2.3.5 domain.com would be the new IP address of your server plus the domain name you’re testing. When you enter domain.com into your browser it will reference the new IP address, 1.2.3.5, instead of the DNS listed.

You can test if the hosts file is working correctly on your computer by adding 1.2.3.5 Google.com (where 1.2.3.5 is the new IP address). When you enter Google.com in your browser it will say “apache is working correctly”

Sidebar

Add an entry for every and any domain or subdomain you’re testing. For example if you need to test “domain.com” and “www.domain.com”, create two entries on separate lines. ie

1.2.3.5 domain.com
1.2.3.5 www.domain.com

* Remove the entries from your hosts file after you’ve finished testing. This is because the hosts file overrides the DNS. If you don’t remove the entries your computer will continue to display the website using the IP address listed in the hosts file (not the original IP address of the website you’re testing).

* Your anti-spyware or anti-virus program could prevent making changes to the hosts file. You can temporarily disable the program settings while performing your test. Just make sure to enable the settings when you’ve finished testing.

How to test your website (without changing DNS)

  • Create a new hosting account on your server and make a note of the new IP address
  • Make a backup of all your files before uploading (including databases and scripts)
  • Upload the files to the server (be sure to import your database files)
  • Add the entry to your hosts file ie 1.2.3.5 domain.com
  • Test your website on the new IP by entering the website address in your browser.
  • Change the DNS to point to your server if the website is functioning correctly
  • Remove the entries from your host file after testing is completed.

Uses of the hosts file

Block Spyware/Ad Networks
You can add lists of ad network and spyware sites to your hosts file. This blocks malicious sites from infecting your computer.

As you can see the hosts file is a powerful tool for testing websites without changing the DNS and can also be used to block malicious programs so your computer is more secure.

*******************
Not happy with your current web hosting service
Check out my web hosting plans for small businesses
I’ll test your website on my server without changing your current DNS?

Comments

  1. Only fifty percent of the post is displaying, strange, is this my browser or the site?

  2. Mathew…the post displays fine in the major browsers..which one are you using?

  3. Its awesome how much more attention I get from the opposite sex now that I own a Challenger!

Leave a Reply to Matthew C. Kriner Cancel reply

*