Last active
August 29, 2015 14:07
-
-
Save calvinbui/d279ef40b35c0afd3810 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# 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 -L https://gist.githubusercontent.com/Mkaysi/15719ff29b1ba29b5bd0/raw/cf-ddns > /usr/local/bin/cf-ddns && nano /usr/local/bin/cf-ddns && chmod 700 /usr/local/bin/cf-ddns | |
# run `crontab -e` and add next line: | |
# */5 * * * * /usr/local/bin/cf-ddns >/dev/null 2>&1 | |
cfkey=API-key | |
cfuser=email-address | |
cfhost=host-you-want-to-change | |
WAN_IP=$(dig +short myip.opendns.com @resolver1.opendns.com) | |
if [ -f $HOME/.wan_ip-cf.txt ]; then | |
OLD_WAN_IP=$(cat $HOME/.wan_ip-cf.txt) | |
else | |
echo "No file, need IP" | |
OLD_WAN_IP="" | |
fi | |
if [ "$WAN_IP" = "$OLD_WAN_IP" ]; then | |
echo "IP Unchanged" | |
else | |
echo $WAN_IP > $HOME/.wan_ip-cf.txt | |
echo "Updating DNS to $WAN_IP" | |
curl -s https://www.cloudflare.com/api.html?a=DIUP\&hosts="$cfhost"\&u="$cfuser"\&tkn="$cfkey"\&ip="$WAN_IP" > /dev/null | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment