Hosting Question? Find the Solution -

KNOWNHOST KNOWLEDGE BASE

Browse our Guides, Articles, and How-To's

How can I test my migrated website before changing the DNS?

Category: Getting Started
Tags: # # # # #

The recommended method of testing websites before changing DNS for a domain is to edit the local hosts file on your computer. This will bypass the DNS lookup from your computer to that domain – allowing your computer to “see” the site as it is in your new service without making any changes to the site or the service.

How to edit your local “hosts” file

This is the preferred method to test your site, as many sites (and most common site software such as WordPress) use Apache mod_rewrite rules – other methods of testing a site before changing DNS can interfere with the way these rules allow your site to work. This method is a bit in-depth and requires some working knowledge of your operating system. I will attempt to break it down as much as possible.

Windows Operating Systems

  • Locate the HOSTS file on your computers. Typically it is in one of the following locations:
    • Windows NT/2000/XP/2003/Vista/7/8/10 – C:\windows\System32\Drivers\etc\hosts
    • Windows 95/98/ME – C:\windows\hosts
  • Open this file with a text editor such as Notepad or Wordpad. (Right-click on Notepad and select the option to Run as Administrator – otherwise you may not be able to open or edit this file.)
  • Then, open the file. Consider performing a “Save As” so you have an original copy of the file that you can restore later. You will see two columns of information, the first containing IP addresses and the second containing host names. By default, a windows hosts file should be similar to the following (after the lines of comments):
    • 127.0.0.1 localhost
  • You can add additional lines to this file that will point requests for a particular domain to your new server’s IP address. Example:
  127.0.0.1 localhost

  67.222.1.2 example.com
  67.222.1.2 www.example.com
  • Save your changes.
  • Restart any currently open browsers. You may also want to flush your DNS cache. In most versions of Windows, you do this by running the following command from within the command prompt:
    • ipconfig /flushdns
  • Visit the migrated version of your website by visiting www.example.com or http://example.com in your browser window.

Mac Operating Systems

  • Open the “Terminal” application.
  • Use the nano application, with sudo, to modify the /etc/hosts file. (You will be prompted for your password for sudo access.)
  sudo nano /etc/hosts

If it does not exist you can also try

  sudo nano /private/etc/hosts

Just as with the Windows steps, you can add additional lines to this file that will point requests for a particular domain to your new server’s IP address. Example:

  127.0.0.1 localhost
  67.222.1.2 example.com
  67.222.1.2 www.example.com
  • Once you make your changes, type [CTRL] + X to save the file.
  • One last step to clear your cache and make the new settings take place. You’ll need to flush DNS, and the instructions will vary depending on your version of MacOS:
    • El Capitan (10.11), Sierra (10.12), High Sierra (10.13), Mojave (10.14), and Catalina (10.15)
  sudo killall -HUP mDNSResponder
  • Yosemite (10.10)
  sudo discoveryutil udnsflushcaches
  • Lion (10.7), Mountain Lion (10.8), and Mavericks (10.9)
  sudo killall -HUP mDNSResponder
  • Snow Leopard (10.6)
  dscacheutil -flushcache

Video Tutorials