The documented and generated crontab path used lowercase /usr/local/zonesync, which doesn't match the actual repo directory name on a case-sensitive filesystem.
zoneSync
What it is
zoneSync keeps BIND's list of served zones in sync between a KeyHelp-managed
primary nameserver and any number of secondary nameservers using a BIND
catalog zone. zonesync.php, run on the primary only, reads KeyHelp's zone
declarations, generates a catalog zone listing every domain, and reloads it
via rndc. From there BIND's own catalog-zone mechanism and standard
AXFR/NOTIFY propagate the zone list to the secondaries — actual zone
data transfers happen the same way they always have, via normal AXFR.
zonesync.php is the only moving part; it does not touch zone contents, only
the catalog that tells the secondaries which zones to slave.
Requirements
- BIND >= 9.11 on all hosts (catalog zone support).
- PHP >= 8.2 on the primary only.
- KeyHelp on the primary, managing zone files under its usual configuration paths.
Install on the primary
- Clone this repository to
/usr/local/zoneSync. - Copy
zonesync.conf.php.sampletozonesync.conf.phpand adjust it. Runphp zonesync.php --versionat any point to confirm you're running the expected zonesync version, orphp zonesync.php --helpfor a summary of all flags. - Verify
namedConfGlobsinzonesync.conf.phpactually match where KeyHelp declares zones on this host:The sample defaults togrep -r 'zone "' /etc/bind//etc/bind/keyhelp_domains/*.confand/etc/bind/named.conf.local— adjust the globs if this host's layout differs. - Configure your nameservers (see "Managing nameservers" below), then
apply
dist/ns1.named.conf.snippetto this host's BIND configuration. Generate the shared TSIG key once with:and paste the resulting key block into the snippet on the primary — the same key block must also be installed on every secondary.tsig-keygen zonesync-transfer - Do a dry run first:
Inspect the output, then run it for real:
php zonesync.php --dry-runphp zonesync.php - Confirm the catalog matches KeyHelp's zone list:
php zonesync.php --check - Install
dist/crontab.snippetinto the primary's crontab so the catalog is kept in sync automatically.
Managing nameservers
The server list lives in nameservers.json (not tracked in git — copy
nameservers.json.sample to get started). IP addresses are never stored;
they are resolved via DNS whenever the snippets are generated.
php zonesync.php servers:list # names, types, resolved addresses
php zonesync.php servers:add ns1.example.org [master|slave] # default: slave
php zonesync.php servers:remove ns1.example.org
php zonesync.php servers:render # regenerate dist/ snippets only
Exactly one master (the primary) is allowed. Every
servers:add/servers:remove saves the list and regenerates
dist/ns1.named.conf.snippet (primary side) and
dist/ns2-ns3.named.conf.snippet (secondary side) from the freshly
resolved addresses. The TSIG secret always stays a
REPLACE-WITH-GENERATED-SECRET placeholder — paste the real key per host
as described above.
With no slaves configured yet, the primary snippet simply omits the
also-notify clause. If a mutation leaves the list without a master (or a
server no longer resolves), the list is still saved but the snippets are
not regenerated — the command exits non-zero and says so; fix the list and
run servers:render.
Install on the secondaries
- Apply
dist/ns2-ns3.named.conf.snippetto each secondary's BIND configuration, using the same TSIG key generated on the primary. - Create the member-zone cache directory as shown in the snippet:
mkdir -p /var/cache/bind/zonesync && chown bind:bind /var/cache/bind/zonesync - Check the configuration and reload:
named-checkconf rndc reload - Verify the catalog zone transferred:
dig @localhost catalog.zonesync SOA - Confirm member zones are being picked up:
and query one of the existing domains to confirm it resolves from this host.
rndc zonestatus <zone>
Verification & rollout test
- Add a throwaway domain in KeyHelp on the primary.
- Wait up to one minute (the cron interval from
dist/crontab.snippet), then confirm the domain resolves on every secondary. - Delete the throwaway domain in KeyHelp and confirm it disappears from the secondaries as well.
Migration from bindAPI
If these hosts previously ran bindAPI, once zoneSync has been verified end to end on all of them:
- Remove bindAPI's cron job or systemd unit (whichever each host uses).
- Remove bindAPI's vhosts and its database.
- Remove the
/etc/bind/local.zonesinclude and any stub zone files it installed on the secondaries.
Troubleshooting
- Cron mails stderr output on failure — check the crontab's mail
destination if
dist/crontab.snippetstops working silently. - zonesync.php logs to syslog under the
zonesynctag; check syslog/journal for run history and errors. - Run
php zonesync.php --checkat any time to detect drift between KeyHelp's zone list and the installed catalog without changing anything. - Run
php zonesync.php --verboseto narrate what a run is doing. - Run
php zonesync.php --helpfor a full usage summary, orphp zonesync.php --versionto confirm which zonesync version is installed.