search ]

Testing Your Website On A New Server Before Changing DNS

When you’re moving to a new hosting server, the most important thing is to test your website before you point the domain to the new server. This will allow you to ensure a proper migration and verify that your site is functioning at 100% before you actually change the DNS.

DNS stands for Domain Name System. Here’s a post I wrote about what DNS is in-depth.

The instructions in this post involve editing the hosts file on your personal computer. Alternatively, you can use a third-party referral service that creates a proxy connection to the new server, such as SkipDNS.

Referring Using the hosts File on Your Personal Computer

The best way to test your website is to direct the domain to the IP of the new server through the hosts file on your computer. This action will save you from waiting for full DNS propagation, which can take quite some time.

However, note that this action will only be relevant for your personal computer. If someone else wants to access and test the site, they will also need to perform these actions of changing the hosts file.

Below you will find instructions for both macOS and Windows.

macOS Users

For macOS users, the location of the hosts file is:

/etc/hosts

macOS

Open the Terminal, and note that you need to make changes to this file as a superuser. To edit the hosts file using nano as a superuser, use the following command:

sudo nano /private/etc/hosts

Since you’re performing an action as a superuser, you’ll be prompted to enter your macOS user password. Enter the password and press Enter.

Add the following lines at the bottom of the hosts file:

SERVER_IP_HERE example.com
SERVER_IP_HERE www.example.com

Replace SERVER_IP_HERE with the IP address of the new server, and replace example.com with the domain name. It should look like this:

12.34.56.78 example.com
12.34.56.78 www.example.com

Once you’ve edited the hosts file, perform the following actions:

  • Press CMD-X on the keyboard.
  • Press Y to save the changes.
  • Press the ENTER key.

That’s it. If you now access the domain in your browser, the redirection to the server with the IP you entered in the hosts file will occur. After you’ve finished testing, remember to remove these lines from the hosts file so that when you make the DNS changes, you can access the domain and server normally.

Windows Users

For Windows users, the hosts file is located at:

C:WindowsSystem32driversetchosts

To edit the file:

  1. Search for Notepad in the Start menu, right-click it, and select Run as administrator.
  2. In Notepad, go to File > Open and navigate to the directory above.
  3. Change the file type filter to All Files so the hosts file is visible.
  4. Add the following lines at the bottom of the file:
SERVER_IP_HERE example.com
SERVER_IP_HERE www.example.com

Replace the values with your server IP and domain, then save the file (Ctrl + S) and close the editor.

Flushing the DNS Cache (If Needed)

If you still see the old site after editing the hosts file, your computer may be caching the previous DNS resolution. Flush the DNS cache to force a fresh lookup:

macOS

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Windows

ipconfig /flushdns

Flushing the cache ensures your computer loads the site from the new IP you entered in the hosts file.

You can also test your site on a new server using a temporary URL, but the hosts file method described in this post is more reliable since it uses your actual domain.

FAQs

Common questions about testing sites before DNS changes:

Will editing the hosts file affect other users or devices?
No. The hosts file change only applies to the specific computer where you made the edit. Other users, devices, and search engines will continue to see the site on the old server until you update the DNS records.
How long does DNS propagation take after I change the records?
DNS propagation typically takes between a few minutes and 48 hours, depending on your domain registrar, the TTL (Time to Live) value set on your DNS records, and the DNS resolvers used by your visitors. Lowering the TTL value a day or two before migration can speed up propagation.
What should I check on the new server before switching DNS?
Verify that all pages load correctly, images display properly, forms submit successfully, and the WordPress admin dashboard works. Check that SSL certificates are active, permalinks function without errors, and any caching or CDN configurations are in place. Test on both desktop and mobile.
Do I need to remove the hosts file entry after switching DNS?
Yes. Once DNS propagation is complete, remove the lines you added to the hosts file. If you leave them, your computer will always connect to the IP you specified, even if the server changes or goes offline in the future.
Can I test an SSL certificate using the hosts file method?
Yes. Since the hosts file redirects your domain to the new server's IP, your browser will attempt to load the site over HTTPS using the domain name. If the SSL certificate on the new server is properly configured for your domain, it will work. You may see a certificate warning if the certificate is not yet active.

Summary

Testing your WordPress site on a new server before changing DNS is a critical step to ensure a smooth migration. By editing the hosts file on your computer, you force your browser to load the site from the new server using your actual domain, without waiting for global DNS propagation.

The process works on both macOS and Windows. If changes do not take effect immediately, flush your DNS cache. Once you have verified that everything functions correctly on the new server, remove the hosts file entries and update your DNS records to complete the migration.

Join the Discussion
0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!

Savvy WordPress Development official logo