Cleaning up wildcards, regex duplicates


A lot of us keep using wildcards, e.g. a configuration file in /etc/dnsmasq.d, containing something like address=/ (IPv4) or / and address=/ (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/, 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!



function cleanregex() {
for regex in  `cat $workdir/$regexfile`
	if [[ $1 =~ $regex ]]; then
		echo "you should remove $1"

for wildcard in  `cat $dnsmasqdir/$wildcardfile`
	IFS='/' read -a address <<< "${wildcard}"
	cleanregex "${address[1]}"

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.



Pi-hole 4.2 is a more likely candidate for this because of the better implementation of wildcard. IPv4 and IPv6 can be defined by one line for both instead of a line for each type of address.


I’ve been testing the dev version, prior to version 4.1, expecting it to be in v4.1, unfortunately, it wasn’t. Big disappointment…

The new syntax has been added by Simon Kelley on my request.
From the changelog:

Implement --address=/ as (more efficient) syntactic
sugar for --address=/ and --address=/
Returning null addresses is a useful technique for ad-blocking.

The suggestion was made because it was already possible in v2.79 for NXDOMAIN.


I can believe that and going already live with 2.80 was a to big risk. I have a major problem with running the current Dev. The cause unkown and not to be reproduced by the developers.