Skip to main content

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/hosts file 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) to 127.0.0.1.
  • βœ… Save the changes by pressing Ctrl+O, then Enter, and exit the editor with Ctrl+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 ping command (e.g., ping www.google.com) to confirm that the domain resolves to your loopback address.
  • βͺ To unblock a website, re-edit the /etc/hosts file 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