How to Edit Your Hosts File – Preview Site Before Updating DNS

Written on April 16, 2015. Updated on November 05, 2017

The hosts file on your computer allows you to override DNS and manually map hostnames (domains) to IP addresses. This can come in handy during migrations as you might want to see how your website looks on a different server, but perhaps the DNS hasn’t propagated yet. Kinsta provides clients with temporary URLs (sitename.kinsta.com), but this can’t mimic everything 100%. For example, a CDN is one feature that won’t work on a temporary URL unless you have manually configured it that way. So an easy way to preview your website and mimic it as close as possible before migrating or making DNS changes is to edit your hosts file.

There is also a free tool option for beginners, if you aren’t comfortable editing your hosts file.

edit hosts file

Preparing to Preview Your Website

Editing the hosts file on your computer essentially means you are faking the DNS on your computer. But before editing the file or using the free tool we recommend, there are two things you must do first.

1. Add Your Domain to Your Web Host

You first need to add your domain to your host. If you are a Kinsta client this can easily be done within MyKinsta. Simply click into Domains and add a primary domain. We also recommend adding the www or non-www version of your domain as well. This will instruct the Kinsta servers to resolve that domain to it’s assigned internal IP.

Add domain in MyKinsta

Add domain in MyKinsta

2. Find Your IP Address

You will also need to copy the IP address that is assigned to your site. If you are a Kinsta client, the IPv4 address can be found under the Info section within your site.

wordpress ipv4 address

IPv4 Address

Once you have completed the two steps above, you can proceed to the two different options below on how to preview your website before changing your DNS, this includes a free online tool or editing your hosts file.

Option 1 – Preview Website Without Editing Anything (Beginners)

If you are not comfortable editing your hosts file in option 2 below, there is a super easy way to preview your website with the free online hosts.cx tool.

Step 1

Simply browse to hosts.cx, input your IP address (which we showed you how to get above) and your domain name. It’s recommended you temporarily disable the following if they are running, as we have seen some encounter issues:

  • CDN (if you are running a plugin like CDN enabler temporarily deactivate this)
  • Typekit (comment this out or remove from your header if possible, otherwise your fonts might appear broken)

If you are unsure on how to do this you can ask your host. Or use the 2nd option below which is a good way to preview things without anything breaking.

Website previewer

Website previewer

Step 2

You will then get assigned a temporary URL which you can use to view your WordPress site before changing your DNS.

Website previewer

Website previewer

Step 3

You can browse to your temporary URL and click around to confirm everything works the way it should.

Preview website before DNS change

Preview website before DNS change

Option 2 – How to Edit Hosts File on Windows

Option 2 requires editing your hosts file. This will more closely replicate your live site before changing your DNS. An advantage of doing this over the temporary URL above is that you don’t have to worry about disabling your CDN or web fonts. Follow the steps below to edit your hosts file on Windows.

Step 1

The hosts file typically requires additional access. So the first step is to open up your text editor as an administrator. Simply click on your start menu, search for your text editor, right-click on it and select “Run as administrator.” This can be done in any text editor such as Notepad, Notepad++, Atom, etc. We are using Sublime in our example below.

open text editor as administrator

Open text editor as administrator

Step 2

Within your text editor click File > Open and browse to the following location:

C:\Windows\System32\drivers\etc\

Step 3

Click on the hosts file and “Open.”

open hosts file

Open hosts file

Step 4

At the very bottom of the file insert your IPv4 address (which you obtained above) and your domain name (in our example we are using wpdev.ink). If you want to test redirects, you can also add the www or non-www version as well. Here is an example of what we added to our hosts file.

 192.168.1.2 wpdev.ink
 192.168.1.2 www.wpdev.ink

Once you add the above, save the file.

edit your hosts file windows

Edit your hosts file in Windows

You can then launch your browser and navigate to the domain you inserted. It will then show up as it would on Kinsta’s servers. You can test things such as logging into your WordPress admin dashboard, click around the site, etc. Once you are fully satisfied, you can remove the DNS information from your hosts file. You can then actually point your DNS to Kinsta’s servers with your domain registrar or 3rd party DNS provider.

Option 3 – How to Edit Hosts File on Mac

Follow the steps below to edit your hosts file on Mac.

Step 1

Click on the “Finder” icon on the bottom of your screen. Click on Applications and then on Utilities.

Open Utilities on MAC

Open Utilities on MAC

Step 2

Click on the “Terminal” application and enter in the following and press Enter (you will most likely be prompted for your administrator password as well).

sudo nano /private/etc/hosts
mac terminal sudo nano hosts

Mac terminal browse to hosts file

Step 3

Press Enter again to begin editing the file. Move down to the bottom with the arrows on your keyboard. Then insert your IPv4 address (which you obtained above) and your domain name (in our example we are using wpdev.ink). If you want to test redirects, you can also add the www or non-www version as well. Here is an example of what we added to our hosts file.

192.168.1.2 wpdev.ink
192.168.1.2 www.wpdev.ink

Then press CTRL + O which will ask you if you want to write to the file. Then press Enter. You should see a wrote confirmation at the bottom of the screen. Then close the terminal.

edit hosts file on mac

Edit hosts file on Mac

You can then launch your browser and navigate to the domain you inserted. It will then show up as it would on Kinsta’s servers. You can test things such as logging into your WordPress admin dashboard, click around the site, etc. Once you are fully satisfied, you can remove the DNS information from your hosts file. You can then actually point your DNS to Kinsta’s servers with your domain registrar or 3rd party DNS provider.

Was this article helpful?
No, or there was something off

Hand-picked related articles

Send this to a friend