Editing your DNS Hosts File imprimir

  • 1

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 server. 

Once our Migration team has completed the validation of your site, they will notify you that it is time for you to edit your DNS Hosts File and begin testing. 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 that 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.

Linux

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

  3. less hosts
  4. 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)
  5. Edit your host file manually with vi, vim, or nano, or append the new entry directly from the command line. If your migration involves multiple IP addresses, you will have one line for each IP address, regardless of how many domain names share it.
    • To use vim, open a terminal and enter the command:
      sudo vim /etc/hosts
    • Enter your password if prompted. 
    • Move your cursor to the end of the hosts file using your arrow keys and enter the entry given to you by the Migration specialist. To save the file hit the escape key and type the following command:
      :wq
    • 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 
    • and enter your password.
  6. Before you exit the terminal, flush your 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. If your migration involves multiple IP addresses, you will have one line for each IP address, regardless of how many domain names share it.
  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 add the entry given to you by the Migration specialist:
      • 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
      • 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. Add the line your Migration specialist indicated you to use at the end of your hosts file, then save and close the file. If your migration involves multiple IP addresses, you will have one line for each IP address, regardless of how many domain names share it.
  6. 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 DNS Cache.

Note:

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.

Note:

QiQ 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.
 

Esta resposta lhe foi útil?

« Retornar