Search for instant answers to common support and billing questions

How Can You Test Your Website Using a Hosts File?

2 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 your website with the destination domain—the one that will be used when your site goes live. This method prevents many potential issues.

Next, update your local hosts file. This step makes your computer believe that DNS resolves to your server’s IP address.

Then, develop and test your website in the browser as though it were live. Once you’re done, update the A records for your domain at your DNS host.

Each operating system has a local hosts file, though its location may vary. 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 simple, as all operating systems use the same syntax. Start by entering the IP address you want to mask, followed by a space, and then type the hostname you want to masquerade.

You can make these changes with any text editor, though you might need to elevate your privileges to do so.

If you prefer using a graphical user interface (GUI), here are a couple of helpful tools we recommend to make the process easier.


Helm (macOS) 

Helm simplifies local hosts file editing on macOS. Instead of using the terminal to elevate your privileges and relying on a text editor, Helm enables quick and easy edits directly from its graphical user interface (GUI).

Hosts File Editor (Windows)

Hosts File Editor is an open-source, GUI-based tool for editing the local hosts file on Windows. Since the file permissions on Windows are more restrictive than those on Linux or macOS, this tool offers a more straightforward way for Windows users to modify their hosts file while minimising the risk of corruption.

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