How To Edit Hosts File To Preview Your Site


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

How To Edit Hosts File

Hosts 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 are mapping the IP address we know to our domain name so that we can preview the website. 

You will need administrator access to edit the hosts file. Editing is pretty simple, as you just have to insert a line of text at the end of the hosts file. 

Edit Hosts File Windows

Follow these steps to edit “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:\Windows\System32\drivers\etc\

Step 3: Select the \etc folder

Step 4: To see the hosts 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 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:

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: 

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 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:

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


You now know how to edit hosts 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.

Leave a Reply