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

Editing your hosts file is a great way to preview a website before updating the DNS. This is especially useful when you are making changes to a website and want to make sure everything looks and works correctly before making the changes live. In this guide, we will explain how to edit your hosts file and how to use it to preview a website before updating the DNS.

1. Open the hosts file on your computer. This file is usually located in the C:\Windows\System32\drivers\etc folder.

2. Add the IP address of the website you want to preview and the domain name. For example, if you want to preview a website with the domain name example.com, you would add the following line to the hosts file:

127.0.0.1 example.com

3. Save the hosts file.

4. Flush your DNS cache. On Windows, you can do this by opening a command prompt and typing ipconfig /flushdns.

5. Open your web browser and type in the domain name of the website you want to preview. You should now be able to view the website as if it were live.
[ad_1]

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 does provide a temporary URL (sitename.kinsta.cloud). However, 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.

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 its assigned internal IP.

Primary domain in MyKinsta.
Primary domain in MyKinsta.

2. Find Your SFTP/SSH IP Address

You will also need to copy the SFTP/SSH IP address that is assigned to your site. If you are a Kinsta client, this IP address can be found under the “SFTP/SSH” section within your site.

SFTP/SSH Address in MyKinsta.
SFTP/SSH Address in MyKinsta.

Once you have completed the two steps above, you can proceed to the three 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 or 3 below, there is a super easy way to preview your website with the free online SkipDNS tool.

Important: SkipDNS is an external service designed only to help you preview the look of your website before changing your DNS. It should not be used for evaluating the speed or performance of your site. For this, you should use one of the options further below, or your temporary URL. The best way to see the full performance of your site is to point your DNS to Kinsta and then use a website speed test tool.

Step 1

Simply browse to skipdns.link and input your domain name and IP address (which we showed you how to get above).

Depending on whether or not you have an SSL certificate already installed, you might need to also enable the “Flexible SSL” option.

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)
  • Adobe Fonts (comment this out or remove from your header if possible, otherwise your fonts might appear broken)

If you are unsure of 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.

SkipDNS
SkipDNS

Step 2

A preview is then created. Click on “Check it.”

SkipDNS preview created
SkipDNS preview created

Step 3

You will then get assigned a temporary URL which you can use to view your WordPress site before changing your DNS. 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.

If you want a quick and easy method, you can use a free application like Hosts File Editor. This allows you to manage multiple entries at a time, as well as filter and sort them.

Otherwise, you can follow the steps below to edit your hosts file on Windows manually.

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 IP 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 manually.

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 IP 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.


Get all your applications, databases and WordPress sites online and under one roof. Our feature-packed, high-performance cloud platform includes:

  • Easy setup and management in the MyKinsta dashboard
  • 24/7 expert support
  • The best Google Cloud Platform hardware and network, powered by Kubernetes for maximum scalability
  • An enterprise-level Cloudflare integration for speed and security
  • Global audience reach with up to 35 data centers and 275 PoPs worldwide

Get started with a free trial of our Application Hosting or Database Hosting. Explore our plans or talk to sales to find your best fit.

[ad_2]

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

GSTIN is 03EGRPS4248R1ZD.

Contact
Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00