Testing Your Website Before Changing Nameservers

Whether you are moving your domain to a new server or creating a new site, you may wish to test your site before the DNS entry is updated to show it live on the server.

You can override DNS settings locally by editing the hosts file on your computer. This allows you to view the website as if it were hosted at the server’s IP address, while everyone else who visits your site will still reach the IP address with the current nameservers.

When you are done testing the site you can edit your hosts file again to switch back to using DNS.

For Windows (Vista, 7, 8, 10)

You will need to first edit your hosts file, and then flush your DNS cache before you can view the site in your browser.

Editing the Hosts File
  1. In the Windows start menu, search for “Notepad”. Right click and select “Run as administrator”.
  2. Navigate to File > Open…
  3. Navigate to ‘c:\windows\system32\drivers\etc’ and change the display files type to “All Files”.
  4. Select the hosts file and click “Open”.
  5. For each IP address/site that you want to test, add a line at the bottom of the file with the IP address, the domain address, and the ‘www’ address separated by spaces. It should look something like this:
    123.0.0.1 domainname.com www.domainname.com
  6. Alternatively, if you want to be able to compare the way the site looks on the new IP with the current one, you can leave off the ‘www.’ URL. This way, if you visit ‘domain.com’ you will see the new IP but if you visit ‘www.domain.com’ you will still see the domain with the current DNS. If you do this, the line should look something like this:
    123.0.0.1 domainname.com
  7. Go to File > Save as.
  8. Change the save as type to “All Files”.
  9. Click on the hosts file in the window. If you click save without choosing the current hosts file from the window, Notepad will only save it was a ‘.txt’ file and not overwrite the actual hosts file.
  10. Click “Save”.
Flushing the DNS Cache
  1. In the Windows start menu, search for “cmd” and press enter. This will open Command Prompt.
  2. Type ‘ipconfig /flushdns’ and press enter. You will see the following
    C:\Users\user>ipconfig /flushdns
    Windows IP Configuration
    Successfully flushed the DNS Resolver Cache.
    C:\Users\user>

Now you are ready to test the IP address by visiting your domain in a browser.

Restoring your Hosts File

When you are done testing the new IP, remember to restore the original hosts file.

  1. Open your hosts file in Notepad as before.
  2. Remove the line containing the IP address and domain you were testing.
  3. Go to File > Save As…
  4. Select “All Files” as the save as file type, and click on the hosts file.
  5. Click “Save”.
For Mac

You will need to first edit your hosts file, and then flush your DNS cache before you can view the site in your browser.

Editing the Hosts File
  1. Open Finder.
  2. Select “Applications” from the right sidebar.
  3. Find and open Utilities.
  4. Find and open Terminal.
  5. Type the following command and hit return:
    sudo nano /etc/hosts
  6. Type your administrator password (it will not be visible for security purposes) and hit return.
  7. You should now see the nano text editor, which will display the file’s contents.
  8. For each site that you want to test, add a line to the file with the IP address and domain name separated by spaced. It should look like the following:
    123.0.0.1 domainname.com www.domainname.com
  9. When you are finished adding the line(s), hit control + O to save, then control + X to exit.
Flush the DNS Cache
  1. Type the following into Terminal and hit return.
    sudo killall -HUP mDNSResponder
  2. You may need to enter your administrator password again, and hit return.

You can now test the new IP by visiting your domain in a browser.

Restoring the Hosts File

When you are done testing IPs, remember to restore your hosts file to its original state.

  1. Follow the steps above (1-7) to open Terminal and run the nano text editor.
  2. Delete the lines that you added to the file.
  3. Hit control + O to save, and control + X to exit.