enira.net

We are all living in a technological wasteland.

RSS
people

NAS – Part 5: Afraid.org DNS

Introduction

The final step to my NAS is keeping my dynamic IP bound to a DNS host. I am using http://afraid.org/ to manage and handle the dynamic DNS.

This script is adapted and based on th script found at: http://adambuchanan.me/post/25473551700/dynamic-dns-with-bash-afraid-org.

Script

This following script will change all hosts assigned to your account to the current IP you are running this script from.

#!/bin/bash
 
#insert SHA-1 hash here (format): username|password
hash=""
 
info_url="http://freedns.afraid.org/api/?action=getdyndns&sha=$hash"
 
echo "Calling $info_url ..."
 
ip=$(dig @208.67.222.220 myip.opendns.com | grep "myip.opendns.com." | grep "0" | awk '{ print $5} ')
echo "Current IP is: $ip"
 
# get the current dns settings...
for each in `curl -s "$info_url"`
do
        domain=`echo "$each" | cut -d"|" -f1`
        dns_ip=`echo "$each" | cut -d"|" -f2`
 
        update_url=`echo "$each" | cut -d"|" -f3`
 
        echo "$domain ..."
        if [ "$ip" != "$dns_ip" ]
        then
                echo "Updating $dns_ip =>$ip ..."
                curl "$update_url" >> log
        fi
        echo "OK"
done

Now run this with a job in crontab to update your afraid.org DNS.

crontab -e

Leave a Reply

You must be logged in to post a comment.