Pages

Labels

R (14) Admin (11) programming (10) Rant (6) personal (5) parallelism (3) spectrum (3) HPC (2) Modeling (2) Rcpp (2) SQL (2) amazon (2) code (2) email (2) frequency (2) git (2) plotting (2) postgresql (2) rstudio (2) school (2) C++ (1) DNS (1) Egypt (1) Flying Cars (1) Future (1) Internet (1) LVM (1) Mubarak (1) Music (1) Obama (1) Politics (1) Python (1) RAID (1) Reproducible Research (1) Science (1) Teaching (1) animation (1) apache (1) aws (1) cloud (1) data (1) ebay shame phone nyt (1) ec2 (1) economics (1) eff (1) encryption (1) example (1) graphing (1) hardware (1) https (1) knitr (1) knoxville xmas08 mobile pic (1) link (1) linux (1) math (1) performance (1) pki (1) plyr (1) security (1) ssh (1) syntax (1) tech audio (1) ubuntu (1) useR (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}"