This post contains scripts, or links to scripts, that are untested by the Pi-hole team. We encourage users to be creative, but we are unable to support any potential problems caused by running these scripts
Have you ever wondered how to delete a client from Pi-hole?
Just follow these simple steps:
FOR EXPERTS
sqlite3 /etc/pihole/pihole-FTL.db
- sqlite>
DELETE from queries WHERE client = 'clientIP';
- Verify that you deleted the client
sqlite>SELECT * FROM queries WHERE client = 'clientIP';
There should be little to no queries as a result of the above command. - Exit SQLite: sqlite>
.exit
PLEASE NOTE:
If you are logged in as the root user, such as with sudo -su
, then you do not need to enter sudo before every command. If you are a regular user, then you must use the sudo
before every command and enter your password (if set).
- Using a text editor of your choice, create a new file in
/usr/local/bin
. Give it a name, such asrmclient
cd /usr/local/bin
sudo nano rmclient
- Copy and paste the following code below into your file:
#!/bin/bash
# rmclient
## Set Global Variables
db="/etc/pihole/pihole-FTL.db"
log="/var/log/pihole.log"
# Pre Run Checks
if [[ $(id -u) -ne 0 ]]; then
echo "Please run as root"
exit 1
elif [ "$#" -lt 1 ]; then
exit 1
elif [ "$#" -gt 1 ]; then
echo "ONLY ONE ARGUMENT PERMITTED"
exit 1
elif [ ! -f "$db" ]; then
echo "NO DATABASE"
exit 1
fi
# Verify the IP Address
ip="$1"
if [[ "$ip" =~ ^(([1-9]?[0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))\.){3}([1-9]?[0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))$ ]]; then
# Delete the client from the database
echo "DELETING CLIENT FROM DATABASE"
sqlite3 "$db" "DELETE from queries WHERE client = '$ip';" && sed -i '/"$ip"/d' "$log"
if [ $? = 0 ]; then
echo "CLIENT SUCCESSFULLY DELETED"
#service pihole-FTL reload
fi
else
echo "INVALID IP ADDRESS"
exit 1
fi
- Save the file (using nano):
[CTL]+[X]
[Y]
[ENTER]
- Give the file execute permissions
sudo chmod a+x rmclient
- You're All Done! You can now delete clients from the Pi-hole database. Look at the example below:
sudo rmclient 127.0.0.1
5B. If you want to see instant results, you will have to reload FTL. Enter the command below:
sudo service pihole-FTL reload
EXTRAS
PRAGMA table_info('queries')
- Get domains for a specific client:
SELECT domain FROM queries WHERE client = '192.168.1.7';
SOURCE CODE: Click Here