How to view a non-live site by editing your Hosts file

How to Preview Your Website Before Changing DNS

 

Temporary Proxy Link Method:

Certain web services like skipdns.link will allow you to input a domain and an IP, then return a temporary link to view a copy of the site. 

 

This is useful for verifying basic content but not for web development, as the site is read-only. For development, we recommend using the Hosts file method.

 

 

Hosts File Method:

Editing your Hosts file is the best way to preview a new version of a website while keeping the live version of the site accessible to all other users.

 

Whenever a website is loaded, your computer will perform a DNS lookup to find the IP of the server the website is hosted on. Before this, it will check in a local Hosts file to see whether it already has that information.

By adding an entry to this file, you can force your computer to attempt to load any domain from any server. Once done, you can simply remove the record and the computer will perform a lookup as normal.

 

Your hosts entry will consist of the IP address of the server, and the domain name(s) you wish to load from that IP.

For example:
103.26.236.255 yourdomain.net.au www.yourdomain.net.au

You can find your server IP in cPanel, or in the email, which contains your Hosting account login details.

 

 

Editing a hosts file on Windows

Step 1 - Click on Start, type in Notepad then right click and select Run as Administrator

2d6f152522f2388c62ed5f4682e8de6f0893d5115b8edb6451a9acdafdb6335a5e13a469809041c6?t=be829d3db5ca2b397646fad29a2896bb
 
Step 2 - Click Continue on the 'Windows needs your permission' popup.
 
Step 3 - In Notepad, click File > Open, go to the C:\Windows\System32\Drivers\etc\ folder. Select the hosts file and click Open.
b09daf316a880684efbbb5377f6b002071a0bed95f6b3c2ac74cf702cd1f4b89a7c941b471c32864?t=67c10384b38f13822b125a838441396a
 
(Optional) - If the folder is blank, first select the file type of All Files then select the hosts file and click Open.

315d567646fb58c7e7541932c8dfd55ace02170699e2c212fd19d3c30ccc0ec1acda0d57df66039f?t=0487a198f9a5439b567311ed635e04c0

 

Step 4 - Start a new line at the bottom of the file and enter the new entry.

 

An example entry would be:

103.26.236.255 yourdomain.net.au www.yourdomain.net.au

 

c8cd3f4b6ae878d9dfd092352ee3907028b917b07a79bd19358a04bf36e5b1f298156a50bbf3746c?t=926496232e3fbd28974d3a3c83f12fb2

Step 5 - Save the file by going to File > Save in Notepad.

You should now be able to view the site from the new IP. You may need to clear your cache and cookies if the site is cached in your browser. Alternatively, use a private browser window or a different browser.

 

Note: You can disable this hosts file entry once it is no longer needed by repeating steps 1-3, and adding a # to the start of the line you added. You could also delete the line from the hosts file entirely. Remember to save your changes.

 

 

 

 

Editing a hosts file on Mac

Step 1 - Open the Terminal program (under Applications > Utilities).

Step 2 - Type in the following code:
sudo nano /etc/hosts
Then type your password in if asked.
 
cb51a4c04a1fdc76ca3a2e73127afed5a2ffc7215914e30895b4d4b04965f8137d6ea0e35f7f16e0?t=92ec489db411a5900a7549ac4a6ac953
 

Step 3 - Start a new line at the bottom of the file and enter the new entry.

 

An example entry would be:

103.26.236.255 yourdomain.net.au www.yourdomain.net.au

 


Step 4 - When finished, hit Control+O followed by Enter/Return to save changes, then hit Control+X to exit out of editing the hosts file.
If you receive an error similar to: "Cannot open file for writing: Permission denied" you may not have the permissions to edit this file. Contact your local system admin.
 
Note: You should now be able to view the site from the new IP. You may need to clear your cache and cookies if the site is cached in your browser. Alternatively, use a private browser window or a different browser.
 

Step 5 (Optional) - Type in the command below into Terminal:
dscacheutil -flushcache

 

 

Step 6 - Hit Enter/Return.

Note: You can disable this hosts file entry once it is no longer needed by repeating steps 1-2, and adding a # to the start of the line you added. You could also delete the line from the hosts file entirely. Remember to save your changes as shown in step 4.

8b1ce4927a23c0be4ff06830c8d62c2203df31d4cab04c9fc2024b3790765334b97537a3bbc489ab?t=6b891c2ff24fd4491d4643c9178982ea

 

 

 

cPanel Temporary URL Method - Not supported

The cPanel documentation on this legacy method can be found here.

 

cPanel does not recommend or provide support for this method, and it is not enabled on our services for security and functionality reasons. 

 

Since modern CMSs like Wordpress have references to the full site URL in their site files and database, a user's browser is directed to download resources at time of page load. Using this method, the non-live site will load resources from the live version instead which defeats the purpose of a temporary domain.
A developer could theoretically get around this by updating every instance of the site url to the temporary domain, but doing so is beyond the scope of this guide.