How regex domains are implemented?

Hello,

First off, thanks for Pi-Hole, it's convenient and useful for many purposes.

Regex matches

We were able to write 0.0.0.0 example.com lines within /etc/hosts and manage those files with dnsmasq to block websites per-domain, but not regex matches on domains.

What's the technology (software) behind regex matches on domains?

Parent domains

And does blocking profile.forum.example.com also blocks forum.example.com and example.com?

If not, is it possible to configure that somehow through Pi-hole?


I was using tinyproxy to block the parent domains as well.

But I think there's no proxies involved with regex matches on Pi-hole.

Thanks in advance.

Pi-hole uses regex to determine if a domain should be blocked. If you have a regex in your blacklists that matches to a domain, that domain is blocked by Pi-hole.

When Pi-hole blocks a domain (either by a domain in one of your blocklists, an exact blacklist entry, or a regex blacklist entry), it returns the NULL IP (by default) to the client.

No. Typically a regex is written for the higher level domain, and extends to domains that emanate from the higher level domain.

If you enter example.com as a wildcard blacklist entry in Pi-hole, that will result in the following regex being generated:

(\.|^)example\.com$

This will block all three domains you listed.

root@nanopi:~# dig +short example.com @127.0.0.1
0.0.0.0

root@nanopi:~# dig +short profile.forum.example.com @127.0.0.1
0.0.0.0

root@nanopi:~# dig +short forum.example.com @127.0.0.1
0.0.0.0

root@nanopi:~# pihole -q example.com
 Match found in regex blacklist
   (\.|^)example\.com$

If you want to block the forum.example.com domains and subdomains, then expand the regex to:

(\.|^)forum\.example\.com$

root@nanopi:~# dig +short example.com @127.0.0.1
93.184.216.34

root@nanopi:~# dig +short profile.forum.example.com @127.0.0.1
0.0.0.0

root@nanopi:~# dig +short forum.example.com @127.0.0.1
0.0.0.0
2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.