T

Edit Hosts File Windows

31 views · updated 2026-07-01 · published 2026-07-01 · by Hasarinda Manjula · Microsoft Windows Reading time: 2 min English සිංහල

How to Edit the Hosts File on Windows

Map hostnames to IPs locally for testing, blocking, or redirecting — safely and with admin rights.

Overview

The hosts file maps hostnames to IP addresses locally, overriding DNS for that machine. It’s used for testing sites, blocking domains, or redirecting hostnames. This guide shows how to edit it safely.

Editing the Windows hosts file.

Warning: The hosts file affects how your PC resolves names. Only add entries you understand — malware sometimes abuses it to redirect sites. Keep a backup of the original.

Key Takeaways

  • The hosts file overrides DNS for this PC only.
  • It lives at C:\Windows\System32\drivers\etc\hosts.
  • You must edit it as administrator.
  • Format: IP address, a space/tab, then the hostname.

What the Hosts File Is For

  • Test a site on a specific server before DNS changes.
  • Block a domain by pointing it to 127.0.0.1 / 0.0.0.0.
  • Create local shortcuts to internal IPs.
  • Override DNS for troubleshooting.

Edit the Hosts File (Notepad)

1. Press Start, type Notepad, right-click it, and choose "Run as administrator".

2. In Notepad, click File > Open and go to C:\Windows\System32\drivers\etc.

3. Set the file filter to "All Files" and open "hosts".

4. Add a line, e.g.: 192.168.1.50 myserver.local

5. To block a site: 0.0.0.0 example.com

6. Save the file (it stays as "hosts" with no extension).

Editing the hosts file.

Edit via the Command Line

1. Open Command Prompt as administrator.

2. Append an entry: echo 0.0.0.0 example.com >> C:\Windows\System32\drivers\etc\hosts

3. Flush DNS to apply: ipconfig /flushdns

Apply and Verify

1. Run ipconfig /flushdns after saving.

2. Test with: ping myhostname (it should resolve to your entry).

3. Remove the line and flush DNS to revert.

Troubleshooting

Problem: "Access denied" when saving.

Solution: Open the editor as administrator; the hosts file is protected.

Problem: Entry doesn’t take effect.

Solution: Run ipconfig /flushdns, and ensure there’s no leading # (which comments the line out).

Problem: File saved as hosts.txt.

Solution: Choose "All Files" when saving and remove the .txt extension so it’s just "hosts".

Problem: Security software blocks edits.

Solution: Some AVs protect the hosts file against tampering — allow the change in the AV, then edit.

Conclusion

Editing the hosts file lets you override DNS on a single PC for testing, blocking, or redirecting hostnames. Edit it as administrator, use the IP-then-hostname format, flush DNS to apply, and keep a backup — while staying alert to malicious hosts entries.

Thanks for your feedback! 🙌

Read more

TechHub Assistant
Online · AI assistant
Thinking
⬇ Downloads 📦 Orders 🛒 Buy License 🎫 Create Ticket 🙋 Contact
AI-generated · may be inaccurate. Talk to a human