Fix a hosts file that blocks a site

We'll confirm the hosts file is the cause, find and remove the blocking entry on Windows or Mac/Linux, and verify the site loads.

Category
Troubleshooting · Home maintenance
Time
3–8 min
Last reviewed
What you'll need
  • Administrator (Windows) or sudo (Mac/Linux)
  • The domain that is blocked

Step-by-step diagnostic

Step 1 of 9
Show full guide

Steps

Goal: Confirm the hosts file blocks the site, remove the entry, and verify.

  • Run ping example.com or getent hosts example.com (replace example.com with the domain). If the IP is 127.0.0.1 or 0.0.0.0, the hosts file is likely the cause.
  • Good: Resolved IP is blocking. Proceed to Windows — edit hosts or Mac/Linux — edit hosts.
  • Bad: IP looks normal—check DNS cache or browser (see fix-dns-cache-is-wrong, fix-browser-will-not-load-site).

Windows — edit hosts

Goal: Open and edit the hosts file on Windows.

  • The hosts file is at C:\Windows\System32\drivers\etc\hosts. Open Notepad as Administrator (right-click Notepad, Run as administrator).
  • File → Open, go to C:\Windows\System32\drivers\etc, set file type to All Files, select hosts, open.
  • Find the line with the domain (e.g. 127.0.0.1 example.com). Remove it or add # at the start to comment it out. Do not remove 127.0.0.1 localhost.
  • File → Save. If access denied, confirm Notepad was opened as Administrator.
  • Good: File saved. Proceed to Flush and verify.
  • Bad: Cannot save—run Notepad as Administrator.

Mac/Linux — edit hosts

Goal: Open and edit the hosts file on Mac or Linux.

  • The hosts file is at /etc/hosts. Open with sudo nano /etc/hosts or sudo vim /etc/hosts. On Mac: sudo open -e /etc/hosts opens it in TextEdit.
  • Find the line with the domain (e.g. 127.0.0.1 example.com). Remove it or add # at the start to comment it out. Do not remove the localhost line.
  • Save: nano: Ctrl+O, Enter, Ctrl+X. vim: Esc, :wq, Enter.
  • Good: File saved. Proceed to Flush and verify.
  • Bad: Permission denied—use sudo.

Flush and verify

Goal: Clear DNS cache and confirm the site loads.

  • Flush DNS cache: Windows ipconfig /flushdns, Mac sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder, Linux sudo systemctl restart systemd-resolved or sudo systemctl restart nscd.
  • Open the site in a browser. Use incognito if the browser may have cached the block.
  • Good: Site loads. The hosts file no longer blocks it.
  • Bad: Still blocked—try incognito, clear browser cache, or check DNS.

When to get help

  • You cannot open or save the hosts file (permission issues).
  • You removed the entry but the site still does not load—may be DNS, browser, or firewall.
  • You are unsure which line to remove and need to avoid breaking the system.

Verification

  • ping example.com or getent hosts example.com no longer resolves to 127.0.0.1 for the domain.
  • The site loads in the browser (or incognito).
  • The blocking entry is removed or commented in the hosts file.

Escalation ladder

Work from the device outward. Stop when the problem is fixed.

  1. Confirm cause Ping or getent to see if hosts overrides DNS.
  2. Open hosts file Windows: C:\Windows\System32\drivers\etc\hosts. Mac/Linux: /etc/hosts.
  3. Remove blocking entry Delete or comment the line for the blocked domain.
  4. Flush DNS and verify Flush cache, test in browser.
  5. Check browser or DNS If still blocked, try incognito, clear browser cache, or check DNS.

What to capture if you need help

Before calling support or posting for help, have these ready. It speeds everything up.

  • Domain that is blocked
  • Resolved IP from ping or getent
  • Line removed or commented
  • Steps already tried

Does ping or getent show 127.0.0.1 or a blocking IP for the domain?

The hosts file overrides DNS. If ping resolves to localhost, hosts is likely the cause.

Run `ping example.com` or `getent hosts example.com`. If the IP is 127.0.0.1 or 0.0.0.0, the hosts file is likely blocking. Good: you see a blocking IP. Bad: IP looks normal—check DNS cache or browser.

You can change your answer later.

Check DNS cache or browser

If the resolved IP is not 127.0.0.1, the hosts file may not be the cause. Try fix-dns-cache-is-wrong or fix-browser-will-not-load-site.

Which OS are you on?

Hosts file location differs by OS.

Windows: open C:\Windows\System32\drivers\etc\hosts in Notepad as Administrator. Mac/Linux: open /etc/hosts with sudo nano /etc/hosts. Find the line with the domain (e.g. 127.0.0.1 example.com). Good: you found it. Bad: no such line—hosts may not be the cause, or the entry uses a different format.

You can change your answer later.

Search for the domain or variations

Search for the domain with and without www. Some entries block both. If still not found, the block may come from DNS, browser, or another tool.

Remove or comment the entry

Delete the line or add # at the start to comment it out. Save the file. Do not remove 127.0.0.1 localhost. Good: saved. Bad: access denied—run as Administrator (Windows) or with sudo (Mac/Linux).

You can change your answer later.

Run as Administrator or sudo

Windows: right-click Notepad, Run as administrator. Mac/Linux: use sudo when opening the file. Retry the edit.

Flush DNS cache and verify

Flush DNS: Windows `ipconfig /flushdns`, Mac `sudo killall -HUP mDNSResponder`, Linux `sudo systemctl restart systemd-resolved`. Open the site in a browser. Good: site loads. Bad: still blocked—try incognito, clear browser cache, or check DNS.

You can change your answer later.

Try incognito or clear browser cache

The browser may cache the block. Try incognito/private mode. If that works, clear the browser cache. See fix-browser-will-not-load-site.

Site unblocked

The hosts file no longer blocks the site. The site should load normally.

Reviewed by Blackbox Atlas

Frequently asked questions

What does the hosts file do?
The hosts file overrides DNS for specific domains. An entry like "127.0.0.1 example.com" makes the system resolve example.com to localhost, effectively blocking it. It is checked before DNS.
Why would a hosts file block a site?
Ad blockers, parental controls, or security tools sometimes add entries to block sites. A typo or old entry can also block a site you need. Malware has been known to modify hosts.
Is it safe to edit the hosts file?
Yes, if you only remove or comment the blocking entry. Do not delete the default localhost lines (127.0.0.1 localhost). Use a backup if unsure.

Rate this guide

Was this helpful?

Thanks for your feedback.

Continue to