Guide Getting Started

How to preview your site before changing DNS

Two ways to check a site works before a domain change goes live, so the domain switch is the last step rather than the first.

Updated 6 min read Beginner

The best time to find a problem with a website is before its domain is pointing at it, not after. Changing DNS commits the live domain to whatever is currently sitting in your hosting account, and if something is broken, visitors see it too. Previewing the site first means the DNS change becomes the last step of the launch instead of the first thing you test with.

Method 1: a temporary server address

Most hosting accounts can be reached by a temporary address before any domain is connected, shown in your control panel or welcome email — something like a shared server hostname with your account's folder appended. Loading that address shows exactly what your site currently looks like on the server, independent of any domain or DNS setting.

Use the address from your own account

This address is specific to your hosting account and server. Always copy it from your own control panel or welcome email rather than guessing at a pattern — an address from a different account will simply show somebody else's site or an error.

This is the fastest option when it is available and needs no configuration on your part, but not every setup supports it cleanly, particularly for sites that check the requested domain name internally — some content management systems redirect based on the domain configured in their settings, which can undo the point of previewing altogether.

Method 2: edit your hosts file

A hosts file edit is the more reliable option, especially for WordPress and other systems that expect a specific domain. It works by telling your own computer — not the wider internet — to send requests for your domain straight to your hosting account's address, while everyone else's computer still sees wherever DNS currently points.

  1. Find your hosting account's IP address

    Shown in your control panel or welcome email. Copy it exactly.

  2. Open your computer's hosts file

    On Windows, this is C:\Windows\System32\drivers\etc\hosts, edited with a text editor run as administrator. On macOS or Linux, it is /etc/hosts, edited with sudo.

  3. Add a line pointing your domain at that address

    The format is the IP address, a space, then the domain: for example 203.0.113.10 yourdomain.com. Add a second line for www.yourdomain.com if you need that version too.

  4. Save the file and flush your DNS cache

    On Windows, ipconfig /flushdns in Command Prompt. On macOS, sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder.

  5. Load the domain in a browser

    It should now show the site sitting in your hosting account, even though public DNS for the domain has not changed at all.

Remove the entry once you are done

A hosts file entry overrides DNS permanently on that one computer until you delete it. Once you have gone live and pointed the domain properly, take the line back out — otherwise your own machine will keep showing an old version of the site if you ever move hosting again, long after everyone else sees the current one.

What to actually check while previewing

  • Every page loads without errors, not just the homepage.
  • Forms submit correctly, including anything that sends an email or writes to a database.
  • Images, styles and scripts all load rather than showing as broken links, which sometimes happens when a site references its old domain directly instead of a relative path.
  • Any SSL certificate is in place and working, so the site is not throwing a security warning the moment it goes live.

Troubleshooting: the preview is not showing what you expect

What you seeLikely causeWhat to do
The temporary address shows an error or a default page instead of your siteThe site is not installed in the folder the temporary address points to, or DNS on your account has not caught up with a very recent changeConfirm the site files are in the right folder in your control panel, and check the temporary address is copied exactly as shown
A hosts file entry has no effect at allThe DNS cache was not flushed after saving the file, or the file was not saved with administrator/root permissionsFlush the DNS cache and reopen the browser; confirm the hosts file save was not silently blocked by permissions
The site keeps redirecting to the live domainThe application stores its own domain internally and redirects any other request to itCheck the site's own settings for a hardcoded site URL, or preview using the temporary address instead if the platform supports it cleanly
Some pages work but others 404Permalink or routing rules tied to the live domain, or a caching layer still serving old resultsClear any site-level cache and check routing settings are not domain-specific
The browser still shows an old version after removing a hosts entryYour browser's own cache, not DNS or the hosts file, is serving a stored copyClear your browser cache — see the guide linked below

Letting someone else preview the site too

A hosts file entry only affects the one computer it was added to, which is fine for testing alone but a limitation the moment a client, colleague or designer needs to see the same preview. The temporary server address from Method 1 works for anyone, provided the site does not depend on checking its own domain internally. If it does, the practical options are either walking the other person through adding the same hosts file entry on their own machine, or waiting until DNS is pointed and reviewing the finished site live instead — both reasonable depending on how much of a hurry the review is in.

Once the preview looks right

With the site confirmed working, follow pointing a domain to your hosting to make the change public. Because you have already tested the site itself, the only thing left to watch is DNS spreading across the internet — which is a waiting problem, not a debugging one.

If a browser is still showing an old version of the site after you remove a hosts file entry or after DNS has changed, clear your browser's cache before assuming something is wrong — see clearing your browser cache.

Frequently asked questions

Can I preview a site on my phone before DNS changes?

Not with a hosts file edit in most cases, since editing the system hosts file on a phone generally needs extra software or a jailbroken or rooted device. The temporary server address is the practical option for mobile preview, provided the site does not check the requested domain internally. If it does, testing on a computer with a hosts file entry is the more reliable route.

Why does my site redirect to the live domain even with a hosts file entry?

Some content management systems store the site's domain in their own configuration and redirect any other request to it, regardless of what your browser thinks it is connecting to. A hosts file entry controls where your computer sends the request, not what the application does once it receives it, so this kind of redirect will override your preview.

Do I need to tell my host I am previewing a site this way?

No. Both methods only involve your own computer and settings that are already available to you — the temporary address is provided for exactly this purpose, and a hosts file edit happens entirely on your own machine.

Related reading