If you just saved a bunch of edits to your hosts file and nothing is actually happening, don't worry - you probably didn't break anything. Modern browsers have started silently bypassing local machine routing thanks to features like DNS over HTTPS. If you want your PC to actually listen to your custom IP mappings, you almost always have to clear out your system’s DNS cache and toggle a couple of sneaky browser security settings.
- 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?
Windows buries this thing pretty deep in the system drive. You’ll find it sitting right at C:\Windows\System32\drivers\etc\hosts, assuming your OS is installed on the standard C: drive like most setups.
Notice that the file doesn't have an extension at all - no .txt, nothing. If you double-click it, Windows will just pop up that annoying "How do you want to open this file?" dialog. To actually get in there and make changes that stick, you need a basic text editor running with full admin privileges.
How to Edit the Hosts File (Top 4 Methods)
Messing with core system files means Windows demands elevated permissions. If you just open it like a regular user, you'll hit a wall the second you try to save your edits.
Method 1: The One-Liner PowerShell Command (Fastest)
Clicking through multiple system folders is a waste of time when you can just launch what you need straight from the terminal. This trick pops the file open in an elevated editor in about two seconds flat.
Just pop open PowerShell as an Administrator, drop in Start-Process notepad C:\windows\system32\drivers\etc\hosts, and hit enter. Notepad will open with the file loaded and the exact permissions you need to hit save without errors.
Method 2: Using VS Code or Notepad++
If you spend your day in proper code editors, you’ll probably want to use them here too so you get clean indentation and syntax highlighting. The workflow is basically the same, with one small catch.
Make sure you actually launch VS Code or Notepad++ as an Administrator before doing anything else. From there, hit File > Open, paste C:\Windows\System32\drivers\etc\hosts into the path bar, and load it up. Using these editors also helps you dodge annoying character encoding bugs that standard Notepad sometimes introduces.
Method 3: Classic Notepad (Run as Administrator)
This is the tried-and-true approach that doesn't need any special tooling. Everything you need is already baked into Windows right out of the box.
Tap your Windows key, search for Notepad, right-click the icon, and pick Run as administrator. Once it’s open, go to File > Open, head over to C:\Windows\System32\drivers\etc, flip the file type dropdown from "Text Documents" to All Files, and pick the hosts file from the list.
Method 4: Using Microsoft PowerToys
If you bounce between local dev environments all day, Microsoft actually built an official utility with a friendly UI just for this. It takes the guesswork out of formatting and keeps you from messing up the file syntax.
Grab Microsoft PowerToys if you don't have it, hop into the Hosts File Editor utility, flip it on, and launch it. It gives you a clean little dashboard where you can add, toggle, or wipe out IP mappings on the fly without ever touching raw text.
Hosts File Syntax and Formatting Rules
The parser reading this file is pretty rigid. If you mess up the spacing or line formatting, Windows will quietly ignore that specific row - or throw out the rest of the file entirely.
The structure is simple: slap down the target IP address first, leave a tab or a space, and follow it up with your domain. For instance, plugging in 127.0.0.1 devcrea.local tells your computer that anytime it tries to reach that domain, it should look right at your own machine.
Why You Cannot Use Wildcards
A lot of folks try to save time by throwing an asterisk in front of a domain to catch an entire site at once. Don't bother doing this - it's a rabbit hole that will just frustrate you.
The built-in Windows hosts system flat-out ignores wildcards. Dropping something like *127.0.0.1 .example.com into the file won't do a thing. You have to write out every single subdomain like api.example.com and cdn.example.com on its own line, or set up a dedicated DNS firewall solution if you need wide-net blocking.
Blocking Traffic: 0.0.0.0 vs 127.0.0.1
Rerouting obnoxious domains back into your local machine is an old-school trick for blocking ads and junk telemetry. That said, the specific IP you point them toward actually matters quite a bit for responsiveness.
If you route traffic to 127.0.0.1, your machine actively waits around for a local service to answer before timing out, which eats up small slices of system resources. Using 0.0.0.0 is much cleaner. It essentially functions as a dead end, dumping the network packet instantly without making your system hang around waiting for a response.
Commenting Out Lines
Don't just delete lines when you finish testing a feature; you'll probably end up needing that exact configuration again next week. Leaving clean comments keeps your file tidy and reusable.
Just drop a # right at the start of any line you want to mute. Windows skips over anything following that hash symbol, making it super easy to toggle testing environments on and off without having to re-type IP strings from scratch.
Why Your Hosts File Changes Are Not Working (The Fixes)
So you edited the file, hit save, and your browser is still pulling up the live internet version of the site anyway. Here is what is usually going wrong behind the scenes.
Step 1: Flush Your DNS Cache
Windows loves to remember where domain names go so it doesn't have to look them up repeatedly. If you don't tell it to dump that memory, it will happily keep using the old routing.
Pop open a standard Command Prompt and run ipconfig /flushdns right after you save your edits. You should see a quick line confirming the resolver cache was wiped. Honestly, this single step resolves nine out of ten issues people run into.
Step 2: Bypass DNS over HTTPS (DoH) in Browsers
Most modern browsers now default to encrypted DNS channels, which means they deliberately ignore your local operating system routing tables altogether. That completely cuts your hosts file out of the loop.
Apps like Chrome, Edge, and Firefox tend to bounce their queries directly off third-party servers like Cloudflare or Google. Head into your browser’s privacy or security settings, search for Secure DNS, and switch it off while you’re developing. That forces the browser to fall back to your local Windows settings.
Step 3: Check File Encoding Formats
Hidden byte markers hiding at the top of your text can easily choke the Windows DNS parser. This happens all the time if you copy and paste snippets directly out of web forums or chat tools.
You want the file saved specifically as ANSI or clean UTF8 without BOM. If an editor sneaks a Byte Order Mark into the header, Windows won't even parse your first line of configuration. Load the file up in Notepad++, look at the Encoding tab in the top menu, and make sure it’s set to standard UTF-8.
Step 4: VPN and Firewall Conflicts
Whenever you're on a VPN, its main job is to channel all your traffic through an encrypted pipe to keep your lookups private. Because of that, the VPN adapter will aggressively override local rules to stop potential leaks.
Try disconnecting your VPN tunnel while you test local entries to see if it starts resolving. If you're on a managed work machine with corporate endpoint protection, dig into the client settings to see if something like Ignore local DNS is actively getting in your way.
How to Fix Access Denied Errors
Because malware loves to mess with the hosts file to hijack web browsing, Windows Defender and third-party antivirus suites watch this specific file like a hawk. Sometimes they get a little too aggressive and block legitimate edits.
If you get hit with an Access Denied pop-up even while running your editor as an admin, your antivirus is almost certainly holding the lock. Jump into Windows Security or your security app, find the real-time scanning section, and pause it for a minute while you save your edits.
It's also worth checking the file attributes directly. Right-click the hosts file, choose Properties, and verify that the Read-only box at the bottom isn't checked; if it is, uncheck it, apply the change, and try again.
How to Verify Your Changes
Don't rely on a web browser to verify whether your routing is working, because internal browser caches will just lie to you. Dropping down to raw network utilities gives you an honest look at what’s happening.
Open up a terminal and run ping yourdomain.com to inspect the output. If the response ping comes back from your custom IP rather than the live web server, you know the hosts file is doing its job. You can also run nslookup alongside it if you need to double-check which server is answering queries.
How to Reset the Hosts File to Windows Defaults
If your file has turned into a tangled mess of broken lines, bad syntax, or weird leftovers from old software, wiping the slate clean is usually the easiest path forward.
First, rename the existing file to hosts.old so you still have a safety net of your previous notes. After that, create a fresh, empty text file right in that same folder and name it hosts - making sure there is no extension on the end. An entirely empty hosts file is completely fine, as Windows 10 and 11 don't need any default text in there to run normally.
