Skip to content

Instantly share code, notes, and snippets.

@jdkelleher
Last active December 3, 2023 18:56
Show Gist options
  • Save jdkelleher/439d5758bbe3292d91f42c8af768ef16 to your computer and use it in GitHub Desktop.
Save jdkelleher/439d5758bbe3292d91f42c8af768ef16 to your computer and use it in GitHub Desktop.
Makefile to help manage bind zone files
#
# Makefile for managing zone updates
#
# Dependencies:
# mkrdns - https://github.com/jdkelleher/mkrdns
# zsu - https://metacpan.org/pod/release/AZS/zsu-1.20/zsu
#
BASE_DIR=/etc/bind/primary
MKRDNS=$(BASE_DIR)/mkrdns
ZSU=$(BASE_DIR)/zsu
NAMED_CONF=$(BASE_DIR)/../named.conf
# this is a link to /etc/bind/named.conf.local to be Debian friendly and avoid mkrdns running on dist provided zones
MKRDNS_NAMED_CONF=$(BASE_DIR)/local.conf
MAINTAINED_ZONE_FILES=$(wildcard $(BASE_DIR)/db.*)
MANAGED_ZONE_FILES=$(wildcard $(BASE_DIR)/managed/db.*)
all: serial rdns check reload
serial:
@# Only update serials in maintained zone files
@# Since an inplace update is perfomed, no dependency check is possible and this will always run.
@$(ZSU) -v -f $(MAINTAINED_ZONE_FILES)
rdns: .sentinel.rdns
@:
.sentinel.rdns: $(MAINTAINED_ZONE_FILES)
@# use debug output to create sentinel file
$(MKRDNS) -debug $(MKRDNS_NAMED_CONF) > $(BASE_DIR)/$@
check: rdns
@# check the full bind configuration and all includes
named-checkconf $(NAMED_CONF)
@# need to loop through both maintained and managed zone file to check zones
@# syntax is "named-checkzone <zonename> <filename>" so use perl to grab the zone name from the file
@for ZF in $(MAINTAINED_ZONE_FILES) $(MANAGED_ZONE_FILES) ; do \
named-checkzone `perl -n -e 'print if s/^.ORIGIN\s+(\S+).$$/$$1/;' $$ZF` $$ZF ; \
done
reload: check
sudo service bind9 restart
# declare all phony targets
.PHONY: serial check reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment