Dev.to
7/16/2026

How to block websites with the hosts file
Short summary
A straightforward tutorial on blocking websites by editing the OS hosts file to point domains at 0.0.0.0. Covers commands for macOS, Linux, and Windows, DNS cache flushing, and common pitfalls like hardcoded IPs, VPNs, and CDN hosts. Includes tips for grouping blocks under comments and mentions Locahl as a desktop manager for host profiles.
- •Edit /etc/hosts (or Windows equivalent) to point domains at 0.0.0.0 for local blocking
- •Flush DNS cache after editing: dscacheutil on macOS, resolvectl on Linux, ipconfig on Windows
- •Works for distraction sites and telemetry; use DNS or firewall rules for network-wide blocking
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



