DNS Hosts File Print

  • 0

One of the most powerful tools available to anyone working on their site during a migration is their computer’s “hosts” file. The hosts file is used to map domain names to IP addresses, and can be used as an alternative to DNS. It also allows you to specify the IP address to which a website resolves on your computer, regardless of what may be published in the site’s DNS zone file.

Why Edit Your Hosts File?

Modifying your hosts file lets you view and test a site on one server while the rest of the world continues to see the site on another. That makes it an essential tool when migrating your website. With this method, you’re able to ensure that:
everything on the site works as expected on the new server before you update the DNS records
your site’s visitors won’t be affected by any potential issues related to different server environments before you’ve had a chance to resolve them
It’s actually a very simple process. Let’s take a look at an example hosts file:

127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
123.123.123.123 thobson.com www.thobson.com

In this case, the first three entries are defaults used to configure the local network interface. You may have more or fewer such local entries in your hosts file; you don’t need to worry about them other than to note their presence. Any custom entries will go at the bottom of the file, and in this case, you can see that I have added a custom entry to the end of the file already:

123.123.123.123 thobson.com www.thobson.com

My custom entry specifies that any request made from my computer (via web browser or SSH, email, or FTP client) for thobson.com or www.thobson.com will be directed to the IP address I’ve specified: 123.123.123.123. You will add your own custom entry to the end of your file using the same format.
The line for your custom entry will consist of three elements:

  • the IP address of the server to which you want the domain name to resolve on your computer
  • a tab or space
  • the domain name(s) meant to resolve to the specified IP address

If you’re migrating to a Thobson Web server, your migration technician will supply you with the line to add; you will just copy and paste it into your hosts 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.

Note: 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, and then removing the lines you’ve added once testing is complete.

Step #1: Edit Your Hosts File

In Windows, the hosts file is located at: C:\Windows\System32\drivers\etc\hosts. You will need to edit the file with administrative privileges.

  1.  Click Windows button and type ‘Notepad’ in the search
  2. Right click on ‘Notepad’ and then ‘Run as Administrator’
  3. Choose ‘Yes’ on the User Account Control popup
  4. In Notepad, choose ‘File’ then ‘Open’
  5. Click the address bar at the top and paste C:\Windows\System32\drivers\etc\hosts – choose ‘Enter’
  6. Choose Notepad from the list and then OK
  7. Add the appropriate IP and hostname (give by the Migration team) at the end of your hosts’ file, select save and close the file
  8. Finally, you will want to flush your DNS cache so you don’t have to log out and back in for the changes to take effect:
    Open an elevated command prompt as above, and enter the following command:

 

ipconfig /flushdns

Step #2: View the Site on its New Server

At this point, your website should resolve on your computer from the IP address specified in your hosts file instead of the IP address specified in the site’s DNS record. If you’re not seeing the site on the new server, it could be because your browser is serving a cached version of the page. In that case, you can:

  • Manually clear your browser’s cache (typically Control+Shift+Delete or Command+Shift+Delete). For browser-specific instructions, see Clearing Your Browser Cache.
  • Use a private browsing window to view the site
  • View the site in another browser
  • Log out of your computer and then log back in

Step #3: Test the Site on its New Server

Now that you can see the site on its new server, you must thoroughly test it to determine whether everything works as expected. It is common to see some issues and error messages when testing a migrated site. There’s no cause for alarm — typically only minor adjustments to the server configuration, such as enabling an Apache module or adjusting a php directive, are needed to resolve them.

  • To ensure that all your site’s software, scripts, and plugins work correctly on the new server, be sure to:
  • Visit each link on your home page and ensure that it loads without error
  • If your site runs a CMS such as WordPress or Magento, log into the administrative area
  • If your site has a shopping cart, add an item and test your checkout process
  • Test any forms on the site
  • Create a post
  • Comment on a post
  • Upload a file

Should you notice any issues when performing the above tests:

 

  • Note the full URL of the page
  • Note the specific error message or problem
  • Provide that information to the person performing your migration. If Thobson is handling the migration, simply paste that information into your migration ticket to ensure that the proper adjustments are made as quickly as possible.

 


Was this answer helpful?

« Back