Skip to main content

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 

Screenshot_2023-10-25_001408.png

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

Screenshot_2023-10-25_001900.png

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. 

Screenshot_2023-10-25_002323.png

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

Screenshot_2023-10-25_002645.png

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

Screenshot_2023-10-25_003416.png

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

Screenshot_2023-10-25_003730.png

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. 

Screenshot_2023-10-25_004018.png

gravity-sync pull - Pulls the config from another Pi-Hole to this Pi-Hole.

Screenshot_2023-10-25_210818.png

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

Screenshot_2023-10-25_212227.png

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.

Screenshot_2023-10-25_212547.png

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 

Screenshot_2023-10-26_003602.png

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.