A lot of us keep using wildcards, e.g. a configuration file in /etc/dnsmasq.d
, containing something like address=/ligatus.com/0.0.0.0
(IPv4) or / and address=/ligatus.com/::
(IPv6). This is repeated for every wildcard domain you want to block.
The only limitation is that the file cannot be named 03-pihole-wildcard.conf
because pihole -g
calls /opt/pihole/wildcard_regex_converter.sh
, witch converts all wildcards into regular expressions (regex.list
). So I called it 03-wildcard.conf
, conversion prevented.
Since pihole, as of version v4.0 doesn't use wildcards anymore (all converted), there is absolutely no logic to detect wildcards and regular expressions that do the same thing.
This script will advise you to remove obsolete wildcards. You need to change the name of your wildcard configuration file!
#!/bin/bash
basename="pihole"
workdir="/etc/${basename}"
regexfile=regex.list
dnsmasqdir=/etc/dnsmasq.d
wildcardfile=03-wildcard.conf
function cleanregex() {
for regex in `cat $workdir/$regexfile`
do
if [[ $1 =~ $regex ]]; then
echo "you should remove $1"
break
fi
done
}
for wildcard in `cat $dnsmasqdir/$wildcardfile`
do
IFS='/' read -a address <<< "${wildcard}"
cleanregex "${address[1]}"
done
sample result from my system:
The script can easily modified to do the deletions for you (using sed
)
Run the script manually, with sudo, whenever you add something to your wildcard configuration.
Enjoy...