bkmeneguello
9/2/2015 - 12:35 PM

Route53 Dynamic DNS

Route53 Dynamic DNS

#!/bin/bash -e

#sudo pip install cli53
#export AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXX
#export AWS_SECRET_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#export ROUTE53_HOSTS=XXXXXXXXXXXX
#export ROUTE53_DOMAIN=XXXXXXXXXXXXXXXXXXXX

# use -f to force ip change
if [[ $# -gt 0 && -n "`echo $1 | grep -- -f`" ]]; then
	FORCE=true
else
	FORCE=false
fi

LASTIP=$(cat /tmp/.lastip 2>/dev/null ||:)

IP=$(curl -s http://checkip.dyndns.com/ | grep -Eo '([0-9]{1,3}[.]?){4}')

if [[ "$LASTIP" != "$IP" || $FORCE == true ]]; then
	echo "IP changed from $LASTIP to $IP"
else
	exit
fi

for HOST in $ROUTE53_HOSTS; do
	echo "updating $HOST..."
	/usr/local/bin/cli53 rrcreate --replace --ttl 300 --wait $ROUTE53_DOMAIN $HOST A $IP
done

echo $IP > /tmp/.lastip