Giter VIP home page Giter VIP logo

pihole-gravity-optimise's Introduction

Optimise Pihole's gravity database

11/05/2020 Update

As of yesterday, Pi-hole V5 was released and with that came the move to a database. Due to the way that the domains are now stored (including duplicates if in multiple adlists), the database size not decreasing unless a VACUUM (db rebuild) is run after each optimisation (not efficient) and the fact that a gravity update undoes all of the changes by this script, it is no longer efficient to run. I will perhaps look to tackle this from a different angle in future, but, for now, this repo will be archived.


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.

What does the script do?

  1. Identifies gravity table entries that do not match items in the regex table
  2. Identifies gravity table entries that do not match items in any DNSMASQ conf files.
  3. Creates a new, optimised gravity table

Requirements

  1. This script requires Python 3.6+ in order to run. It has been written and tested on Raspbian Buster / DietPi.
  2. The script must be run as root (sudo)

Example Output

mmotti@ubuntu-server:~$ curl -sSl https://raw.githubusercontent.com/mmotti/pihole-gravity-optimise/master/gravityOptimise.py | sudo python3
[i] Root user detected
[i] Pi-hole path exists
[i] Updating gravity (this may take a little time)
[i] DB detected
[i] Fetching domains
[i] Connecting to /etc/pihole/gravity.db
[i] Querying DB for gravity domains
[i] --> 113,492 domains found
[i] Scanning /etc/dnsmasq.d for wildcards
[i] --> 35,877 wildcards found
[i] Identifying wildcard conflicts with gravity
[i] --> 41,467 conflicts found
[i] Fetching regexps
[i] --> 16 regexps found
[i] Checking for gravity matches
[i] --> 8,100 matches found in gravity
[i] Running deletions
[i] --> 59,438 domains remain in the gravity database
[i] Restarting Pi-hole

Instructions

  • 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.

Installations:

Update your list of available packages

sudo apt-get update

Make sure the following packages are installed:

sudo apt-get install python3

Running the optimisation

curl -sSl https://raw.githubusercontent.com/mmotti/pihole-gravity-optimise/master/gravityOptimise.py | sudo python3

Running on a schedule

Example cron job that runs each night at 02:45:

  1. Edit the root user's crontab (sudo crontab -u root -e)

  2. Enter the following:

SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
45 2 * * * /usr/bin/curl -sSl https://raw.githubusercontent.com/mmotti/pihole-gravity-optimise/master/gravityOptimise.py | /usr/bin/python3
  1. Save changes

pihole-gravity-optimise's People

Contributors

mmotti avatar snapsl avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.