Skip to content

Instantly share code, notes, and snippets.

@Sitebase
Forked from larrybolt/cf-ddns.sh
Last active August 29, 2015 14:06
Show Gist options
  • Save Sitebase/8552675cb5401fb42791 to your computer and use it in GitHub Desktop.
Save Sitebase/8552675cb5401fb42791 to your computer and use it in GitHub Desktop.
#!/bin/sh
# modified by jfro from http://www.cnysupport.com/index.php/linode-dynamic-dns-ddns-update-script
# Update: changed because the old IP-service wasn't working anymore
# Uses curl to be compatible with machines that don't have wget by default
# modified by Ross Hosman for use with cloudflare.
#
# Place at:
# /usr/local/bin/cf-ddns.sh
# if you're lazy (like me): curl https://gist.githubusercontent.com/Sitebase/8552675cb5401fb42791/raw/e646241fd4fc14a0736eab6b5422ba97a3c1d242/cf-ddns.sh > /usr/local/bin/cf-ddns.sh && chmod +x /usr/local/bin/cf-ddns.sh && vim /usr/local/bin/cf-ddns.sh
# run `crontab -e` and add next line:
# 0 */5 * * * * /usr/local/bin/cf-ddns.sh >/dev/null 2>&1
# Configuration
CLOUDFLARE_KEY="your-api-key"
CLOUDFLARE_USER="[email protected]"
CLOUDFLARE_HOST="my.site.com"
WAN_TMP_FILE=$HOME/.wan_ip
# Fetch public IP
WAN_IP=`dig +short myip.opendns.com @resolver1.opendns.com`
# Helper function
function log()
{
logger -t MyDynDNS $1
}
OLD_WAN_IP=""
if [ -f $WAN_TMP_FILE ]; then
OLD_WAN_IP=`cat $WAN_TMP_FILE`
fi
if [ "$WAN_IP" = "$OLD_WAN_IP" ]; then
log "Public IP not changed"
else
echo $WAN_IP > $WAN_TMP_FILE
log "Public IP is changed, update CloudFlare entry for $CLOUDFLARE_HOST to $WAN_IP"
curl -s https://www.cloudflare.com/api.html?a=DIUP\&hosts="$CLOUDFLARE_HOST"\&u="$CLOUDFLARE_USER"\&tkn="$CLOUDFLARE_KEY"\&ip="$WAN_IP" > /dev/null
fi
@Sitebase
Copy link
Author

On OpenWRT run following commands to install dig.

opkg update
opkg install bind-dig

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment