Why Editing /etc/hosts Fails to Block Sites in Modern Chrome (IPv6, DoH & Path Limits)
Editing /etc/hosts (or C:\Windows\System32\drivers\etc\hosts) is the oldest zero-install trick for blocking distracting websites. Yet almost every developer who tries it runs into the same frustration: you add 127.0.0.1
Editing /etc/hosts (or C:\Windows\System32\drivers\etc\hosts) is the oldest zero-install trick for blocking distracting websites. Yet almost every developer who tries it runs into the same frustration: you add 127.0.0.1 youtube.com, save the file, open Chrome, and the site still loads.
Here are the four concrete technical reasons that happens in 2026 — and how to fix each one.
1. Missing IPv6 (::) entries
Modern home routers, ISPs, and browsers resolve both A (IPv4) and AAAA (IPv6) records. If your hosts file only maps 0.0.0.0 reddit.com, Chrome can still connect over IPv6.
Always include both 0.0.0.0 (which fails fast instead of waiting for a local web server timeout on 127.0.0.1) and :::
0.0.0.0 reddit.com
:: reddit.com
0.0.0.0 www.reddit.com
:: www.reddit.com
0.0.0.0 old.reddit.com
:: old.reddit.com
2. Missing mobile & alternate subdomains
The hosts file does not support wildcards (*.reddit.com is ignored). Blocking reddit.com alone still leaves www.reddit.com, old.reddit.com, and m.reddit.com wide open. The same applies to m.youtube.com, mobile.x.com, and m.facebook.com.
3. Stale DNS caches, Chrome Secure DNS (DoH), and open HTTP/3 sockets
Even after writing a clean hosts file:
-
macOS: flush with
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder -
Windows: flush with
ipconfig /flushdns -
Linux (
systemd-resolved): flush withsudo resolvectl flush-caches -
Chrome: open
chrome://net-internals/#dns→ Clear host cache, and close existing tabs so live QUIC/HTTP3 sockets drop. If Chrome's Use secure DNS (DoH) is set to a custom provider underchrome://settings/security, switch it to your OS default or restart Chrome.
4. Domain-only granularity (e.g., blocking YouTube Shorts without blocking YouTube)
A hosts file operates strictly at the DNS hostname layer. It has no visibility into URL paths or keywords — so it cannot block youtube.com/shorts while leaving youtube.com/watch working for tutorials and lectures, nor can it automatically unblock sites after 6 PM.
Free offline Hosts File Generator (MIT)
If you want a clean IPv4 + IPv6 blocklist with www. / m. / old. expansion and OS-specific flush commands without typing it by hand:
- Live zero-upload generator: lukaslabs.top/tools/hosts-file-blocker
- MIT open-source repo: github.com/oneguo-boop/hosts-file-website-blocker-generator
(Disclosure: When you need schedules, Pomodoro focus sessions, or URL path blocking like youtube.com/shorts in desktop Chrome, I also maintain Sitefence — a local-only Chrome extension covering up to 2,000 sites for free with no account and zero free-tier network requests.)
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.