How can I simulate a DNS change locally with the /etc/hosts file?

Modified on Mon, 17 Nov at 3:18 PM

Introduction

Are you currently in the testing phase before connecting your site to Fasterize? Would you like to check how it behaves without modifying your official DNS configuration?

Good news: it’s possible to simulate a DNS change locally on your machine, without affecting other users or altering your DNS zone.

In this article, we’ll walk you through how to redirect a domain name to a specific IP address on your computer using the hosts file. This method is especially useful for:

  • Testing your site before the official switch to Fasterize,
  • Checking the result of an optimized or unoptimized version,
  • Diagnosing behavior at the origin without Fasterize or a CDN.


What is the hosts file and what is it used for?

The hosts file is a system file present on all computers. It lets you force the association between a domain name and an IP address, even before any external DNS request is made.

By editing this file, you can test a website as if it pointed to a different IP, locally on your machine only.


Classic resolution vs hosts file

  • Without the hosts file: your browser queries a DNS server to resolve www.example.com
  • With a line in the hosts file: your computer uses the IP you specified, without querying any DNS server


Step 1 – Identify the target IP

Case 1: Testing a site optimized with Fasterize

To ensure your site displays correctly with Fasterize before switching your public DNS, you can point it to the platform’s IP:

51.159.84.68 www.example.com

 If your domain is already behind a CDN, contact Fasterize support to avoid DNS conflicts.


Case 2: Testing the site without Fasterize or CDN

To observe how your origin behaves without interference from Fasterize or your CDN, use your server’s origin IP:

  • Go to the Fasterize Console > Domains tab > copy the origin IP
  • Example line:
1.2.3.4 www.mysite.com

Replace 1.2.3.4 with your actual origin IP.


Step 2 – Edit the hosts file on your computer


Where to find the hosts file

  • Windows: C:\Windows\System32\drivers\etc\hosts
  • Mac/Linux: /etc/hosts

This file is protected: you’ll need administrator rights to modify it.


How to edit it

  • Windows: open Notepad as Administrator, then open the hosts file


  • Mac: use the Terminal with sudo nano /etc/hosts, or install the graphical tool Gas Mask 


Add your line at the end of the file, using this format:

[IP address] [domain name]

Example:

51.159.84.68 www.example.com

Save and close the file.


Step 3 – Flush your DNS cache


To ensure your modification is effective, flush your system’s DNS cache:

  • Windows:
ipconfig /flushdns

  • macOS:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder


Step 4 – Restart your browser


Restart your browser completely to apply the new DNS resolution.


Check if the test works

  • On Chrome, use the Fasterize browser extension:
    • White icon: the site is not optimized by Fasterize
    • Colored icon: the site is going through Fasterize

Conclusion


Editing your hosts file is a simple, reversible, and risk-free way to test your optimizations or diagnose origin-level issues before officially switching your site to Fasterize.

  • Case 1: test with Fasterize before going live
  • Case 2: test without Fasterize or CDN to isolate an issue


Don’t forget to restore your original hosts file once testing is complete, and feel free to contact our support team if needed!

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article