Syncing two pihole instances.

Why would you need two piholes?

I run a combo of pihole+unbound, which means that my pihole besides blocking some bad stuff also resolves DNS locally. What happens if your DNS server stop working? your whole internet goes down.

The solution then is add more piholes. My current setup is one pihole (in a raspberry pi) and a second pihole (in a VM; in Unraid if that matters). The problem is that if you make your own modifications to your primary pihole those modifications won’t be in your second pihole. Hence, syncing the two pihole instances.

Here is the script; probably won’t be as complete as Gravity Sync but wanted to give this a go myself anyway!

BKP_DATE=$(date +%Y%m%d_%H%M%S)
PIHOLE_ORIGIN_IP=192.168.0.10
PIHOLE_ORIGIN_USER=pi
LOCAL_USER=pep
PIHOLE_LOCAL_CONFIG=/home/pep/docker/config/pihole
GRAVITYDB_ORIGIN_PATH=/home/pi/docker/config/pihole/etc-pihole/gravity.db
GRAVITYDB_LOCAL_PATH=/home/pep/docker/config/pihole/etc-pihole/gravity.db
GRAVITYDB_LOCAL_BACKUP_PATH=/home/pep/docker/config/gravity.db.bkp.${BKP_DATE}
CNAMECONF_ORIGIN_PATH=/home/pi/docker/config/pihole/etc-dnsmasq.d/05-pihole-custom-cname.conf
CNAMECONF_LOCAL_PATH=/home/pep/docker/config/pihole/etc-dnsmasq.d/05-pihole-custom-cname.conf
echo "stoping pihole"
docker stop pihole
sudo chown -R $LOCAL_USER $PIHOLE_LOCAL_CONFIG
sudo chgrp -R $LOCAL_USER $PIHOLE_LOCAL_CONFIG
cp -v $GRAVITYDB_LOCAL_PATH $GRAVITYDB_LOCAL_BACKUP_PATH
echo "syncing pihole's…"
scp $PIHOLE_ORIGIN_USER@$PIHOLE_ORIGIN_IP:$GRAVITYDB_ORIGIN_PATH $GRAVITYDB_LOCAL_PATH
scp $PIHOLE_ORIGIN_USER@$PIHOLE_ORIGIN_IP:$CNAMECONF_ORIGIN_PATH $CNAMECONF_LOCAL_PATH
echo "restarting pihole"
docker start pihole
view raw piholesync.sh hosted with ❤ by GitHub

What this does is basically put your gravity.db database file in your secondary pihole (the one you need to run the script from) and do the same with your custom cname.conf file.

So far it is working fine for my needs.

You will need to run this from a passwordless sudo user.

Un comentario en “Syncing two pihole instances.

Deja un comentario