# 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

```bash
sudo apt-get install lrzsz
sudo apt-get install sqlite3
```

Add the URL's per line for example

<table border="1" id="bkmrk-https%3A%2F%2Fraw.githubus" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>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&amp;showintro=0&amp;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

</td></tr></tbody></table>

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

```bash
sudo vi /etc/pihole/adlists.list
```

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

```bash
#!/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:

```bash
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

<table border="1" id="bkmrk-2025-03-25-21%3A53%3A21." style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td><span class="hljs-number">2025</span><span class="hljs-number">-03</span><span class="hljs-number">-25</span> <span class="hljs-number">21</span>:<span class="hljs-number">53</span>:<span class="hljs-number">21.039</span> EDT \[<span class="hljs-number">1353</span><span class="hljs-operator">/</span>T9050\] ERROR: SQLite3: <span class="hljs-keyword">no</span> such <span class="hljs-keyword">table</span>: info <span class="hljs-keyword">in</span> "SELECT value FROM info WHERE property = 'updated';" (<span class="hljs-number">1</span>) <span class="hljs-number">2025</span><span class="hljs-number">-03</span><span class="hljs-number">-25</span> <span class="hljs-number">21</span>:<span class="hljs-number">53</span>:<span class="hljs-number">21.039</span> EDT \[<span class="hljs-number">1353</span><span class="hljs-operator">/</span>T9050\] WARNING: gravity\_updated(): <span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">value</span> <span class="hljs-keyword">FROM</span> info <span class="hljs-keyword">WHERE</span> property <span class="hljs-operator">=</span> <span class="hljs-string">'updated'</span>; <span class="hljs-operator">-</span> <span class="hljs-keyword">SQL</span> error <span class="hljs-keyword">prepare</span>: <span class="hljs-keyword">SQL</span> logic error</td></tr></tbody></table>

If so just rebuild the database like this

```bash
sudo mv /etc/pihole/gravity.db /etc/pihole/gravity_backup.db
sudo pihole -g
```