How to Use the Hosts File to Preview a Migrated Site

How to edit your computer's hosts file to preview a website on a new server before changing public DNS records.

· Updated · 2,159 views

The hosts file lets your computer override DNS for specific domains. By pointing a domain to your new server IP locally, you can preview a migrated site while the rest of the world still sees the old one.

Find Your Server IP

Your new cPanel account shows the shared server IP in its sidebar, or the migration team can provide it. You will map your domain to this address.

Edit the Hosts File

The file location depends on your operating system:

| OS | Path | |----|------| | Windows | C:\Windows\System32\drivers\etc\hosts | | macOS | /etc/hosts | | Linux | /etc/hosts |

Open it with administrator or root privileges, then add a line mapping the IP to your domain:

203.0.113.10   example.co.ke www.example.co.ke

Save the file. On Windows you may need to run your editor as Administrator; on macOS and Linux use sudo.

Preview the Site

  1. Close and reopen your browser, or clear its DNS cache.
  2. Visit your domain as normal.
  3. Your computer now loads the new server while public DNS is unchanged.

Clean Up When Done

  1. Remove or comment out the line once testing is complete.
  2. Save the file again so your computer returns to public DNS.
  3. If the old version still loads, flush your system DNS cache.

This trick affects only your machine, so it is safe to use at any point during a migration without any impact on live visitors. It is the most reliable way to verify a site before the real DNS switch.

Was this article helpful?

Your feedback helps us improve our documentation.

Still Need Help?

Our support team is available 24/7 to assist you.