In this post, I’m installing PiHole on a RPi. You will need Docker on your Rpi (there is a post here about it).

– Create a directory for the application

mkdir ~/apps/pihole

– Create a start-up script in that directory:

cd ~/apps/pihole
vi pihole.sh

– Paste the following script (replace the TZ and WEBPASSWORD values):

#!/bin/bash

docker pull pihole/pihole:latest
docker container stop pihole
docker rm pihole

docker run -d \
    --name pihole \
    -p 53:53/tcp -p 53:53/udp \
    -p 80:80 -p 67:67/udp \
    -p 443:443 \
    -e TZ="Asia/Bangkok" \
    -e WEBPASSWORD="piholeadmin" \
    -v "$(pwd)/etc-pihole/:/etc/pihole/" \
    -v "$(pwd)/etc-dnsmasq.d/:/etc/dnsmasq.d/" \
    --dns=127.0.0.1 --dns=8.8.8.8 \
    --restart=unless-stopped \
    pihole/pihole:latest

printf 'Starting up pihole container '
for i in $(seq 1 20); do
    if [ "$(docker inspect -f "{{.State.Health.Status}}" pihole)" == "healthy" ] ; then
        printf ' OK'
        echo -e "\n$(docker logs pihole 2> /dev/null | grep 'password:') for your pi-hole: https://${IP}/admin/"
        exit 0
    else
        sleep 3
        printf '.'
    fi

    if [ $i -eq 20 ] ; then
        echo -e "\nTimed out waiting for Pi-hole start start, consult check your container"
        echo -e "logs for more info (\`docker logs pihole\`)"
        exit 1
    fi
done;

Make it executable

chmod u+x pihole.sh

– Stop and disable `systemd-resolved.service`:

sudo systemctl stop systemd-resolved
sudo systemctl disable systemd-resolved

– Reset `/etc/resolv.conf`:

sudo rm /etc/resolv.conf
echo "nameserver 127.0.0.1" | sudo tee /etc/resolv.conf
echo "nameserver 8.8.8.8" | sudo tee -a /etc/resolv.conf

– Then start it:

./pihole.sh

– You can browse and login on http://<rpi-ip-address>/admin
That’s all needed. Enjoy!