Knowledgebase

How to access new website using hosts file before updating DNS

 

We can test the newly migrated website prior to updating the DNS and check whether it is loading as expected by editing the hosts file on our local machine. 

The 'hosts' file location varies as per the OS. 

Below is the guidelines on how to edit the hosts file on Windows, Mac and Linux.

When we add the entry in the hosts file, we tell our machine to resolve the website to the respective IP before resolving to the DNS so that the web request goes to that specified IP.

This allows you to access the website normally, but have it load from a different server.

The entry should be added with below syntax

10.10.10.10 mywebsite.com www.mywebsite.com

Once the changes are made and the line is added, you can simply browse the website normally you access for e.g. http://domain.com

Once the website is tested, please do not forget to remove the entry from the hosts file

 

Windows

  1. Locate 'notepad' in the start menu



 2. Right click on notepad and select 'Run as Administrator'

           

   3. Click 'File' and then 'Open'
   4. Navigate to the following location:      'C:\Windows\System32\drivers\etc'

  • First navigate to your C: drive
  • Then navigate to the Windows folder
  • Then find the System32 folder
  • Then select drivers
  • Then locate the etc folder

     
   5. Change 'Text Documents (*.txt)' to 'All Files'
   6. Select 'hosts' and click 'Open'
   7. Type in the details as required

Ensure that you use the details provided in the migration email for this section.

   8. When done save the file by clicking on 'File' and then 'Save'

 

Mac

  1. Open Finder



  2. Select 'Applications', and then 'Utilities'



    You can also hold down the 'Control' and 'Shift' keys and press 'U

  3. Open 'terminal'



  4. Type in 'sudo nano /private/etc/hosts'
    (If this file is blank use 'sudo nano /etc/hosts')



  5. Type in your computer's password and press 'Enter'
    The screen will remain blank while doing this
  6. Use the 'down arrow' key to navigate to the end of the file



  7. Type in the details as required
  8. Hold down the 'Control' key and press 'O' to save, then press 'Enter'
  9. Hold down the 'Control' key and press 'X' to exit nano
  10. You can now exit terminal

 

Linux

  1. Open a teminal window
  2. Type in 'sudo vi /etc/hosts'
  3. Type in your computer's password and press 'Enter'
    The screen will remain blank while doing this
  4. Use either the down arrow or 'j' to navigate to the bottom of the file
  5. Press 'i' to enter insert mode
  6. Type in the details as required
  7. When done press 'Esc' to exit insert mode
  8. To close the file press either 'Z' twice or type the following ':wq'
  9. You can now exit terminal
 
 Once the hosts file updated, run below command in command prompt to check whether the website is pointing to the new IP:

ping domain.com

If it response from the new IP 10.10.10.10, it means hosts file changes are reflected. Now you can browse the site in the browse. 

As stated earlier, once the website is tested, remove the entry from hosts file.

  • 6 Users Found This Useful
Was this answer helpful?