Hosts Script — Unified Hostlist Generator
15 Jun 2021
• 2 min read
Hosts Script is a Bash-based utility that generates a unique, sorted, and consolidated hosts blocklist from multiple sources.
Hosts Script is a Bash-based utility that generates a unique, sorted, and consolidated hosts blocklist from multiple sources.
It supports combining:
- Existing hosts-formatted lists
- Plain domain/IP lists
The output can be directly used as a system hosts file or as an input for DNS-based blocking solutions.
How It Works
- Fetches multiple hostlist sources defined by the user
- Normalizes domains into a hosts-style format
- Removes duplicates
- Sorts entries for consistency
- Redirects all blocked domains to a configurable local address (default:
0.0.0.0)
The script helps maintain a clean, minimal, and deterministic blocklist from multiple upstream sources.
Features
- Merge multiple hostlist sources
- Deduplicate and sort entries
- Generate hosts-formatted blocklists
- Configurable redirect IP
- Simple plain-text configuration
- Lightweight and dependency-free (Bash only)
Configuration
| Parameter | Description |
|---|---|
LOCAL_HOST | Local IP to redirect blocked domains (default: 0.0.0.0) |
OUTPUT_HOST | Output file name (default: hosts.txt) |
source.list | Hosts-formatted sources |
source.domain | Plain domain/IP sources |
Source File Format
source.list
Hosts-formatted entries only:
TEXT
0.0.0.0 www.example.com
0.0.0.0 www.evil.comsource.domain
Domain or IP only:
TEXT
www.example.com
www.evil.comIf a source file contains only one entry, add an extra empty line at the end (known script limitation).
Usage
- Clone the RepositoryBASH
git clone https://github.com/patkarmandar/Hosts cd Hosts - Add Source Lists
- Add hosts-formatted sources or links to
source.list - Add plain domains/IPs or links to
source.domain - One entry per line
- Add hosts-formatted sources or links to
- Run the ScriptBASH
bash generate.sh - Output
- The generated hosts blocklist will be available as:
hosts.txt
- The generated hosts blocklist will be available as:
- You can append or replace it in:
/etc/hosts(Linux/macOS)- System DNS or Pi-hole
- Custom DNS filtering tools
Curated Hosts Lists
| Category | Description |
|---|---|
| Porn | Porn sites + ads |
| Trackers | MIUI & Microsoft trackers |
| Facebook domains | |
| Google domains | |
| Instagram domains | |
| LinkedIn domains | |
| Twitter/X domains | |
| WhatsApp domains |
Credits & Sources
This project aggregates and processes data from the following sources:
- Steven Black Hosts
- Pornaway
- Fanboy Hosts
- Energized.pro
- LukeSmithxyz Hosts
All credit goes to the original maintainers of these lists.
Use Cases
- System-level ad blocking
- Privacy hardening
- DNS sinkhole input (Pi-hole, AdGuard)
- Social media blocking
- Tracker & telemetry reduction
