The changes you just saved to your local environment are likely failing because modern browsers silently ignore local routing through DNS over HTTPS. Clearing your system DNS cache and bypassing secure browser settings are mandatory steps to force your machine to respect the new IP addresses.

  • File Location: C:\Windows\System32\drivers\etc\hosts
  • Required Permission: Administrator
  • Apply Changes Command: ipconfig /flushdns
  • Supported Formats: ANSI or UTF8 without BOM

Where is the Windows Hosts File Located?

The file is buried deep within the Windows system architecture. You can find the hosts file exactly at C:\Windows\System32\drivers\etc\hosts on your main OS drive.

The file has no extension. Opening it directly by double-clicking usually prompts Windows to ask which application you want to use. You need a plain text editor with elevated privileges to make any permanent changes.

How to Edit the Hosts File (Top 4 Methods)

Editing system files requires administrative rights. Trying to save changes as a standard user results in immediate permission errors.

Method 1: The One-Liner PowerShell Command (Fastest)

Opening menus and navigating folders takes unnecessary time. You can launch a fully elevated text editor directly from your command line.

Open PowerShell as an Administrator. Paste the command Start-Process notepad C:\windows\system32\drivers\etc\hosts and press enter. The file opens immediately with full save permissions.

Method 2: Using VS Code or Notepad++

Developers usually prefer dedicated code editors for syntax highlighting and better formatting control. Opening the file directly in these editors is straightforward.

Launch your preferred editor as an Administrator first. Go to File then Open and paste the C:\Windows\System32\drivers\etc\hosts path into the address bar. Saving changes here avoids the common encoding issues associated with standard text editors.

Method 3: Classic Notepad (Run as Administrator)

This is the traditional method that requires no third-party software. The process relies entirely on built-in Windows tools.

Press the Windows key and type Notepad in the search bar. Right-click the application icon and select Run as administrator from the context menu. Click File then Open, navigate to the C:\Windows\System32\drivers\etc directory, change the file type dropdown from Text Documents to All Files, and select the hosts file.

Method 4: Using Microsoft PowerToys

Microsoft provides a graphical interface for developers who frequently switch local environments. The PowerToys Hosts File Editor makes syntax errors almost impossible.

Install Microsoft PowerToys and open the Hosts File Editor module. Toggle the switch to enable it and click the launch button. You can now add, toggle, or delete IP routings using a clean visual dashboard without touching the raw text.

Hosts File Syntax and Formatting Rules

The file format is strictly defined. Breaking these rules causes Windows to ignore the specific line or the entire file.

The correct syntax is the destination IP address, followed by at least one space or tab, and then the hostname. Writing 127.0.0.1 devcrea.local routes all local requests for that domain to your localhost.

Why You Cannot Use Wildcards

Many developers try to block entire networks by adding asterisks to their domain entries. This is a massive time trap.

The Windows hosts file does not support wildcards. Writing *127.0.0.1 .example.com will completely fail. You must explicitly list every single subdomain like api.example.com and cdn.example.com on separate lines. For broad network blocking, you need DNS firewall solutions instead of local text files.

Blocking Traffic: 0.0.0.0 vs 127.0.0.1

Redirecting domains to your local machine is the standard way to block telemetry or ads. However, the IP address you choose impacts system performance.

Using 127.0.0.1 forces your machine to actively resolve and reject the connection, which takes milliseconds and creates timeout logs. Routing traffic to 0.0.0.0 is much faster. It acts as a black hole, dropping the connection instantly without waiting for a local timeout.

Commenting Out Lines

Deleting entries completely means losing your configuration data for future projects. Commenting them out is a much safer developer practice.

Place a # symbol at the very beginning of the line. Windows ignores everything after the hash symbol on that specific line. This allows you to quickly toggle local test environments on and off without retyping IP addresses.

Why Your Hosts File Changes Are Not Working (The Fixes)

You saved the file successfully but the browser still loads the live website. This is the most common frustration for developers.

Step 1: Flush Your DNS Cache

Windows caches IP addresses to speed up browsing. The system will continue using the old cached IP until you force a manual reset.

Open Command Prompt and type ipconfig /flushdns immediately after saving your hosts file. You will see a success message confirming the cache is clear. This single command solves the majority of routing failures.

Step 2: Bypass DNS over HTTPS (DoH) in Browsers

Modern browsers prioritize encrypted DNS requests over your local system settings. This completely bypasses your freshly edited hosts file.

Chrome, Firefox, and Edge route requests through providers like Cloudflare or Google by default. You need to open your browser settings, search for Secure DNS, and temporarily disable it. Once disabled, the browser falls back to the Windows hosts file for routing instructions.

Step 3: Check File Encoding Formats

Invisible characters at the beginning of your file will break the Windows DNS parser. This happens frequently when copying configurations from the internet.

Your file must be saved as ANSI or UTF8 without BOM. If you accidentally save the file with a Byte Order Mark (BOM), the system fails to read the first line. Open the file in Notepad++, check the encoding menu at the top, and convert it to standard UTF8.

Step 4: VPN and Firewall Conflicts

Active network tunnels override local DNS rules to prevent DNS leaks. Your VPN client is actively protecting your traffic by ignoring local instructions.

Disconnect your VPN completely while testing local domains. If you use a corporate firewall or advanced endpoint protection, check the settings for an option named Ignore local DNS and disable it.

How to Fix Access Denied Errors

Antivirus software actively monitors the hosts file to prevent malware from hijacking your web traffic. This protection blocks even legitimate administrator edits.

If Notepad gives you an Access Denied error despite running as an administrator, your security software is locking the file. Open Windows Security or your third-party antivirus, navigate to the real-time protection settings, and temporarily disable file system shields.

Another common issue is the Read-Only file attribute. Right-click the hosts file, select Properties, and ensure the Read-only checkbox at the bottom is unchecked before trying to save.

How to Verify Your Changes

Testing your configuration in a browser introduces cache variables that make debugging difficult. Command line tools provide absolute proof of your routing.

Open Command Prompt and type ping yourdomain.com to see the raw output. If the response comes from your specified IP address instead of the public server, your hosts file is working perfectly. You can also use the nslookup command to verify exactly which DNS server is handling the request.

How to Reset the Hosts File to Windows Defaults

Sometimes syntax errors or malware entries become too complex to fix manually. Starting fresh is the safest option.

Rename your current file to hosts.old to keep a backup. Create a brand new text document in the same folder and name it hosts without any file extension. You can leave it completely blank, as Windows 10 and 11 do not require any default entries to function normally.