Test a website before changing DNS: hosts file vs a preview link
Updated 6 min readBy the DNSPeek team
You can test a site on a new server before DNS changes in two ways: map the domain to the new IP in your computer’s hosts file, or open a preview link that requests the site from the new IP for you. The hosts file is exact and free but works only on the machine you edit, while a preview link works on any device and can be shared with a client. Many teams use both: a preview link for review and sign-off, the hosts file for a final check of things a proxy changes.
Why you can’t just open the new server’s IP
A web server often hosts many sites on one IP address and picks the site by the domain name the browser sends. Open http://203.0.113.10/ and you usually get a default page, a different site, or a certificate warning. To see your site, the request has to go to the new IP while still saying “I want example.com”. Both methods below do exactly that.
Method 1: the hosts file
The hosts file is a small text file that your operating system reads before asking DNS. A line in it overrides DNS for that name on that computer:
# Windows: C:\Windows\System32\drivers\etc\hosts (edit as Administrator)
# macOS / Linux: /etc/hosts (edit with sudo)
203.0.113.10 example.com
203.0.113.10 www.example.comThe hosts file generator writes these lines for your domain and IP, with steps for Windows, macOS and Linux. It runs entirely in your browser.
- Exact. The browser talks to the new server directly, with your real domain, its own certificate and headers. Nothing in between changes the response.
- Works for anything. Private IPs, intranet servers, every subdomain and every port.
- One machine only. Each teammate or client has to edit their own file, with admin rights.
- Hard on phones. iOS and Android have no hosts file you can easily edit.
- Easy to forget. Browsers and the OS cache DNS, so it is easy to look at the wrong server without noticing, and an entry left behind breaks the site for you after the migration.
Method 2: a preview link
A preview link is an ordinary HTTPS address that always shows your site from the new server. With DNSPeek you enter the domain and the new IP and get a link. When someone opens it, DNSPeek connects to that IP, asks for your real domain, and sends the answer back. Links, redirects and cookies that point at your domain are rewritten to the preview address, so people can click through, submit forms and sign in without leaving the preview.
- Any device. Phones, tablets and a client’s laptop open it like any other link. A QR code helps on phones.
- Shareable and controllable. Protect it with a password, set an expiry date, or switch it off.
- Nothing to undo. No system files edited, nothing left behind after the switch.
- Checks on top. QA crawls, side-by-side compares and DNS alerts run on the same link.
A proxy changes a few things by design. To make pages work on the preview address, DNSPeek removes the Strict-Transport-Security, Content-Security-Policy and X-Frame-Options headers and adjusts cookie flags. Sign in with Google or SSO and hosted payment pages return to your real domain, which still points at the old server. Firewalls on the new server may challenge proxy traffic. Previews only reach public IPs. The full list is on what previews can’t do.
Side by side
| Item | Hosts file | Preview link |
|---|---|---|
| Who can see the new site | Only the person who edited the file | Anyone you send the link to |
| Phones and tablets | Impractical | Yes |
| Setup | Admin rights, a text editor, cache flushing | Domain and IP in a form |
| Response exactly as after the switch | Yes | Nearly: security headers and cookie flags are adjusted |
| Private or internal IPs | Yes | No, public IPs only |
| Third-party sign-in and payments | Work as after the switch | Return to the live domain |
| Cleanup after the migration | Remove the lines by hand | Disable the link or let it expire |
| Cost | Free | Free plan available |
Which one to use when
- Developer checking their own work on a private server: hosts file.
- Client, manager or colleague needs to see it: preview link. Nobody outside IT should be asked to edit system files.
- Mobile layout and real-device checks: preview link.
- Final check of HSTS, CSP and sign-in flows before the switch: hosts file on your own machine.
- Agency or host sending many previews: preview links, ideally prefilled from your own system with a
/new?domain=…&ip=…link or created through the API.
Whichever you choose, the rest of the move is the same: see the website migration checklist. More on the trade-off: the hosts file alternative, and how DNSPeek compares with SkipDNS, Peek-DNS and hosts.click.
Test the new server either way
Step 1: Find the new server’s public IP
Take it from the new host’s welcome email or control panel, not from a DNS lookup of your domain, which returns the old server. See Find your server IP.
Step 2: Confirm the server answers for your domain
Run
curl -skI --resolve example.com:443:203.0.113.10 https://example.com/. A 200 or a redirect to your own domain is a good sign; a default page means the site is not set up there yet.Step 3: Create a preview link to share
Enter the domain and the IP on the new preview form. Open the link, click through the site and send it to anyone who needs to review it.
Step 4: Add a hosts entry for your own final check
Generate the lines with the hosts file generator, add them, flush the DNS cache and check the parts a proxy changes, such as sign-in and security headers.
Step 5: Remove the hosts entry after the switch
Delete the lines once DNS points at the new server, so your computer follows public DNS again.
What to check, whichever method you use
Pre-switch test
- The site, not a default page, loads from the new IP
- Home page, key pages and navigation work
- Forms submit and confirmation emails arrive
- Login to the CMS or admin area works
- Images, fonts and scripts load without errors
- Mobile layout checked on a real phone
- HTTPS plan clear: certificate now or right after the switch
- Hosts file entries removed after the switch
Frequently asked questions
Is a preview link safe to send to a client?
Yes, with a little care. Anyone with the link can open it, so set a password for anything sensitive and switch the link off when the migration is done. Remember that actions on the preview, such as orders or form submissions, really happen on the new server.
Can I edit the hosts file on an iPhone or Android phone?
Not without jailbreaking or rooting the device, or routing it through a VPN or proxy app that rewrites DNS. That is why preview links are the practical way to check a new server on a phone.
Why do I still see the old site after editing the hosts file?
The browser or operating system cached the old DNS answer, or the browser uses DNS over HTTPS and ignores the hosts file. Flush the DNS cache, restart the browser, and check that both the bare domain and www are in the file.
Does a preview link show exactly what visitors will see?
Almost. The pages, files and redirects come from the new server, but the proxy removes some security headers and adjusts cookies so the preview works on its own address, and third-party sign-in returns to the live domain. Check those on the real domain after the switch.
Do I need an account to create a preview link?
No. You can create a guest preview link on DNSPeek with just a domain and an IP. Guest links are limited; a free account adds a password, spaces and a QA report.