Knowledgebase Home / Preview websites before DNS propagation is complete by editing hosts file

Preview websites before DNS propagation is complete by editing hosts file

This guide will walk you through the steps included in editing the hosts file in your local computer to preview the website before updating the public DNS servers.

It is quite common for DNS propagation to take 24-48 hours to become active after the nameservers have been changed. During this time period, you won’t be sure if your website is loading using your newly updated DNS or the old one. However, we do have an option to bypass the DNS and load your website from the desired IP address by editing your hosts file on your local machine. The hosts file on your computer allows you to override the DNS entries and map the website to the desired IP address. This is really helpful during website migrations as you will be able to check if the website is working as expected with the new hosting provider.

Quick steps:

  • Open up the “hosts” file in your local computer according to the OS you are running.
  • Add the following lines in the “hosts” file by replacing the IP with your server IP and domain name with the actual domain name.
    192.0.43.10    example.com www.example.com
  • Save the “hosts” file and exit the text editor.

Editing the “hosts” file may differ with different operating systems that you are running on your local machine.

Editing Hosts File on Windows

  • Click Start
  • Search for Notepad, right-click on the icon and select Run as Administrator.
  • Within your text editor click File > Open and browse to the following location.
    C:\Windows\System32\drivers\etc\
  • Click on the hosts file and Open.
  • Once you added the IP address and domain name as mentioned in Quick Steps, save the file.

Editing Hosts File in Mac OS

  • Click on the “Finder” icon on the bottom of your screen.
  • Click Applications and then on Utilities
  • Click on the Terminal application and enter the following command.
    sudo nano /private/etc/hosts
  • Press on Enter to start editing the file. Move down to the bottom with arrow keys. Then insert the IP address and domain name as mentioned in Quick Steps.
  • Press CTRL+O which will ask if you want to write to the file. Then press enter. Close the terminal.

Editing Hosts File in Linux

  • Search for Terminal in applications
  • Enter the following command on terminal and press enter.
    sudo vi /etc/hosts
  • Once you enter the file, press “i” which will start editing the file.
  • Then insert the IP address and domain name as mentioned in Quick Steps.
  • Press on Esc key which will exit editing mode. Then enter “wq!” and press enter key which will save the changes.

Now you can load the website from your browser directly from the new server IP address you have mentioned in your “hosts” file

Note: Please make sure to clear your DNS cache after adding the entry. Also, make sure you have removed this entry once the DNS is correctly updated globally. You can use this guide for clearing the DNS cache.

Conclusion

Congratulations! You have learned how to edit the hosts file in your local computer to preview the website before updating the DNS


If the steps above listed in this article do not resolve your issue, please feel free to open a support ticket and we’d be happy to take a look.  

Ready for NVMe Hosting? And you thought SSD was fast...Get started today for $1.00 Promo code: 1dollar

Our Guiding Principles

  • Provide consistent, stable and reliable web hosting services.
  • Ensure rapid ticket response and quick resolutions to issues.
  • Never saturate or over-provision servers to ensure stability and speed for our customers.
  • Use only high quality enterprise-class hardware to ensure minimal downtime from hardware failures.
  • Provide clear pricing with no hidden fees or gotchas.