wiki'd

by JoKeru

HomeMade DynDNS

The solution is simple:

  • on the server (10.20.30.40) hosting the DNS Server (bind) we'll create a listener (a nc infinite loop) that will update & reload the service when there is an IP change on the client
  • on the client having dynamic IP we'll configure a cronjob that will feed the listener with the current IP address

on Client (OpenWRT)

$ cat <<'EOF' > /root/dyndns.sh
#!/bin/ash
domain='jokeru.ro'
device='openwrt'
ip=$(ifconfig ppp0 | grep inet | awk '{print $2}' | cut -d':' -f2)
echo "$domain:$device:$ip" | nc 10.20.30.40 53053
EOF
$ chmod +x /root/dyndns.sh
$ crontab -e # add /root/dyndns.sh

on Server (Ubuntu)

$ cat <<'EOF' > /etc/bind/jokeru/dyndns.sh
#!/bin/bash

out='/etc/bind/jokeru/dyndns'

while :
do
 in=$(nc -n -l -p 53053)
 domain=$(echo $in | cut -d':' -f1)
 host=$(echo $in | cut -d':' -f2)
 ip=$(echo $in | cut -d':' -f3)
 if [ "$domain" == "jokeru.ro" ]
 then
  new="$host IN A $ip"
  old=$(cat $out)
  if [ "$new" != "$old" ]
  then
   /etc/init.d/bind9 reload
   echo $new > $out
  fi
 fi
done
EOF
$ chmod +x /etc/bind/jokeru/dyndns.sh
$ echo '/etc/bind/jokeru/dyndns.sh' >> /etc/rc.local
$ /etc/bind/jokeru/dyndns.sh &

Comments