Table of Contents

Convert tinydns data format to zone file format described by RFC 1035 (bind-style)

This simple script converts the content of tinydns' data file into separate zone files - one zone file per domain. The major conversion is done by the axfrdns program which is part of djbdns.

Requirements

Setting up axfrdns

Use axfrdns-conf. Make sure that the user account gaxfrdns and the group gdnslog exists. The following lines will set up axfrdns to listen on 127.0.0.1 and to control the process via daemontools.

axfrdns-conf gaxfrdns gdnslog /etc/axfrdns /etc/tinydns 127.0.0.1
ln -s /etc/axfrdns /etc/service

Conversion Script

#!/bin/bash

set -e
cd /etc/tinydns/root
make
mkdir -p zone
SERIAL=$(date +%Y%m%d)01
grep "^\." data | cut -d: -f1 | uniq | cut -c2- | while read domain; do
   echo -e "; vim\\x3a ts=8" > zone/$domain.zone
   echo -e '$TTL 86400\n' >> zone/$domain.zone
   dig +nostats +onesoa +nocmd @127.0.0.1 AXFR $domain | \
   sed -e "s/\(.*\)2560\(.*SOA\t[^ ]\+ [^ ]\+ \)[0-9 ]\+/\1259200\2(\n\t$SERIAL ; serial\n\t3H         ; refresh\n\t1H         ; retry\n\t3W         ; expire\n\t600)       ; ttl neg caching/" >> zone/$domain.zone
done