1. Blog
  2. Manuals

How to Test a Site on a New Server Before Changing DNS

How to Test a Site on a New Server Before Changing DNS

When you move a site to new hosting or a new server, you want to be sure everything works before sending visitors there. You do not need to change DNS for that: just tell your own computer that the domain lives at the new address. Everyone else keeps seeing the site on the old server.

How it works

Before asking a DNS server, the operating system checks the local hosts file. If it has an entry for the domain, the IP address from that entry is used. The change affects only your computer.

What you need

  • the IP address of the new server — it is in the access details email or the control panel;
  • administrator rights on your computer.

The hosts file entry

The format is the same on every system — the IP address, then the names separated by spaces:

203.0.113.10 example.com www.example.com

List both variants of the name, with and without www. The hosts file does not support wildcards such as *.example.com: each subdomain is added separately.

Windows

  1. Find Notepad in the Start menu, right-click it and choose Run as administrator.
  2. Open C:\Windows\System32\drivers\etc\hosts. Switch the file type filter to All Files in the open dialog.
  3. Add the line at the end of the file and save.

macOS and Linux

sudo nano /etc/hosts

Add the line at the end of the file, save (Ctrl+O, Enter) and exit (Ctrl+X).

Flush the DNS cache

To make the change take effect immediately, flush the cache.

Windows:

ipconfig /flushdns

macOS:

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Linux with systemd-resolved:

sudo resolvectl flush-caches

The browser keeps its own cache too, so open the site in a private window or restart the browser.

Make sure you are seeing the new server

Check which address the domain resolves to:

ping example.com

The reply should show the new server’s IP address. The most reliable method is to place a small marker file on the new server in advance, for example new.txt, and open example.com/new.txt — the old server does not have it.

Testing without editing hosts

For a quick check of the server response, use curl. The --resolve option substitutes the address for a single request only:

curl -I --resolve example.com:443:203.0.113.10 https://example.com/

The command prints the status code and headers. 200 means the site responds; 301 or 302 is a redirect whose target is in the Location header.

What to check on the new server

  • the home page and several inner pages;
  • logging in to the site’s admin area;
  • submitting forms and sending email;
  • image loading and search;
  • no errors in the web server log.

The SSL certificate on the new server may not be issued until DNS is switched, so the browser may show a warning — that is expected at this stage. Issue a Let’s Encrypt certificate after changing DNS.

After testing

Point the domain’s A record to the new IP address. DNS propagation takes from a few minutes to a day — during that time some visitors still reach the old server, so do not shut it down straight away. Files can be brought up to date with rsync right before the switch.