Over the past few days, I’ve ended up migrating my site to a NameHero VPS. And in all this, I’ve found the absolute best way to test your site on the new server before you change your DNS records.
Making the final switch of your DNS records is an act of faith. You have to be absolutely sure that your site is working properly on the new host before you leap. Otherwise, your visitors will experience downtime, and you’ll have to revert your DNS changes, which can take a lot of time to propagate, leading to an absolute mess.
But how do you test it? After all, the internal links of your site will all point to its own domain – not to an IP address. So even if your web host has given you a temporary URL to which you can point your web browser and see your homepage, it’s not going to work the moment you click a link on it.
What we’re looking for, is a system that will resolve your site’s name to the new IP address – but only for you and no one else. There are a few online services that accomplish this, but nothing beats modifying your system’s hosts file.
Here’s how you do it.
Step 1: Open Notepad as an Administrator
The file we’ll be modifying requires escalated privileges to edit. So go to your start menu on Windows, and right-click Notepad, and select “Run as administrator” like this:
This way when you make your changes, you won’t get an “Access Denied” message. If you’re using another editor program, then of course search for that instead.
Step 2: Open the Hosts File
Using your file editor that you just opened in admin mode, open the following location on Windows:
On Mac, it should be here:
This should open up the file in your note program for editing.
Step 3: Add the New IP Address (Temporarily)
In the next stage, add one line in this format:
[new IP address] [domain.com] [www.domain.com]
For example, when I migrated my site WP-Tweaks to NameHero, I used the following entry:
126.96.36.1997 wp-tweaks.com www.wp-tweaks.com
Where “188.8.131.527” was the IP address of my new VPS server. This ensures that both wp-tweaks.com and www.wp-tweaks.com resolve to my new NameHero IP address on my local machine.
Step 4: Clearing your Browser Caches
Browsers store the results of their DNS lookups, so they won’t immediately see the change in your hosts file. You need to manually clear the DNS cache. Here’ how you do it.
Clearing the DNS Cache on Chrome
With Chrome, type the following address into the URL bar:
From here, you can clear the host cache by clicking the button as shown here:
This should clear out your DNS cache on Chrome.
Clearing the DNS Cache on Firefox
To clear the DNS cache on Firefox, navigate to:
And now just click “Clear DNS Cache” like this:
After this, you can even click the “DNS Lookup” tab and check that it’s showing the new IP address.
Step 5: Browse the Site on your New Server
Now when you navigate to your site via the URL, it should point to the new server. From here, you can do everything you would normally do. Literally everything. You can go to the dashboard, check backups. In short, you have a perfect way of making sure that your website works flawlessly. I’ve written before about the best way to migrate a WordPress site to a new host using the All-in-One WP migration plugin.
Step 6: Don’t Forget to Change Back your hosts File Afterward!
Once you’re all ready to party, revert the changes to your hosts file and flush the caches on your browser. Now you’re ready to finally change the DNS entries. Good luck!
I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!