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

  1. Clone this repository to /usr/local/zoneSync.
  2. Copy zonesync.conf.php.sample to zonesync.conf.php and adjust it. Run php zonesync.php --version at any point to confirm you're running the expected zonesync version, or php zonesync.php --help for a summary of all flags.
  3. Verify namedConfGlobs in zonesync.conf.php actually match where KeyHelp declares zones on this host:
    grep -r 'zone "' /etc/bind/
    
    The sample defaults to /etc/bind/keyhelp_domains/*.conf and /etc/bind/named.conf.local — adjust the globs if this host's layout differs.
  4. Configure your nameservers (see "Managing nameservers" below), then apply dist/ns1.named.conf.snippet to this host's BIND configuration. Generate the shared TSIG key once with:
    tsig-keygen zonesync-transfer
    
    and paste the resulting key block into the snippet on the primary — the same key block must also be installed on every secondary.
  5. Do a dry run first:
    php zonesync.php --dry-run
    
    Inspect the output, then run it for real:
    php zonesync.php
    
  6. Confirm the catalog matches KeyHelp's zone list:
    php zonesync.php --check
    
  7. Install dist/crontab.snippet into 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

  1. Apply dist/ns2-ns3.named.conf.snippet to each secondary's BIND configuration, using the same TSIG key generated on the primary.
  2. Create the member-zone cache directory as shown in the snippet:
    mkdir -p /var/cache/bind/zonesync && chown bind:bind /var/cache/bind/zonesync
    
  3. Check the configuration and reload:
    named-checkconf
    rndc reload
    
  4. Verify the catalog zone transferred:
    dig @localhost catalog.zonesync SOA
    
  5. Confirm member zones are being picked up:
    rndc zonestatus <zone>
    
    and query one of the existing domains to confirm it resolves from this host.

Verification & rollout test

  1. Add a throwaway domain in KeyHelp on the primary.
  2. Wait up to one minute (the cron interval from dist/crontab.snippet), then confirm the domain resolves on every secondary.
  3. 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:

  1. Remove bindAPI's cron job or systemd unit (whichever each host uses).
  2. Remove bindAPI's vhosts and its database.
  3. Remove the /etc/bind/local.zones include 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.snippet stops working silently.
  • zonesync.php logs to syslog under the zonesync tag; check syslog/journal for run history and errors.
  • Run php zonesync.php --check at any time to detect drift between KeyHelp's zone list and the installed catalog without changing anything.
  • Run php zonesync.php --verbose to narrate what a run is doing.
  • Run php zonesync.php --help for a full usage summary, or php zonesync.php --version to confirm which zonesync version is installed.
S
Description
No description provided
Readme
142 KiB
0 Stars 1 Watchers 0 Forks
v1.0.1
Latest
2026-08-20 14:06:59 +02:00
Languages
PHP 100%