How To create a DDNS (Dynamic DNS) with Bind and OpenWRT

sezione dedicata ai sistemi operativi alternativi Open Source

How To create a DDNS (Dynamic DNS) with Bind and OpenWRT

Messaggio da leggereda root » 23/10/2017, 11:01

First of all you need to configure BIND on your server to accept dynamic updates from a remote client.

To configure BIND follow this guide:
http://www.foell.org/justin/diy-dynamic-dns-with-openwrt-bind/

Important note:
your BIND server must be the authoritative DNS for the domain you want to manage,
see here: https://www.dnsknowledge.com/whatis/authoritative-name-server/

On your OpenWRT Router:

-- install bind-client package

opkg update
opkg install bind-client


-- copy the two generated files from BIND server (file.key and file.private) to your OpenWRT router (/root directory)

-- create the script to check for public IP changes and update your zone if IP has changed:

vi /root/check-ip.sh

Codice: Seleziona tutto
#!/bin/bash
NOWIPADDR="/tmp/nowipaddr"
GETIPADDR="curl http://icanhazip.com"
IP=$(curl http://icanhazip.com)
if [ -f $NOWIPADDR ]
then
if [ `cat $NOWIPADDR` = `$GETIPADDR` ]
then
echo "IP NOT changed"
else
$GETIPADDR > $NOWIPADDR
echo "IP changed"
echo "server 222.222.222.222
zone domain.com.
update delete sub.domain.com. A
update add sub.domain.com. 86400 A $IP
show
send" | nsupdate -k /root/Ksub.domain.com.+157+30338.key -v
fi
else
curl $GETIPADDR >> $NOWIPADDR
fi


Notes:
change "222.222.222.222" with your BIND server static IP public address
change "domain.com" and "sub.domain.com" with your domain and your third
level domain name you want to update
change "/root/Ksub.domain.com.+157+30338.key" with the file name (.key) generated by your BIND server


-- give the right permissions to the script:

chmod 755 /root/check-ip.sh

-- generate a crontab with crontab -e command to launch the script every 5 minutes:

Codice: Seleziona tutto
*/5 * * * * /bin/sh /root/check-ip.sh


-- insert the following two lines to "/etc/rc.local" file, right before the "exit 0" line:

Codice: Seleziona tutto
/bin/touch /tmp/nowipaddr
/bin/sh /root/check-ip.sh


reboot the router ...
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 394
Iscritto il: 10/04/2012, 10:55
Località: Turin

Torna a OpenWRT

Chi c’è in linea

Visitano il forum: Google [Bot] e 1 ospite

cron