How to preview a site with your hosts file
One edit on your own computer lets you load the new server privately while every other visitor keeps seeing the old one.
The hosts file is a small text file that exists on every computer, and it does one job: it lets your machine override DNS for specific domains. Normally your computer asks the internet's DNS system where yourdomain.com lives. A hosts file entry answers that question locally instead, before the request ever reaches DNS — which means you can point your own computer at a new server while the domain's real DNS records, seen by everyone else, still point at the old one.
This is the single most useful trick in a website migration. It lets you test the new server thoroughly, in private, with zero risk to anyone else, before you commit to the DNS switch.
What you need first
The IP address of the new server. This is shown in your new hosting control panel or in the welcome email you were sent when the account was set up — always use the value shown there rather than a number copied from an old guide or a previous project, since it will be specific to your account.
Editing the hosts file on Windows
- Open Notepad as administrator
Search for Notepad in the Start menu, right-click it, and choose "Run as administrator". The hosts file cannot be saved without this.
- Open the file
In Notepad, go to File > Open and navigate to
C:\Windows\System32\drivers\etc\hosts. You may need to change the file type filter to "All Files" to see it, since it has no file extension. - Add a new line at the end
On its own line, type the new server's IP address, then a space, then the domain:
203.0.113.10 yourdomain.com(using the IP address from your own control panel, not this example). - Save the file
File > Save. If Notepad refuses to save, it was not opened as administrator — close it and start again from step 1.
Editing the hosts file on macOS or Linux
The file lives at /etc/hosts on both. Open a terminal and run:
sudo nano /etc/hosts
Add a line at the end in the same format as above, then save (Ctrl+O, then Enter, then Ctrl+X to exit nano).
Flush your DNS cache so the change takes effect
Your computer keeps its own short-term memory of DNS lookups, separate from the hosts file. Clear it so the new entry is picked up immediately rather than after it happens to expire on its own:
| System | Command |
|---|---|
| Windows | ipconfig /flushdns in Command Prompt |
| macOS | sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder |
| Linux | Varies by distribution — restarting the network service is usually enough |
Then fully close your browser and reopen it, since browsers also keep their own DNS cache on top of the operating system's.
Testing the site
Browse to the domain as normal. If the hosts file entry has taken effect, you are now looking at the new server, while everyone else in the world is still looking at the old one. This is the point to work through the full pre-launch testing checklist: every page, every form, the admin login, and checkout if the site is a store.
A hosts file entry does not expire on its own. If you leave it in place after switching DNS for real, your computer will keep using it forever — meaning you will never see a future DNS change take effect, and if you ever revert or move host again, you will be the one person who cannot tell whether it worked. Delete the line once the migration is confirmed and settled.
If the site does not load, or still shows the old version
- Double-check the IP address matches exactly what your new host's control panel shows.
- Confirm the hosts file actually saved — reopen it and check the line is there.
- Try a private or incognito browser window, which often bypasses cached DNS lookups a normal window is still using.
- Confirm there is no typo in the domain name, including matching whether it needs a
www.prefix or not — you may need both awwwand non-wwwline depending on how the site is configured.
Once testing is complete
With the new server confirmed working, you can move on to the real DNS switch, covered in full in our main migration guide. Lower the TTL a day ahead if you have not already — see how DNS propagation actually works — then switch, and remove the hosts file entry once you are confident it has taken effect for everyone else too.
Website migration is included free with our hosting plans, and previewing on the new server before anything switches is a standard part of how we run it. Get in touch if you would like us to handle the whole move.
Frequently asked questions
Will other people see the new site while I have this set up?
No. A hosts file entry only affects the computer it is edited on. Everyone else continues to be sent to whatever the domain's real DNS records currently point at, which is why this is a safe way to test before switching for real.
Why does the site still show the old version after I edit the file?
Almost always a caching issue on your own machine. Flush your DNS cache, fully close and reopen your browser, and try a private/incognito window, which bypasses more caches than a normal one.
Related reading
Copy first, test second, switch DNS last. Get that order right and a migration is boring — which is exactly what you want.
How to test a migrated site before going liveThe whole point of testing before DNS switches is that mistakes are free to find and free to fix while nobody else can see them.
How to migrate a website with no downtimeZero downtime is not a special technique — it is what happens automatically when the steps are done in the right order.
How long does DNS propagation take?Usually a few hours, occasionally up to 48 — and your own browser is almost always the last thing on earth to catch up.