How do I add Wildcard sites to the blacklist?


#1

Update: The functionality of this is now baked into Pi-Hole! You can either add wildcarded blacklist domains on the Web Admin UI, or from the command line by running pihole -wild example.com
 

Note: This works for blacklisting, but not for whitelisting. Hopefully it wont be too long until we can make this a native feature, but it needs to be perfected first! Any requests blocked in this way will not show as “Pi-holed” on the query page of the Web-Admin.

Create the file /etc/dnsmasq.d/02-wildcards.conf, and add in your *.domain.com etc there in this format:

address=/test.com/xxx.xxx.xxx.xxx

Where xxx.xxx.xxx.xxx is your Pi-hole’s IP.

This will block all access to *.domain.com.

What about exceptions?

For example, let’s say i’ve blacklisted .xyz with the following in /etc/dnsmasq.d/02-wildcards.conf:

address=/xyz/192.168.1.253

That works, and I can no longer connect to anything on the xyz TLD. However, I know that I want to be able to access Alphabet’s site (https://abc.xyz). In order to do this, I can either create another file (to keep things seperate (e.g /etc/dnsmasq.d/03-exceptions.conf) or add my exceptions to 02-wildcards.conf like so:

server=/abc.xyz/8.8.8.8
server=/abc.xyz/8.8.4.4 (where 8.8.8.8 and 8.8.4.4 are your chosen upstream DNS IPs)

So, to tie it all together, the entire contents of my additional config file (the name really doesn’t matter, but they are read into dnsmasq in alphanumerical order):

pi@raspberrypi:~ $ cat /etc/dnsmasq.d/02-wildcards.conf
#Block Entire XYZ TLD
address=/.xyz/192.168.1.253

#Exceptions below:
#Alphabet:
server=/abc.xyz/8.8.8.8
server=/abc.xyz/8.8.4.4

remember to reload and restart dnsmasq
sudo service dnsmasq reload
sudo service dnsmasq restart


How do I block ads on YouTube?
Blocking sub domains
Blocking whole .xyz .click ad domains possible?
Block Taboola, Outbrain, etc
Avoid ambiguity in wildcard blocking
Avoid ambiguity in wildcard blocking
Best way to "programatically" handle blocking for wildcard TLDs?
#2

Maybe a stupid question but…
Can I have multiple ‘blocks’ in same .conf-file?

I.e.

address=/.xyz/192.168.1.253
address=/.xzz/192.168.1.253
address=/.xxz/192.168.1.253

#3

There are no stupid questions here… (Well, maybe some).

You can have as many as you like!


#4

#5

What if domain test.com is in both blacklists (02-wildcards.conf & gravity.list)? Will there be some kind of conflict? Gravity.sh doesn’t check these lists for duplicates.


#6

Note that wildcard blocking is a normal feature of Pi-hole since a few versions and this solution has become obsolete.


#7