How To Edit Hosts File To Preview Your Site

Table of Contents

When you migrate to a new host or change your domain’s nameserver settings, it takes time for these settings to take effect. One of the reasons is the time required for DNS propagation. You cannot access your site using your domain name until DNS propagation is complete. You can preview your website even before DNS propagation is complete by editing the host’s file on your local computer. This article will show you how to edit the host file to preview your site. 

 

How To Edit Hosts File

 

The host file is a plain text file found in computers running on Windows, OS X, etc. It maps domain names to specific IP addresses. In this method, we map the IP address we know to our domain name so we can preview the website. 

 

You will need administrator access to edit the host’s file. Editing is pretty simple, as you must insert a line of text at the end of the host’s file. 

 

Edit Hosts File Windows

Follow these steps to edit the “hosts” file in Windows. 

 

Step 1: Search “Notepad” in Windows Search, Right-click on the “Notepad” icon, and select Run as Administrator

 

notepad-run-as-administrator  Edit Hosts File

 

 

Step 2: Click on “File>>Open”. Browse the following location:

 

C:WindowsSystem32driversetc

 

Step 3: Select the etc folder

 

Step 4: To see the host file, Change the file type from *.txt to All Files

 

hosts-file-display  Edit Hosts File

 

Step 5: Select the “hosts” file and open it

 

Step 6: Go to the last line, Add the server IP address, your domain name, and its www version

 

Edit Hosts File

 

Step 7: Save the file 

 

Step 8:  Flush DNS Cache

 

A) Open “Run” (Windows+R). Type “cmd” and click ok. This will open the command prompt.

 

Clear DNS Cache Run cmd Edit Hosts File

 

B) In the command prompt, run the following command:

 

ipconfig /flushdns
clear dns cache windows Edit Hosts File

 

clear dns cache windows success Edit Hosts File

 

C)Hit Enter. You will get a success message once the DNS cache is clear.

 

Step 9: Open your browser, enter the website’s address and explore your site. 

 

Edit Hosts File Mac

 

Step 1: Open the Terminal Application

 

Step 2: In the Terminal window type the following command: 

 

sudo nano /private/etc/hosts

Step 3: If prompted, enter the password to open the “hosts” file

 

mac hosts file Edit Hosts File

 

Step 4: Go to the last line, Add the server IP address, your domain name, and its www version

 

mac hosts file update Edit Hosts File

 

Step 5: Press Ctrl+O to save the Hosts file

 

Step6: Flush the DNS Cache

 

Enter the following command in the Terminal:

 

sudo killall -HUP mDNSResponder; sleep 2; 

 

Step 7: Open your browser, enter the website’s address and explore your site.

 


You now know how to edit the host file on Windows and Mac. Editing hosts file lets you preview your site on your local machine. Let us know if you find this method useful. If you have any doubts, please reach out to us in the comments.

 

Fully Managed WordPress Hosting

Nestify’s AWS powered dedicated CPU servers keep your sites fast, secure, and always up to date.

Want faster WordPress?

WordPress Speed Optimization

Try our AWS powered WordPress hosting for free and see the difference for yourself.

No Credit Card Required.

Whitelabel Web Hosting Portal Demo

Launching WordPress on AWS takes just one minute with Nestify.

Launching WooCommerce on AWS takes just one minute with Nestify.