Convert ad-blocking filter lists to MikroTik RouterOS DNS adlist format.
Tip
Ready-to-use URL for RouterOS:
https://raw.githubusercontent.com/eugenescodes/adblock2mikrotik/refs/heads/main/hosts.txt
Transforms popular ad-blocking filter lists (Hagezi) into a compact format compatible with the MikroTik RouterOS 7.15+ DNS adlist feature. Optimized for memory-constrained low-resource devices like the RB951Ui-2nD hAP (which has 16 MB storage).
| List | Description |
|---|---|
| Hagezi Multi PRO mini | General ad/tracker blocking |
| Hagezi TIF mini | Threat intelligence feeds |
| Hagezi Gambling mini | Gambling sites |
- Converts
||example.com^rules to MikroTik DNS adlist format (0.0.0.0 example.com) - Deduplicates entries across all sources
- Validates domains against RFC label rules (rejects double-dots, leading/trailing hyphens)
- Pre-filters comments and empty lines for efficiency
- Compatible with RouterOS 7.15+
# Install uv if not already installed (macOS / Linux)
curl -LsSf https://astral.sh/uv/install.sh | sh
# Clone and run
git clone https://github.com/eugenescodes/adblock2mikrotik
cd adblock2mikrotik
uv run convert_to_hosts.pyuv run automatically creates a virtual environment and installs dependencies — no manual setup required.
docker build -t adblock2mikrotik .
# Linux / macOS
docker run --rm --user $(id -u):$(id -g) -v "$(pwd)":/output adblock2mikrotik
# Windows (PowerShell)
docker run --rm -v "${PWD}:/output" adblock2mikrotikNote
The -v flag mounts your current directory into the container at /output.
The script writes hosts.txt to /output, so the file appears directly
in your current directory on the host — no manual copying needed.
On Linux, --user $(id -u):$(id -g) ensures the output file is owned by
your current user. Not required on macOS or Windows (Docker Desktop handles this automatically).
After running either option, hosts.txt is created in the current directory.
/ip/dns/adlist add url=https://raw.githubusercontent.com/eugenescodes/adblock2mikrotik/refs/heads/main/hosts.txt ssl-verify=no
If you want to use ssl-verify=yes, you can download and import CA certificates using the following commands:
/tool fetch url=https://curl.se/ca/cacert.pem
/certificate import file-name=cacert.pem passphrase=""
/ip/dns/adlist add url=https://raw.githubusercontent.com/eugenescodes/adblock2mikrotik/refs/heads/main/hosts.txt ssl-verify=yes
See also the official MikroTik documentation:
By default, the script uses three pre-configured Hagezi filter lists. You can customize which sources are used by creating a config.toml file:
- Copy the example configuration:
cp config.toml.example config.toml- Edit
config.tomlto add or remove sources:
[sources]
urls = [
"https://raw.githubusercontent.com/hagezi/dns-blocklists/main/adblock/pro.mini.txt",
"https://raw.githubusercontent.com/hagezi/dns-blocklists/main/adblock/tif.mini.txt",
"https://raw.githubusercontent.com/hagezi/dns-blocklists/main/adblock/gambling.mini.txt",
]- Run the converter:
uv run convert_to_hosts.pyThe script will automatically load sources from config.toml. If the file doesn't exist, it falls back to the default sources above.
You can use any blocklist in AdBlock format (||domain.com^ syntax)
For more Hagezi lists, visit the Hagezi DNS blocklists repository
This project uses uv for dependency management and Ruff for linting/formatting.
Install uv (replaces pip and venv) more info about uv:
# macOS / Linux
curl -LsSf https://astral.sh/uv/install.sh | shDevelopment tools (ruff, pytest) are in the dev dependency group and need to be installed separately:
uv sync # Installs all dependencies including dev toolsuv run ruff check . --fix # lint + autofix
uv run ruff format . # formatuv run pytest -vNote
Development dependencies (ruff, pytest) are not included in the Docker image.
Use uv sync locally to run linting, formatting, and tests.
The Docker image only includes production dependencies for running the converter.
- Open a GitHub issue to discuss major changes before starting work.
- Fork the repo and create a feature branch:
git checkout -b feature/your-feature - Make your changes and run tests:
uv run pytest -v - Commit with a clear message and push to your fork.
- Open a Pull Request targeting
mainwith a description of what and why.
- Hagezi for maintaining comprehensive filter lists
- MikroTik for the DNS adlist feature in RouterOS 7.15+
This tool is not affiliated with MikroTik.