This project provides a comprehensive solution to block advertisements across various platforms (Mac, Windows, Linux, and Android) by leveraging the hosts file. The hosts file is used to map hostnames to IP addresses and can be manipulated to redirect ad-serving domains to a non-existent IP, effectively blocking ads.
- Aggregates hosts from 204+ authoritative sources
- Blocks ads, trackers, malware, phishing, and adult content
- Regular expression and wildcard support
- Automatic deduplication
- Platform-specific deployment scripts
- Supports multiple blocklist categories
- Auto-run check (24-hour throttle)
- Resume capability for interrupted downloads
| Category | Description |
|---|---|
| Ads & Trackers | Main advertising domains |
| Malware | Known malicious websites |
| Phishing | Fraud and scam sites |
| Social Media | Optional social network blocking |
| Adult | Sexual content filtering |
| Gambling | Casino and betting sites |
| Piracy | Torrent and streaming sites |
| Telemetry | Device tracking domains |
- macOS
- Windows
- Linux
- Android
# Install dependencies
pip install requests tldextract
# Run the aggregator
python3 aggregator.pyThis will download and merge all blocklists into a single hosts file.
Navigate to the appropriate directory for your platform:
| Platform | Script | Command |
|---|---|---|
| Linux | scripts/block_ads_linux.sh |
sudo ./block_ads_linux.sh |
| macOS | scripts/block_ads_mac.sh |
sudo ./block_ads_mac.sh |
| Windows | scripts/block_ads_windows.bat |
Run as Administrator |
| Android | android-scripts/README.md |
See instructions |
After running the script, restart your device or networking service:
Linux:
sudo systemctl restart systemd-resolvedmacOS:
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponderWindows:
ipconfig /flushdns- Python 3.7+
requestslibrarytldextractlibrary
The aggregator will:
- Read source URLs from
sources.txt - Download each blocklist in parallel
- Parse and extract domains
- Remove duplicates
- Generate a unified
hostsfile
python3 aggregator.pyThe aggregator saves progress to cache/state.json. If interrupted, simply run again to resume from where it left off.
The aggregator checks when it was last run:
- If more than 24 hours since last run: automatically processes all URLs
- If less than 24 hours: prompts you to confirm before running again
Edit sources.txt and add your blocklist URLs (one per line, lines starting with # are comments):
# My custom blocklist
https://example.com/my-blocklist.txt
- Standard hosts file format (
0.0.0.0 domain.com) - AdBlock-style domain lists
- Plain domain lists (one per line)
| Metric | Value |
|---|---|
| Sources | 204 blocklists |
| Unique Domains | 10,036,528 |
| Output File Size | 270 MB |
| Last Updated | March 10, 2026 |
- Clear your browser cache
- Flush DNS cache (commands above)
- Restart your device
- Check if your browser has built-in ad blocking
- Ensure you run with appropriate permissions (sudo for system hosts)
- Verify the
hostsfile exists before running deployment scripts - Check that Python dependencies are installed
Contributions are welcome! If you have improvements or additional scripts for other platforms, feel free to fork this repository and submit a pull request.
Blocking ads using the hosts file can impact the functionality of certain websites and services. Use this script responsibly and be aware of potential side effects. The maintainers of this repository are not responsible for any adverse effects on your system.
This project is provided for educational and informational purposes only. Use it at your own risk.
This project is licensed under the MIT License.