Skip to content

Instantly share code, notes, and snippets.

@suominen
Created April 25, 2023 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suominen/40072c4226768ec541fcd549796d9efa to your computer and use it in GitHub Desktop.
Save suominen/40072c4226768ec541fcd549796d9efa to your computer and use it in GitHub Desktop.
Fix large TTLs in signed zones (BIND)
#!/bin/sh
#
# Fix signed zones with excessively high TTLs
#
# 20230425 Kimmo Suominen
#
set -eu
PATH=/bin:/usr/bin
export PATH
get_zone()
{
case "${1}" in
2[0-9a-f][0-9a-f][0-9a-f].*.rev)
printf '%s.ip6.arpa\n' "$(rev_ipv6 "${1}")"
;;
*.rev)
printf '%s.in-addr.arpa\n' "$(rev_ipv4 "${1}")"
;;
*)
echo "${1}"
;;
esac
}
rev_ipv4()
{
echo "${1}" \
| tr . \\n \
| tac \
| sed 1d \
| paste -d . -s
}
rev_ipv6()
{
local line
echo "${1}" \
| sed 's/\.rev$//' \
| tr . \\n \
| while read line
do
printf '%04x' "0x${line}"
done \
| rev \
| sed 's/\(.\)/\1./g' \
| sed 's/\.$//'
}
cd /var/cache/bind/pri
for file in *.signed
do
base="$(basename "${file}" .signed)"
zone="$(get_zone "${base}")"
# printf '%35s %-35s\n' "${file}" "${zone}"
# continue
if ! named-checkzone -l 86400 -f raw -j "${zone}" "${file}"
then
dnssec-signzone \
-K ../keys \
-M 86400 \
-N increment \
-I raw \
-O raw \
-o "${zone}" \
"${file}" \
&& mv "${file}" "${file}.OLD" \
&& mv "${file}.signed" "${file}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment