Block a Website by Editing /etc/hosts
Point a domain to 127.0.0.1 so every browser on this Mac fails to reach it.
Run `printf "127.0.0.1 www.distracting-site.com\n" | sudo tee -a /etc/hosts && sudo dscacheutil -flushcache` to block the site immediately.
01Command
Command
$ printf "127.0.0.1 www.distracting-site.com\n" | sudo tee -a /etc/hosts && sudo dscacheutil -flushcache02What it does
The hosts file is checked before DNS, so mapping a domain to 127.0.0.1 makes it unreachable in every browser and app — a simple, ad-blocker-free way to cut distractions. Flush the lookup cache afterwards so the change takes effect without logging out. Block each hostname variant you actually use (with and without www) on its own line.
03Risk
!Warning: Editing /etc/hosts with the wrong syntax can break name resolution — always keep a backup copy and revert with the undo command if anything misbehaves.
04Undo
Undo
$ sudo sed -i '' '/www\.distracting-site\.com/d' /etc/hosts && sudo dscacheutil -flushcache05Sources
- dscacheutil — flush the directory services cache (macOS man page)Evidence: Documents dscacheutil -flushcache invalidating cached lookups so the new hosts entry takes effect.
- nano — edit a file in Terminal (macOS man page)Evidence: nano is the simple editor for manually removing or fixing lines in /etc/hosts.
Last verified: 2026-09-18 · Category: Network