#!/bin/bash #this script generates two zone files for two locally hosted domains. #it requires a valid, funtional account with dyndns.org, or a similar #dynamic dns service. it is designed to allow a host to be its own #primary authoritative nameserver on a dynamic ip address. your dnydns #hostname must be listed as primary nameserver with your domain registrar. #please modify the parameters of the zone files, below, to match your #local domain name, just as you would a regular zone file. this script #placed in /etc/ppp/ip-up.d for ppp links or /etc/network/if-up.d/ for #dhcp ethernet connections will allow auto updating of your dns entry. #enjoy. released under the GNU General Public Licence ADDRESS="/var/dns/dns" NUMBER=`cat /var/dns/dns` OLD="/var/dns/dnsold" OLDNUMBER=`cat $OLD` SN="/var/dns/sn" SERIAL=`cat $SN` reset(){ echo "waiting 5 minutes and checking again..." >> /var/log/syslog sleep 300 getip } getip(){ ip address show ppp0 | egrep -m 1 -o '[[:digit:]]+.[[:digit:]]+.[[:digit:]]+[.][[:digit:]]+ ' > /var/dns/dns echo "ip=`cat /var/dns/dns`" >> /var/log/syslog compip } compip(){ diff /var/dns/dns /var/dns/dnsold if [ "$?" = "0" ]; then echo "no change" >> /var/log/syslog reset else echo "address changed" >> /var/log/syslog incserial fi } incserial(){ echo "incrementing zone file serial number" >> /var/log/syslog ((SERIAL++)) echo $SERIAL > $SN writezone } writezone(){ echo "writing new zone file" >> /var/log/syslog echo '$ORIGIN'" net." > /etc/bind/db.gnuveaun echo "gnuveau 300 IN SOA gnuveau.net. shogunx.sleekfreak.ath.cx. ( $SERIAL 600 300 600 600 )" >> /etc/bind/db.gnuveaun echo " 300 IN NS sleekfreak.ath.cx." >> /etc/bind/db.gnuveaun echo " 300 IN NS ns6.gandi.net." >> /etc/bind/db.gnuveaun echo " 300 IN MX 100 mail.gnuveau.net." >> /etc/bind/db.gnuveaun echo " 300 IN A `cat /var/dns/dns`" >> /etc/bind/db.gnuveaun echo " 300 IN AAAA 3ffe:bc0:8000::4795" >> /etc/bind/db.gnuveaun echo '$ORIGIN'" gnuveau.net." >> /etc/bind/db.gnuveaun echo "mail 300 IN A `cat /var/dns/dns`" >> /etc/bind/db.gnuveaun echo "www 300 IN A `cat /var/dns/dns`" >> /etc/bind/db.gnuveaun echo "hello 300 IN AAAA 3ffe:bc0:ce9:1:205:5dff:fe5b:ec0a" >> /etc/bind/db.gnuveaun echo "new gnuveau.net zone file written" >> /var/log/syslog writezone2 } writezone2(){ echo "writing new zone file" >> /var/log/syslog echo '$ORIGIN'" com." > /etc/bind/db.gnuveauc echo "gnuveau 300 IN SOA gnuveau.com. shogunx.sleekfreak.ath.cx. ( $SERIAL 600 300 600 600 )" >> /etc/bind/db.gnuveauc echo " 300 IN NS sleekfreak.ath.cx." >> /etc/bind/db.gnuveauc echo " 300 IN NS ns6.gandi.com." >> /etc/bind/db.gnuveauc echo " 300 IN MX 100 mail.gnuveau.com." >> /etc/bind/db.gnuveauc echo " 300 IN A `cat /var/dns/dns`" >> /etc/bind/db.gnuveauc echo " 300 IN AAAA 3ffe:bc0:8000::4795" >> /etc/bind/db.gnuveauc echo '$ORIGIN'" gnuveau.com." >> /etc/bind/db.gnuveauc echo "mail 300 IN A `cat /var/dns/dns`" >> /etc/bind/db.gnuveauc echo "www 300 IN A `cat /var/dns/dns`" >> /etc/bind/db.gnuveauc echo "new gnuveau.com zone file written" >> /var/log/syslog bindrestart } bindrestart(){ cp /var/dns/dns /var/dns/dnsold /etc/init.d/bind9 restart exit } sleep 30 getip