Hosts File to Domain List Conversion Using Notepad++ – Quick Guide
If you use DNS-level ad blocking (like AdGuard Home in hosts-only mode), a clean domain-only list is faster and more efficient than a traditional hosts file.
This guide shows how to convert a typical hosts file (like AdAway) into a pure domain list using Notepad++.
Why Convert to Domain-Only?
A standard hosts file looks like this:
127.0.0.1 ads.example.com
0.0.0.0 tracker.example.org
But DNS tools like AdGuard Home don’t need the IP part. A cleaner version:
ads.example.com
tracker.example.org
Benefits:
- Faster parsing
- Lower memory usage
- Cleaner and easier to maintain
- Ideal for high-performance DNS setups
What You Need
- Notepad++ installed
- A hosts file (e.g., AdAway hosts list)
Step-by-Step Guide
1. Open Your Hosts File
- Launch Notepad++
- Open your hosts file (
hosts.txt)
2. Remove Comments
Comments start with # and are not needed.
- Press Ctrl + H
- Set Search Mode → Regular expression
Find:
^#.*\R
Replace with: (leave empty)
Click Replace All
3. Remove Localhost Entries
These lines are unnecessary for DNS filtering.
Find:
^.*localhost.*\R
Replace with: (empty)
Click Replace All
4. Remove IP Addresses (Keep Only Domains)
Now extract only the domain part.
Find:
^(?:\d{1,3}\.){3}\d{1,3}\s+(.+)$
Replace with:
\1
Click Replace All
5. Remove Empty Lines
Clean up leftover blank lines.
Find:
^\s*\R
Replace with: (empty)
Click Replace All
Optional: Remove Duplicate Domains
- Go to Edit → Line Operations → Remove Duplicate Lines
This reduces file size and improves performance.
Final Result
You now have a clean domain list:
ads.example.com
tracker.example.org
analytics.site.com
Where to Use This
This format works best with:
- AdGuard Home (hosts-only mode)
- DNS-based blockers
- Custom DNS filtering setups
Pro Tip
If you combine multiple lists:
- Always remove duplicates
- Keep the file sorted
- Avoid overly large lists unless necessary