A powerful and efficient tool for downloading, optimizing, and organizing blocklists for Pi-hole
Key Features β’ Installation β’ Quick Start β’ Configuration β’ Usage β’ Documentation β’ Contributing
- What Does This Tool Do?
- Key Features
- System Requirements
- Installation
- Quick Start
- Configuration
- Usage
- Output Directory Structure
- Using with Pi-hole
- Performance Notes
- Screenshots
- Troubleshooting
- Contributing
- License
- Acknowledgements
This tool helps you maintain comprehensive blocklists for Pi-hole by:
- Downloading blocklists from multiple sources
- Optimizing them by removing duplicates and invalid entries
- Organizing them into categories (advertising, tracking, malicious, etc.)
- Combining them into ready-to-use production lists
- External Configuration: Blocklists are defined in an external configuration file for easy management
- Multi-Format Support: Handles all common blocklist formats:
- Standard hosts format (
0.0.0.0 domain.com
) - AdBlock syntax (
||domain.com^
) - Plain domain lists
- Standard hosts format (
- Intelligent Processing:
- Preserves the original format of well-structured lists
- Retains valuable metadata (title, version, modification date)
- Maintains logical grouping from source lists
- Quality Control:
- Validates all entries as proper domains
- Removes duplicate domains across all lists
- Performance Optimized:
- Multi-threaded downloading for faster operation
- Efficient memory usage even with millions of domains
- Production-Ready Output:
- Creates optimized combined lists for each category
- Generates a master list of all unique domains
- Detailed Reporting:
- Provides comprehensive statistics about downloaded lists
- Tracks successful and failed downloads
- Error Recovery:
- Automatically comments out failed lists in the configuration file
- Continues processing despite individual list failures
- Python 3.6 or higher
- Required Python packages (automatically installed by the wrapper scripts):
- requests
- tqdm
- Clone the repository:
git clone https://github.com/zachlagden/Pi-hole-Blocklist-Optimizer
cd Pi-hole-Blocklist-Optimizer
- Make the scripts executable (Linux/macOS only):
chmod +x pihole_download.sh
-
Download or copy these files:
pihole_downloader.py
(Main Python script)pihole_download.sh
(Linux/macOS wrapper script)pihole_download.bat
(Windows wrapper script)blocklists.conf
(Configuration file)
-
Ensure you have Python 3.6+ installed
-
Install the required dependencies:
pip install requests tqdm
Linux/macOS:
./pihole_download.sh
Windows:
pihole_download.bat
That's it! The script will:
- Create necessary directories
- Download blocklists from the configuration file
- Optimize and categorize them
- Create production-ready lists in
pihole_blocklists_prod/
The blocklists are defined in blocklists.conf
. Each line has this format:
url|name|category
For example:
https://adaway.org/hosts.txt|adaway|advertising
Where:
- url: The URL of the blocklist
- name: A descriptive name (used for the filename)
- category: The category of the blocklist (advertising, tracking, malicious, etc.)
Lines starting with #
are comments and will be ignored. Lists that failed to download will be automatically commented out with #DISABLED:
.
The default configuration includes these categories:
advertising
: Ad networks and servicestracking
: User tracking and analyticsmalicious
: Malware, phishing, and scam sitessuspicious
: Potentially unwanted contentnsfw
: Adult contentcomprehensive
: Multi-category lists
You can add your own categories by simply using them in the configuration file.
Linux/macOS:
./pihole_download.sh
Windows:
pihole_download.bat
You can run the Python script directly with additional options:
python3 pihole_downloader.py --threads 8 --verbose
usage: pihole_downloader.py [-h] [-c CONFIG] [-b BASE_DIR] [-p PROD_DIR] [-t THREADS] [--skip-download] [--skip-optimize] [-v] [-q]
Pi-hole Blocklist Downloader and Optimizer
options:
-h, --help show this help message and exit
-c CONFIG, --config CONFIG
Configuration file (default: blocklists.conf)
-b BASE_DIR, --base-dir BASE_DIR
Base directory for raw and optimized lists (default: pihole_blocklists)
-p PROD_DIR, --prod-dir PROD_DIR
Production directory for combined lists (default: pihole_blocklists_prod)
-t THREADS, --threads THREADS
Number of download threads (default: 4)
--skip-download Skip downloading files (use existing files)
--skip-optimize Skip optimization (just download)
-v, --verbose Enable verbose logging
-q, --quiet Suppress all output except errors
The tool creates the following directory structure:
pihole_blocklists/
βββ advertising/ # Individual advertising blocklists
βββ tracking/ # Individual tracking blocklists
βββ malicious/ # Individual malicious/security blocklists
βββ suspicious/ # Individual suspicious blocklists
βββ nsfw/ # Individual NSFW blocklists
βββ comprehensive/ # Individual comprehensive blocklists
pihole_blocklists_prod/
βββ all_domains.txt # Combined list of all unique domains
βββ advertising.txt # Combined advertising domains
βββ tracking.txt # Combined tracking domains
βββ malicious.txt # Combined malicious domains
βββ suspicious.txt # Combined suspicious domains
βββ nsfw.txt # Combined NSFW domains
The optimized lists in pihole_blocklists_prod/
are ready to be used with Pi-hole. You can:
Host the files on a web server and add the URLs to Pi-hole's blocklist settings.
Copy the files to Pi-hole's custom list directory:
# On your Pi-hole device
sudo cp pihole_blocklists_prod/*.txt /etc/pihole/
sudo pihole restartdns
Use these files as a reference to create your own specialized blocklists based on your needs.
- The default configuration includes ~50 blocklists with over 6 million unique domains
- Processing all lists typically takes 60-90 seconds on modern hardware
- Memory usage scales with the number of domains (expect ~1GB for full processing)
- For low-memory systems, consider processing fewer lists or categories
Issue | Solution |
---|---|
Connection Errors | Check your internet connection and proxy settings |
Memory Errors | Reduce the number of lists or increase available memory |
Permission Errors | Ensure you have write permissions in the script directory |
Python Errors | Make sure you have Python 3.6+ and required packages installed |
Check pihole_downloader.log
for detailed information about any errors.
Lists that fail to download will be commented out in the configuration file with #DISABLED:
prefix.
Review pihole_blocklists/blocklist_stats.txt
for detailed statistics and error information.
Contributions are welcome! Here's how you can help:
- Report bugs or suggest features by opening an issue
- Fix bugs or implement features by submitting a pull request
- Improve documentation by submitting updates to the README or other docs
- Share the project with others who might find it useful
# Clone the repository
git clone https://github.com/zachlagden/Pi-hole-Blocklist-Optimizer
cd Pi-hole-Blocklist-Optimizer
# Set up a virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install requests tqdm
This project is licensed under the Unlicense - see the UNLICENCE file for details. This means you are free to use, modify, distribute, and do whatever you want with this software with no restrictions.
- This tool builds upon the great work of various blocklist maintainers listed in the configuration file
- Special thanks to the Pi-hole team for creating such a useful ad-blocking tool