/linux-hosts-moderator

Website access control for linux

Primary LanguagePowerShellGNU General Public License v2.0GPL-2.0

Hosts Moderator

📅 Last List Update.: 2024-09-03

Note

The lists of sites are extracted from the repository StevenBlack/hosts.

This project provides scripts for blocking and unblocking access to specific websites on both Linux and Windows. Sites are organized into categories and redirected to 127.0.0.1 by modifying the hosts file.

📂 Structure

  • categories/: Contains subdirectories for each site category (e.g., social, entertainment, news, etc.);
  • Each subdirectory contains a sites_list.txt file with the list of sites to be blocked for that category.

Linux

The Linux script is written in Shell Script and uses the /etc/hosts file to redirect blocked domains.

How to Use

  1. Add the sites you want to block to the sites_list.txt files in the appropriate category subdirectories.
  2. Run the block_sites.sh script with the following options:
  • 🔒 Block all categories

    sudo ./block_sites.sh block
  • 🔒 Block a specific category

    sudo ./block_sites.sh block social
  • 🔓 Unblock all categories

    sudo ./block_sites.sh unblock
  • 🔓 Unblock a specific category

    sudo ./block_sites.sh unblock social

Important

This script requires superuser permissions to modify the /etc/hosts file. Therefore, you may need to use sudo to run it.

How to Make the Script Executable

Run the following command to make the script executable:

chmod +x block_sites.sh

Windows

The Windows script is written in PowerShell and manipulates the hosts file located at C:\Windows\System32\drivers\etc\hosts.

How to Use

  1. Add the sites you want to block to the sites_list.txt files in the appropriate category subdirectories.
  2. Open PowerShell as Administrator and run the block_sites.ps1 script with the following options:
  • 🔒 Block all categories

    .\block_sites.ps1 block
  • 🔒 Block a specific category

    .\block_sites.ps1 block social
  • 🔓 Unblock all categories

    .\block_sites.ps1 unblock
  • 🔓 Unblock a specific category

    .\block_sites.ps1 unblock social

Important

This script needs to be run as Administrator to modify the hosts file. Make sure to open PowerShell with elevated permissions.