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.
What you'll need
- Administrator (Windows) or sudo (Mac/Linux)
- The domain that is blocked
Step-by-step diagnostic
Quick triage — pick your path
Quick triage — pick your path
Choose the option that matches what you see. You can jump straight to that section.
Show full guide
Steps
Goal: Confirm the hosts file blocks the site, remove the entry, and verify.
- Run
ping example.comorgetent 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 remove127.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 withsudo nano /etc/hostsorsudo vim /etc/hosts. On Mac:sudo open -e /etc/hostsopens 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, Macsudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder, Linuxsudo systemctl restart systemd-resolvedorsudo 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.comorgetent hosts example.comno 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.
- Confirm cause Ping or getent to see if hosts overrides DNS.
- Open hosts file Windows: C:\Windows\System32\drivers\etc\hosts. Mac/Linux: /etc/hosts.
- Remove blocking entry Delete or comment the line for the blocked domain.
- Flush DNS and verify Flush cache, test in browser.
- 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.
You can change your answer later.
Check DNS cache or browser
Which OS are you on?
Hosts file location differs by OS.
You can change your answer later.
Search for the domain or variations
Remove or comment the entry
You can change your answer later.
Run as Administrator or sudo
Flush DNS cache and verify
You can change your answer later.
Try incognito or clear browser cache
Site unblocked
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.