How to Edit the Hosts File in Windows 10 and 11

The Windows hosts file is a plain text file that maps domain names to IP addresses before DNS lookup happens. Editing it lets you block domains, redirect traffic locally, or create custom hostname entries for development work. Here’s how to edit it correctly.

What the hosts file does

When you type a URL in a browser, Windows first checks the hosts file before querying DNS. If the hosts file has an entry for that domain, it uses that IP address directly. This makes it useful for:

  • Blocking websites by pointing them to 127.0.0.1 (localhost)
  • Redirecting a domain to a local development server
  • Overriding DNS for testing purposes

File location

The hosts file is at: C:\Windows\System32\drivers\etc\hosts

It has no file extension. It’s a plain text file.

How to edit it

You can’t just open and save the hosts file – it requires administrator permissions. Two methods:

Method 1: Open Notepad as administrator

  1. Search for Notepad in the Start menu
  2. Right-click Notepad > Run as administrator
  3. File > Open > navigate to C:\Windows\System32\drivers\etc\
  4. Change the file type filter from “Text Documents” to “All Files”
  5. Select “hosts” and open it
  6. Make your edits and save

Method 2: Copy, edit, replace

  1. Copy the hosts file to your Desktop
  2. Edit it in any text editor
  3. Copy it back to C:\Windows\System32\drivers\etc\ and approve the administrator prompt

Hosts file format

Each line follows the format: IP address [tab or space] hostname

Examples:

  • 127.0.0.1 example.com – blocks example.com by pointing it to localhost
  • 192.168.1.100 mydevserver.local – maps a custom hostname to a local IP
  • Lines starting with # are comments and are ignored

Flushing DNS after editing

After saving changes to the hosts file, flush the DNS cache so the changes take effect immediately: open Command Prompt as administrator and run ipconfig /flushdns.

Reverting changes

To undo, open the hosts file again and remove the lines you added. The default hosts file only contains commented lines (starting with #) – deleting any uncommented lines you added restores the original behavior.

the “change file type to All Files” step in Notepad is the one that gets people. you open file > navigate to the folder > and the hosts file isn’t visible because Notepad defaults to showing .txt files only. changing that filter reveals it. classic UX friction that trips up first-timers.

blocking sites via the hosts file is genuinely useful for self-control. pointing reddit.com and twitter.com to 127.0.0.1 during work hours is a well-known productivity trick. it’s low-tech but effective because the block happens before the browser even tries to connect.

The hosts file being checked before DNS is what makes it powerful for development. Mapping a production domain name to your local server IP means you can test your site exactly as it will appear in production, using the real domain, without touching actual DNS records.

The ipconfig /flushdns step after editing is important and often missed. Without it, Windows may continue using the cached DNS result for a domain even after you’ve added a hosts entry. The flush forces immediate use of the new mapping.

Worth noting that hosts file edits are per-machine. If you want to block a domain on multiple computers, you need to edit the hosts file on each one. For household-level blocking, setting up a Pi-hole or configuring DNS blocking on your router is more scalable.