Pi-Hole - 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/StevenBlack/hosts/master/hosts 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 https://v.firebog.net/hosts/AdguardDNS.txt https://v.firebog.net/hosts/Admiral.txt https://raw.githubusercontent.com/anudeepND/blacklist/master/adservers.txt https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt https://v.firebog.net/hosts/Easylist.txt https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext https://raw.githubusercontent.com/FadeMind/hosts.extras/master/UncheckyAds/hosts https://raw.githubusercontent.com/bigdargon/hostsVN/master/hosts https://v.firebog.net/hosts/Easyprivacy.txt https://v.firebog.net/hosts/Prigent-Ads.txt https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.2o7Net/hosts https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt https://hostfiles.frogeye.fr/firstparty-trackers-hosts.txt https://raw.githubusercontent.com/DandelionSprout/adfilt/master/Alternate%20versions%20Anti-Malware%20List/AntiMalwareHosts.txt https://s3.amazonaws.com/lists.disconnect.me/simple_malvertising.txt https://v.firebog.net/hosts/Prigent-Crypto.txt https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Risk/hosts https://bitbucket.org/ethanr/dns-blacklists/raw/8575c9f96e5b4a1308f2f12394abd86d0927a4a0/bad_lists/Mandiant_APT1_Report_Appendix_D.txt https://phishing.army/download/phishing_army_blocklist_extended.txt https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-malware.txt https://v.firebog.net/hosts/RPiList-Malware.txt https://v.firebog.net/hosts/RPiList-Phishing.txt https://raw.githubusercontent.com/Spam404/lists/master/main-blacklist.txt https://raw.githubusercontent.com/AssoEchap/stalkerware-indicators/master/generated/hosts https://urlhaus.abuse.ch/downloads/hostfile/ https://raw.githubusercontent.com/RPiList/specials/master/Blocklisten/child-protection https://raw.githubusercontent.com/RPiList/specials/master/Blocklisten/gambling https://raw.githubusercontent.com/mhhakim/pihole-blocklist/master/porn.txt https://raw.githubusercontent.com/RPiList/specials/master/Blocklisten/pornblock2 https://raw.githubusercontent.com/RPiList/specials/master/Blocklisten/pornblock3 https://raw.githubusercontent.com/RPiList/specials/master/Blocklisten/pornblock4 https://raw.githubusercontent.com/RPiList/specials/master/Blocklisten/pornblock5 https://raw.githubusercontent.com/RPiList/specials/master/Blocklisten/pornblock6 https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/porn/hosts https://raw.githubusercontent.com/RPiList/specials/master/Blocklisten/spam.mails
|
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
Error Check
Run the following to make sure your database is still okay and does not display any errors like these
| 2025-03-25 21:53:21.039 EDT [1353/T9050] ERROR: SQLite3: no such table: info in "SELECT value FROM info WHERE property = 'updated';" (1) 2025-03-25 21:53:21.039 EDT [1353/T9050] WARNING: gravity_updated(): SELECT value FROM info WHERE property = 'updated'; - SQL error prepare: SQL logic error |
If so just rebuild the database like this
sudo mv /etc/pihole/gravity.db /etc/pihole/gravity_backup.db
sudo pihole -g