Labels

R (15) Admin (12) programming (11) Rant (6) personal (6) parallelism (4) HPC (3) git (3) linux (3) rstudio (3) spectrum (3) C++ (2) Modeling (2) Rcpp (2) SQL (2) amazon (2) cloud (2) frequency (2) math (2) performance (2) plotting (2) postgresql (2) DNS (1) Egypt (1) Future (1) Knoxville (1) LVM (1) Music (1) Politics (1) Python (1) RAID (1) Reproducible Research (1) animation (1) audio (1) aws (1) data (1) economics (1) graphing (1) hardware (1)

Afraid.org Dynamic DNS Script for Amazon EC2

Below is a fully self-explanatory bash/crontab script that allows the use of Afraid.org Dynamic DNS from an an Amazon EC2 instance. Please let me know if you spot any errors.
It also wouldn't hurt to execute this in /etc/rc.local (just add the full path of this script to that file) so that the IP gets checked right at startup.


#! /bin/bash
## DESCRIPTION
## For Amazon EC2 Instances
## Use curl to update a dynamic dns entry for http://afraid.org
## based on http://forums.gentoo.org/viewtopic-t-468368.html
##
## INSTRUCTIONS
## FIRST, change DIRECT_URL (below) based on http://freedns.afraid.org/dynamic/
## THEN, it doesn't hurt to do the following (change permissions)
## chmod 500 /etc/cron.d/afraid.aws.sh
## sudo chown root.root /etc/cron.d/afraid.aws.sh
## NEXT, move this file to /etc/cron.d,
## FINALLY, add the following line to /etc/crontab
## */2 * * * * root /etc/cron.d/afraid.aws.sh >/dev/null

OLDIP_FILE="/tmp/ip.tmpfile"
## this is from within an instance, just returns instance public IP
## See http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/using-instance-addressing.html#concepts-instance-addressing for details
CHECK_CMD="GET http://169.254.169.254/latest/meta-data/public-ipv4"
## Find this at http://freedns.afraid.org/dynamic/
DIRECT_URL="http://freedns.afraid.org/dynamic/update.php?aEdTcVlocDIwUDhkQ0NId1ZxaWQ6NzE5NzYyOA=="
UPDATE_COMMAND="/usr/bin/curl -s $DIRECT_URL"

echo "Getting current IP"
CURRENTIP=`${CHECK_CMD}`
echo "Found ${CURRENTIP}"

if [ ! -e "${OLDIP_FILE}" ] ; then
echo "Creating ${OLDIP_FILE}"
echo "0.0.0.0" > "${OLDIP_FILE}"
fi

OLDIP=`cat ${OLDIP_FILE}`

if [ "${CURRENTIP}" != "${OLDIP}" ] ; then
echo "Issuing update command"
${UPDATE_COMMAND}
fi

echo "Saving IP"
echo "${CURRENTIP}" > "${OLDIP_FILE}"