Gravity Sync - Sync Settings Across Multiple Pi-Hole
Gravity Sync is a tool designed for users who operate multiple Pi-hole instances on their network, to ensure consistent configuration across all Pi-hole installations. It syncs blocklist, whitelist, DNS, DHCP, and more settings between these multiple Pi-hole setups.
You can learn more about the Gravity Sync project at https://github.com/vmstan/gravity-sync
Installing Gravity Sync
Installing Gravity Sync is very straightforward. You will need to run the installer on all your Pi-Hole installations that you want to keep in sync.
SSH into your Pi-Hole installation, and run the following command:
curl -sSL https://raw.githubusercontent.com/vmstan/gs-install/main/gs-install.sh | bash
The installer will asked for the Remote Pi-Hole host settings. Enter the information, and the installer will continue.
Gravity Sync installer will also create a new RSA keypair to use for SSH into other Pi-hole installations. If your remote Pi-Hole uses key authentication only, the Detecting remote Pi-Hole installation step may fail, like mine in the picture below, We will get to fixing that later.
The newly created RSA key pair is located at /etc/gravity-sync/gravity-sync.rsa.pub .
On your primary Pi-Hole installation, use the cat command to view the public key, and copy it down for now.
cat /etc/gravity-sync/gravity-sync.rsa.pub
Login to your secondary Pi-Hole installation, and append the primary Pi-Hole's public key to the authorized_keys file, using a text editor such as nano or vim, or use the following command:
echo "ssh-rsa the_primary_pi-hole_gravity_sync_RSA_public_key" >> ~/.ssh/authorized_keys
Repeat the above two steps, but this time, copy the secondary Pi-Hole's gravity sync created RSA public key to the primary Pi-Hole.
Once done, you can run gravity sync config on all the Pi-Hole installations to reconfigure gravity sync, and this time, Detecting remote Pi-Hole installation step should be successful.
gravity-sync config
Gravity Sync Push and Pull
To start syncing the Pi-Hole installations through Gravity Sync, you can use either the Push or Pull option to sync the settings across.
gravity-sync push - Pushes the config from this Pi-Hole to the other Pi-Hole installations.
gravity-sync pull - Pulls the config from another Pi-Hole to this Pi-Hole.
Automate Gravity-Sync
Automating Gravity-Sync so that it can automatically push or pull the config is as easy as running the following command:
gravity-sync auto
You can also use the following options if you want Gravity Sync to run on a longer timer instead of the default 5 minutes interval:
gravity-sync auto hour for hourly intervals.
gravity-sync auto half for half-hour intervals.
gravity-sync auto quad for quarter-hour intervals.
The gravity-sync auto creates an systemd file to automate the sync. You can view the systemd file at /etc/systemd/system/gravity-sync.service
cat /etc/systemd/system/gravity-sync.service
You can fine-tune the automated gravity-sync command to do a pull only or push only action by modifying the ExecStart line:
#Push only Gravity Sync
ExecStart=/usr/local/bin/gravity-sync push
#Pull only Gravity Sync
ExecStart=/usr/local/bin/gravity-sync pull
This is helpful if you have any Pi-Hole instances that you want to keep in sync in one direction.