How do I add Wildcard sites to the blacklist?

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

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 * etc there in this format:


Where is your Pi-hole’s IP.

This will block all access to *

What about exceptions?

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


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 ( 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=/ (where and 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

#Exceptions below:

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


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


1 Like

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

You can have as many as you like!

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

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