Search for instant answers to common support and billing questions

Testing your website with a hosts file

4 min read

Network Dynamics knows that a hosts file maps hostnames (e.g., google.com) to IP addresses (e.g., 216.58.199.78). To change the IP address that a domain resolves to, add entries to your local hosts file on your computer.

Use a hosts file if you want to preview a website on a different server. This approach saves you the wait for DNS changes to propagate or the need to make any DNS changes at all.

Many developers choose a temporary URL to develop a website before it goes live. This method lets them work on the site without affecting the live version. However, developing on a temporary URL can create issues when you switch to the live site.

Many CMS and CRM applications require you to update the database when switching domains from temporary to live. These updates sometimes break the website or application, and the switch-over process can take a long time.

However, you can modify your local hosts file so your computer treats the new site as if it already resides at its final location. This trick allows you to test the site before updating DNS. As a result, you will see the same content before your site goes live as you do after updating DNS.

The Problem without Hosts File

Missing assets (CSS files, JavaScript, images, and other media) on your website can cause major site‐rendering problems.

Nearly every developer has encountered an issue when a stylesheet fails to load. This failure makes the page appear outdated, with unformatted text and missing images.

When you develop on a temporary URL, the website or application might create hard-coded links in the database. These links reference assets using a fully qualified domain name (FQDN).

If you do not address these hard links properly, your site might break when you switch from a temporary URL to the production URL. This issue can affect CMSs, CRMs, themes, or plugins.

Skilled system administrators and developers use scripts or plugins to search for and replace these links in the database. Furthermore, developers often use ‘grep‘ to scan website contents and update these links to reflect the correct production URL.

This process can be time-consuming. Some applications serialise data, which makes it difficult—or nearly impossible—to locate and update the offending asset links.

The Solution

Develop the website using its destination domain—the domain that will be used when your site is live. This approach eliminates many potential problems.

Next, modify your local hosts file. This change tricks your computer into believing that DNS resolves to the IP address of your server.

Then, develop and test your website in the browser as if it were live. Once you finish, update the A records for your domains at your DNS host.

Every operating system has a local hosts file, though its location may differ. Consequently, to modify your hosts file, consider one of the following options:

  • Linux / Mac OS X: /etc/hosts
  • Windows: %windir%\system32\drivers\etc\hosts

Editing your local hosts file is straightforward since all operating systems follow the same syntax. First, enter the IP address you want to mask, then add a space, and finally, type the hostname you wish to masquerade.

You can edit these with any text editor (although you may need to elevate your privileges in order to do so).

If an easy-to-use GUI is more your style, here are a couple of handy tools we recommend to use in order to make the job easier.


Helm (macOS) 

Helm is a local host file editing tool for macOS. Rather than having to use the terminal to elevate your privileges and then use a text editor to make the changes, Helm allows for rapid editing of your host file from within the GUI.

Hosts File Editor (Windows)

Hosts File Editor is an Open Source GUI-based local hosts file editing tool for Windows. The file permissions surrounding the hosts file on Windows are a bit harder to circumvent than they are in Linux or Mac OS X.

This provides a simpler way for Windows users to make modifications to their hosts file and reduces the risk of corrupting the file.

hosts file in windows
Did this support article help?

Get in touch, we're here to help you!

You can also check out our knowledgebase for instant answers to common questions

Email Us

We’ll respond to your inquiry as soon as possible.
Get In Touch

Call Us

Our customer support team is available
1300 768 249

Live Chat

Chat with us in real-time using our live chat feature.
Chat Now