If you are making use of Pihole's regex filtering and/or DNSMASQ wildcards, then it's likely that your gravity domain table contains far more domains than necessary.
- Identifies gravity table entries that do not match items in the regex table
- Identifies gravity table entries that do not match items in any DNSMASQ conf files.
- Creates a new, optimised gravity table
pi@raspberrypi:~ $ gravityOptimise.sh
[i] Pi-hole DB detected
[i] Updating gravity
[i] Parsing existing wildcard config (DNSMASQ)
[i] Removing wildcard matches from gravity
[i] Removing regex matches from gravity
[i] Updating gravity database
[i] Removing temp files
[i] Refreshing Pihole
[i] 55205 domains were removed from gravity
[i] 58103 domains remain in gravity
- All commands will need to be entered via Terminal (PuTTY or your SSH client of choice) after logging in.
- Each time
pihole -g
is ran, either through updates, automatic cron or manually, any entries that were previously removed by this script will be re-added so you will need to run it regularly.
Download the script, copy it to /usr/local/bin/
and give it execution permissions:
sudo bash
wget -qO /usr/local/bin/gravityOptimise.sh https://raw.githubusercontent.com/mmotti/pihole-gravity-optimise/master/gravityOptimise.sh
chmod +x /usr/local/bin/gravityOptimise.sh
exit
Enter gravityOptimise.sh
in Terminal
This example will run the script every morning at 03:45
sudo nano /etc/cron.d/gravityOptimise
- Enter:
45 3 * * * root PATH="$PATH:/usr/local/bin/" gravityOptimise.sh
- Press
CTRL
+X
- Press
Y
- Press
Enter
pihole -g
sudo rm -f /usr/local/bin/gravityOptimise.sh
sudo rm -f /etc/cron.d/gravityOptimise
pihole -g