How-to · WordPress

Test a migrated site with the hosts file before changing DNS

At the end you will have viewed and tested the site on the new server under its real domain name from your own computer, while everyone else still sees the old server, and then removed the override.

Updated 8 steps2 official sources
Before you start

What you need before step 1

Applies to: Windows 10, Windows 11 and Windows Server; macOS. Works for WordPress and any other website or web app

Admin roles you need

  • Windows: a local administrator account (Notepad must run as administrator to save the hosts file)
  • macOS: an administrator account (sudo asks for your sign-in password)

Licences

None needed.

Also have ready

  • The public IP address of the new server (from your new host's control panel)
  • The site already copied to the new server and configured to answer for your domain
  • Every hostname you want to test, for example contoso.com and www.contoso.com
SiteGround web hosting
Step by step

8 steps

  1. 1

    Windows: open the hosts file as administrator

    Where: Windows: Start > search Notepad > right-click Notepad > Run as administrator

    In Notepad select File > Open, go to C:\Windows\System32\drivers\etc, change the file type filter from Text Documents to All Files, and open hosts. Alternatively, in an administrator Command Prompt type the two commands below, as Microsoft documents.

    cd %windir%\System32\Drivers\Etc
    notepad hosts
    You should see: The hosts file opens in Notepad. It usually contains only comment lines starting with #.
  2. 2

    Windows: add the entries and save

    Where: Notepad (running as administrator)

    At the bottom of the file add one line per hostname: the new server IP address, a space or tab, then the hostname. Save with File > Save (Ctrl+S). Keep the file name hosts with no extension.

    203.0.113.10    contoso.com
    203.0.113.10    www.contoso.com
    You should see: Notepad saves without an "Access denied" or "Save As" prompt.
  3. 3

    Windows: flush the DNS cache

    Where: Command Prompt (Start > search cmd > Run as administrator)

    Microsoft says ipconfig /flushdns reloads the hosts file without restarting the computer.

    ipconfig /flushdns
    You should see: Successfully flushed the DNS Resolver Cache.
  4. 4

    macOS: edit /etc/hosts with sudo

    Where: Mac: Finder > Applications > Utilities > Terminal

    Type the command below and press Return, then enter your Mac sign-in password (nothing appears as you type). Use the arrow keys to move to the end of the file and add the lines shown. Press Control-O then Return to save, and Control-X to exit nano.

    sudo nano /private/etc/hosts
    
    203.0.113.10    contoso.com
    203.0.113.10    www.contoso.com
    You should see: nano shows "Wrote N lines" after Control-O and returns you to the Terminal prompt after Control-X.
  5. 5

    macOS: make the change take effect

    Where: Mac

    Apple's own hosts file procedure finishes by restarting the Mac. Restart (Apple menu > Restart) so cached lookups for the domain are cleared, then reopen your browser.

    You should see: After restarting, the Mac resolves the domain using your hosts entry.
  6. 6

    Confirm your computer resolves to the new server

    Where: Command Prompt (Windows) or Terminal (macOS)

    Ping the domain and check the address in the reply. On Windows add -4 to force IPv4. (The server may not answer pings; the address shown is what matters.)

    ping -4 contoso.com
    ping -c 4 contoso.com
    You should see: The reply shows the new server IP address, 203.0.113.10 in this example.
  7. 7

    Test the site

    Where: A private or incognito browser window

    Open the site, log in to the admin area, click through key pages, submit a test form and check images and HTTPS. If the browser warns about the certificate, the new host may only be able to issue it after DNS points to it. Note any problem and fix it on the new server before changing DNS.

    You should see: The site loads from the new server and behaves like the old one.
  8. 8

    Remove the entries when you are done

    Where: Notepad as administrator (Windows) or sudo nano /private/etc/hosts (macOS)

    Delete the lines you added (or put # at the start of each), save, then run ipconfig /flushdns on Windows or restart the Mac. Do this before or straight after the DNS change, otherwise your computer will keep using the override.

    ipconfig /flushdns
    You should see: ping contoso.com returns the address that public DNS gives.
From experience

Expert tips

Test without editing the hosts file

For a quick check, curl -I --resolve contoso.com:443:203.0.113.10 https://contoso.com/ sends the request to the new server with the real host name, for one command only. It is ideal for checking redirects, headers and certificates on several sites.

Confirm which server you are really on

In the browser's developer tools, open the Network tab, reload and check the Remote Address of the page request. It should show the new server's IP. Browsers can keep connections and their own DNS cache open, so close all windows or use a private window after editing the file.

Expect certificate issues until DNS moves

If the new server does not yet have a certificate for the domain, you will see a warning. Certificate authorities validate against public DNS, not your hosts file, so HTTP-based certificate issuing on the new server usually works only after cutover. Ask the host about DNS validation or a pre-issued certificate if you need HTTPS before then.

Disable entries with # instead of deleting them

Put # at the start of a line to switch it off without losing it, as Apple's instructions do. Run ipconfig /flushdns on Windows afterwards; Microsoft notes it reloads the hosts file without a restart.

Test the things users actually do

Beyond the home page, check sign-in, the contact form, search, checkout and any page that calls an outside service. Forms that send mail or payment callbacks may run on the new server while you test, so use test data.

Check it worked

How to confirm it worked

  • While testing: ping -4 contoso.com (Windows) or ping -c 4 contoso.com (macOS) shows the new server IP.

  • After removing the entries: the hosts file contains only its original lines, and ping shows the address from public DNS.

Undo

How to reverse it

Rollback:

Delete the lines you added to the hosts file, save it, and flush the DNS cache (Windows) or restart (macOS). Nothing on the server or in public DNS changes, so other people are never affected.

Troubleshooting

Errors you might see

Access is denied / You don't have permission to save in this location (Windows)

Cause: Notepad was not started with Run as administrator.

Fix: Close Notepad, right-click it and select Run as administrator, then open and save the hosts file again.

File saved as hosts.txt (Windows)

Cause: Notepad added a .txt extension.

Fix: In File Explorer turn on file name extensions, rename the file back to hosts, or save with the file type set to All Files.

Browser still shows the old site

Cause: The browser or system DNS cache still holds the old address, or the site redirects to a different hostname you did not add.

Fix: Run ipconfig /flushdns (Windows) or restart (macOS), use a private window, and add every hostname the site uses (with and without www).

Entry ignored when written with no space

Cause: The IP address and hostname must be separated.

Fix: Use a space or tab between the IP address and the hostname.

FAQ

Questions

Does editing my hosts file affect anyone else?

No. It only changes name lookups on the computer you edit.

Why do I need to add www and non-www separately?

Each line maps one hostname. If the site redirects from contoso.com to www.contoso.com and only one is listed, the redirect sends you to the old server.

Do I need the hosts file if my host gives me a temporary URL?

Not always, but a temporary URL can break WordPress links and HTTPS. The hosts file tests the site with its real domain.

Where is the hosts file on a Mac?

Apple's instructions edit /private/etc/hosts. The hosts manual page refers to it as /etc/hosts.

Sources

Official sources

Vendors change menus and requirements. Confirm on the source before you rely on a detail. Last checked 4 Nov 2026.