A Guide to Blocking Unwanted Websites
Published: 2024-01-10 18:25:29

## 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 :)):
    ```bash
    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:

    ```bash
    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:

    ```bash
    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](https://github.com/feruzoripov/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](https://someonewhocares.org/hosts/hosts), [StevenBlack's Hosts](https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts), [AdAway](https://adaway.org/hosts.txt), and [PGl Yoyo](https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts;showintro=0&mimetype=plaintext).

Additional resources:

- https://en.wikipedia.org/wiki/Shock_site
- https://someonewhocares.org/hosts/
- https://github.com/StevenBlack/hosts