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
- Close and reopen your browser, or clear its DNS cache.
- Visit your domain as normal.
- Your computer now loads the new server while public DNS is unchanged.
Clean Up When Done
- Remove or comment out the line once testing is complete.
- Save the file again so your computer returns to public DNS.
- 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.