Skip to content

Instantly share code, notes, and snippets.

@juparave
Created January 21, 2013 22:00
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 juparave/4589883 to your computer and use it in GitHub Desktop.
Save juparave/4589883 to your computer and use it in GitHub Desktop.
Building hosts files for bind9 from a list of domains in a txt file
#!/bin/bash
# 2013/01/21
# Building hosts files for bind9 from a list of domains in a txt file
DNS=some.dnsserver.net
for d in `cat domains`; do
echo "\$ttl 38400" > $d.hosts
dig +nocmd @$DNS $d any +multiline +noall +answer >> $d.hosts
for cname in 'www' 'ftp' 'mail' 'webmail'; do
dig +nocmd @$DNS $cname.$d CNAME +multiline +noall +answer >> $d.hosts
done
# now include input in /etc/bind/named.conf.local
echo -e "zone \"$d\" {" >> /etc/bind/named.conf.local
echo -e "\ttype master;" >> /etc/bind/named.conf.local
echo -e "\tfile \"/var/lib/bind/$d.hosts\";" >> /etc/bind/named.conf.local
echo -e "\t};" >> /etc/bind/named.conf.local
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment