DDNS with IPv6

My ISP provides /64 IPv6 block but it's a not a static block, so it's really annoying when I trying to  access my home server (yes, it's a raspberry pi) remotely as allocated IPv6 prefix block changes time to time. here's my solution for that

Getting the current IP
#!/bin/sh
if [ -z "$1" ]
  then
    echo "usage : ./$0 <iface>"
else
    ip -o -6 addr show $1 | sed -e 's/^.*inet6 \([^ ]\+\).*/\1/' | grep '/128' | awk -F '/' '{print $1}'
fi
I am using freedns.afraid.org as my DDNS provider (it's free), this is my script to run as a cron job to update latest IPv6 address
#!/bin/sh
ip6_addr=`./get-addr-dialog-bb.sh eth0` #
last_ip6_addr=`cat ./.last_ip6_addr 2> /dev/null`
host=`hostname -f`
auth='<user>:<password>' # freedns.afraid.org credentails
if [ "$ip6_addr" != "$last_ip6_addr" ] 
then
    curl -k "https://freedns.afraid.org/nic/update?hostname=$host&myip=$ip6_addr" --user $auth
    echo "$ip6_addr" > ./.last_ip6_addr
else
    echo "Address $ip6_addr has not changed"    
fi

Comments

Popular posts from this blog

Consuming a RESTful Web Service with C++ using QT libraries

How to develop CXF based JAX-WS with WSO2 Developer Studio

Quick Start Apache Stratos from EC2 images