DEV Community

Feruz Oripov
Feruz Oripov

Posted on

A Guide to Blocking Unwanted Websites

Introduction

In the vast landscape of the internet, not all websites are created equal. Some may harbor malicious content, while others could be a source of distraction. In this guide, we'll explore the importance of blocking unwanted websites and how you can safeguard your digital space.

Why Block Unwanted Websites?

The internet is a treasure trove of information and entertainment, but it also comes with its fair share of pitfalls. Blocking unwanted websites can offer several benefits:

  • Enhanced Productivity: Avoid distractions by blocking time-wasting websites during work hours.
  • Improved Security: Prevent access to potentially harmful sites that could compromise your computer's security.
  • Content Control: Ensure a family-friendly online environment by blocking inappropriate content.

Tools and Techniques

Now that we understand the importance of blocking unwanted websites, let's delve into the tools and techniques to achieve this:

  • Editing the Hosts File: The etc/hosts file on your computer can be edited to block access to specific websites. We will learn how to do this on Linux/Mac later.
  • Using Browser Extensions: Browser extensions like https://blocksite.co/ and https://www.webblockerextension.com/ allow for easy and customizable website blocking.
  • Parental Control Software: For a comprehensive solution, consider using parental control software that offers website blocking features.

Editing the Hosts File

  1. Open Terminal: On both Linux and Mac, you'll need to use the terminal to edit system files.
  2. Access the Hosts File: Run the following command in the terminal to open the etc/hosts file with a text editor (in my case I will use vim, I hope you know how to exit :)):

    sudo vim /etc/hosts
    
  3. Enter Admin Password: You'll be prompted to enter your administrator password since editing the etc/hosts file requires elevated privileges.

  4. Add Blocking Entries: To block a website, navigate to the end of the file and add an entry in the following format:

    127.0.0.1   unwantedwebsite.com
    

    Save the changes in the text editor and exit.

  5. Flush DNS Cache (Optional): To ensure changes take effect immediately, you can flush the DNS cache. Run the following command:

    sudo dscacheutil -flushcache  # For macOS
    sudo systemctl restart systemd-resolved  # For Linux (Debian-based)
    
  6. Verify Changes: Open a web browser and try accessing the blocked website. It should now be inaccessible.

Conclusion

Blocking unwanted websites is a proactive step toward creating a secure and focused digital environment. Whether you're aiming for increased productivity or maintaining a family-friendly online space, implementing these techniques can make a significant difference.

Remember, the key is to strike a balance between enjoying the internet's benefits and protecting yourself from its potential drawbacks. Happy browsing!


If you're looking for a convenient way to block unwanted websites on your computer, check out my open-source project, Block Unwanted Hosts. This tool, written in Go, fetches and blocks websites from various sources, adding them to your system's etc/hosts file for enhanced security and productivity.

Block websites from predefined sources, including Someonewhocares, StevenBlack's Hosts, AdAway, and PGl Yoyo.

Additional resources:

Top comments (1)

Collapse
 
jovidon profile image
Jovidon

Great post! Thank you for uselful informations.