Guide Migrations & Transfers

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.

Updated 6 min read Beginner

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

  1. 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.

  2. 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.

  3. 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).

  4. 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:

SystemCommand
Windowsipconfig /flushdns in Command Prompt
macOSsudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
LinuxVaries 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.

Remove the entry once DNS has genuinely switched

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 a www and non-www line 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.

We test every migration this way

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