Skip to main content

PiHole - Adding blocklist urls to the Gravity DB from the command-line

This is to add block list to the Gravity DB from the command line from a text file.

You will need a few things to do this

This is for allowing zmodem options if you telnet session allows it like SecurCRT that I used.

Install the following packages

sudo apt-get install lrzsz
sudo apt-get install sqlite3

Add the URL's per line for example

https://raw.githubusercontent.com/PolishFiltersTeam/KADhosts/master/KADhosts.txt
https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Spam/hosts
https://v.firebog.net/hosts/static/w3kbl.txt
https://adaway.org/hosts.txt

To add these URL's you have to add them to the following file

sudo vi /etc/pihole/adlists.list

Then create a script and call it what ever you like and put this in

#!/bin/bash

#Get all URLs from file and add them to the gravity database
while IFS= read -r url; do
sqlite3 /etc/pihole/gravity.db "INSERT INTO adlist (address, enabled, comment) VALUES ('$url', 1, 'FROM ADLIST');
"
done < /etc/pihole/adlists.list 

Docker Users

If you place the script within the working directory of pihole container you can do the following:

docker exec -it pihole chmod +x /etc/pihole/bash_script.sh
docker exec -it pihole chmod 777 /etc/pihole/adlists.list
docker exec -it pihole ./etc/pihole/bash_script.sh