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