Block a website using the /etc/hosts file
Redirect a domain to 127.0.0.1 so no browser on this machine can open it.
01Command
$ echo -e '127.0.0.1\texample.com\n127.0.0.1\twww.example.com' | sudo tee -a /etc/hosts02What it does
The system checks /etc/hosts before DNS, so mapping a domain to 127.0.0.1 makes the browser fail to connect immediately — no extensions or filtering software needed. Add both the bare domain and the www. variant, since browsers request them separately. The block applies system-wide and survives reboots until you delete the line.
03Risk
04Undo
$ sudo sed -i '/example.com/d' /etc/hosts05Sources
- hosts(5) — Linux manual pageEvidence: /etc/hosts maps hostnames to IP addresses and is consulted before DNS, so pointing a domain at 127.0.0.1 blocks access to it.
Last verified: 2026-09-18 · Category: Network
06Related solutions
One command that prints every interface with its state and IPv4/IPv6 addresses in a short table — the modern, memorable replacement for digging through `ifconfig` or the verbose `ip addr` output.
The classic forgotten-syntax command: `traceroute` shows every router between you and a destination plus the round-trip time of probes to each hop.
Add a UFW rule to permit inbound traffic on a TCP or UDP port, such as SSH on port 22.