...Edit the DNS Hosts File

One of the most important parts of the migration process is testing. During this time, we ask the site owner to go through and carefully test pages, links and make sure that everything is working the way that it should before changing the DNS and making the site live on your new iThemes Hosting account. 

Your computer's hosts file is one of the most powerful tools available for you to view and test a site on the new server while your site is still available to the world on the other. By editing the hosts file, you can ensure that everything on the site works as expected before you update the DNS records and your site visitors won't be affected by any potential issues related to different server environments.

Editing your DNS Hosts File is a simple process. In most cases, you will need administrative privileges to edit the DNS host file. These instructions are specific to your operating system:

Warning: Do not remove or modify any existing local entries in your hosts file. You will only be adding a new line or lines at the bottom of the file for testing, then remove the lines once testing is completed.

Getting your IP

The first thing you will need to do is access your iThemes Hosting panel and get the IP address of your website. You will find that under Hosting > Site Information. You will want to copy this down to be used later on.

HostingIP.png

Linux

  1. Your host files are located in the etc directory. You can view them by using the command: 
    cd /etc
  2. Then type: 

    less hosts
  3. Your host files will appear. In this case, the first three entries are defaults used to configure the local network interface. Any custom entries will go at the bottom of this file.
    ##
    # Host Database
    #
    # localhost is used to configure the loopback interface
    # when the system is booting. Do not change this entry.
    ##
    127.0.0.1 localhost
    123.123.123.123 broadcasthost
    ::1 localhost 
    hosts (END)
  4. Edit your host file manually with vi, vim, or nano, or append the new entry directly from the command line. 
    1. To use vim, open a terminal and enter the command:
      sudo vim /etc/hosts
    2. Enter your password if prompted. 
    3. Move your cursor to the end of the hosts file using your arrow keys and enter the IP address and domain in this format using the IP address retrieved above and changing yournewdomain.com to be your actual domain:

      184.106.55.132 yournewdomain.com

    4. To edit the file, use the i key to insert text. To save the file hit the escape key and type the following command:
      :wq
      1. To append the entry to the existing file, you can use one command to substitute your server's IP address and domain name for the ones in this example:
        echo "1.1.1.1 test.com www.test.com | sudo tee -a /etc/hosts >/dev/null"
      2. and enter your password.
  5. Before you exit the terminal, Flushing Your Local DNS Cache so you don't have to log out and log back in for changes to take effect. The command can vary depending on your specific distribution and version.
    • Many Ubuntu and Debian-derived distributions use:
      sudo service dns-clean restart
    • Other Linux distributions using Name Service Caching Daemon may need to use:
      sudo service nscd restart, sudo systemctl restart nscd.service
      or: 
      nscd -l hosts

Mac OS X

  1. The host file is located at /private/etc/hosts for Mac OS. 
  2. Click on your Applications icon, then search for "Terminal." Click on the Terminal to launch the CLI.

    To edit the file manually:

    1. Enter the following command in Terminal:
      sudo nano /private/etc/hosts
    2. Enter the password when prompted and press Enter to authenticate and open the file
    3. To enter the IP address and domain in this format using the IP address retrieved above and changing yournewdomain.com to be your actual domain:
      • Use your arrow keys to navigate to the bottom of the file
      • Type in (or paste) the IP address and website name you intend to redirect in this format:

        184.106.55.132 yournewdomain.com
      • Press Control+O to save the file
      • Press Enter to overwrite the existing file
      • To exit, press Control+X

    To append the entry:

    1. In the command line, use the following command:
      echo "1.1.1.1 test.com www.test.com"; | sudo tee -a /private/etc/hosts >/dev/null
    2. When prompted, enter your password to complete the command.

Flush the DNS Cache so you don't have to log out and log back in for changes to take effect. You can use this command:

dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Windows

The hosts file is located at C:\Windows\System32\drivers\etc\hosts.

  1. First, open an elevated command prompt:
  2. In Windows 8 and higher, use the keyboard shortcut Windows key + x to access the Power Users menu, then select the Command Prompt (Admin).
  3. In previous Windows versions:
    • Type "command" into the search field at the bottom of the Start menu.
    • Right-click on the cmd.exe icon
    • Select Run as Administrator.
  4. Enter the following command:
    notepad C:\Windows\System32\drivers\etc\hosts
  5. Enter the IP address and domain in this format using the IP address retrieved above and changing yournewdomain.com to be your actual domain:
    184.106.55.132 yournewdomain.com
  6. Save and close the file
  7. The last step is to flush your DNS cache so you don't have to log out and log back in for the changes to go into effect. If you need help flushing your DNS cache, see our article Flushing Your Local DNS Cache.
    ipconfig /flushdns

Notice: When copying and pasting the DNS host file given to you by the Migration team, Windows 10 does allow for keyboard shortcuts. All other versions of Windows will need to use the right-click method of copy/paste. If you prefer, you also can locate Notepad, right-click its icon to select “Run as Administrator”, then open your hosts file (at C:\Windows\System32\drivers\etc) in Notepad. With this method, you will need to change “Text Documents (*.txt)” in Notepad’s file browser to “All files” to see the hosts file, and you still will need to open a command prompt to flush your DNS cache as described in Step 6.

If All Else Fails

There is a third-party website which will allow you to preview and test your website on a different IP address. Hosts.CX is a free web-based service that will help you test on a per-site basis.

Notice: iThemes Hosting has no affiliation with Hosts.CX and does not offer support for testing using the site.

When visiting https://hosts.cx, you will be asked to provide your server address and website name. Click the Get My Testing URL link and you will be provided with a shortened URL to open and test your site on the new server.

Warning: While this is a helpful tool, certain functions, such as CAPTCHA may not work as expected. Do not transmit any sensitive data such as login information or passwords while testing using this service.

Have more questions? Submit a request
Powered by Zendesk