How to Block Websites on Linux Using the /etc/hosts File
HardReset.InfoDecember 17, 20254 min73 views
2 connections·4 entities in this video→Blocking Websites with the /etc/hosts File
- 💡 The
/etc/hostsfile on Linux allows you to map domain names to IP addresses, enabling local website blocking. - 🎯 This method works by redirecting a website's domain to an unreachable IP address, such as
127.0.0.1(the loopback address).
Editing the hosts File
- 🔑 To edit the file, you need administrative privileges. Open a terminal and use
sudo nano /etc/hosts. - 📌 Enter your password when prompted to gain write access to the configuration file.
- ✍️ Add a new line mapping the desired website (e.g.,
www.google.com) to127.0.0.1. - ✅ Save the changes by pressing
Ctrl+O, thenEnter, and exit the editor withCtrl+X.
Verifying and Unblocking Websites
- 🚀 After saving, restart your web browser to apply the changes.
- 🔍 You can verify the block by trying to access the website, which should now fail to load.
- 📊 Use the
pingcommand (e.g.,ping www.google.com) to confirm that the domain resolves to your loopback address. - ⏪ To unblock a website, re-edit the
/etc/hostsfile and comment out the line by adding a#at the beginning. - 🔄 Retest access after commenting out the line to ensure the website is accessible again.
Knowledge graph4 entities · 2 connections
How they connect
An interactive map of every person, idea, and reference from this conversation. Hover to trace connections, click to explore.
Hover · drag to explore
4 entities
Chapters2 moments
Key Moments
Transcript15 segments
Full Transcript
Topics11 themes
What’s Discussed
Linux/etc/hostsHosts FileBlock WebsiteTerminalLoopback Address127.0.0.1Website BlockingDomain MappingSudo NanoPing Command
Smart Objects4 · 2 links
Medias· 2
Location· 1
Product· 1