Quick dynamic DNS?

Stanley Weilnau sweilnau at cnri.reston.va.us
Thu Dec 24 18:14:40 UTC 2020


What you want is a program on the rPI that will query the internet to find what the current outside address is and then send that to the bind9 server.

There are several ways of doing this.  
1) Use a service and have a CNAME pointing to the DNS entry of the service. Some examples:
https://www.dynu.com/DynamicDNS/IPUpdateClient/RaspberryPi-Dynamic-DNS
http://www.darwinbiler.com/dynamic-dns-using-raspberry-pi/

2) Use a custom script that will use ntpupdate to update a dynamic zone on the bind9 server.  This is what I have done.
The script first queries the outside world for the ip address and then builds a nsupdate command set to send to the server.  I am doing this on a CentOS box, but it should work on a rPI.   I do use a key to prevent others from updating this record. 

script
———————————
#!/bin/bash
# Servers: http://dynupdate.no-ip.com/ip.php, http://www.antedes.com/getip.php, ..?
# Less straifghtforward: http://checkip.dyndns.org/, ...
IPS=http://dynupdate.no-ip.com/ip.php

DNSP=/home/demouser/DNS_KEY

# First, retrieve IP address
CURIP=`curl -s $IPS | awk '{ print $1 }'`
OLDIP=`cat $DNSP/oldip`  
echo $OLDIP
# Compare to previously saved IP
[ "$CURIP" == "$OLDIP" ] && exit
echo $CURIP > $DNSP/oldip
echo `date` $CURIP >> $DNSP/oldips
echo $CURIP
# If different, tell DNS
echo "server mybind9serverIP" > $DNSP/zone
echo "zone dyn.example.com" >> $DNSP/zone
echo "update delete rpi.dyn.example.com. A" >> $DNSP/zone
echo "update add rpi.dyn.example.com. 3600  A $CURIP" >> $DNSP/zone
echo "show" >> $DNSP/zone
echo "send" >> $DNSP/zone
echo "before nsupdate"
/usr/bin/nsupdate -k $DNSP/Krpi.dyn.example.com.+157+02083.private $DNSP/zone IN external


-----------------
bind config entry

        zone “dyn.example.com" {
                type master;
                file "master/external/dyn.example.com";
                allow-update {key rpi.dyn.example.com.; };
                inline-signing yes;
                auto-dnssec maintain;
                key-directory "/keys/dyn.example.com/";





More information about the bind-users mailing list