DIY DynDNS with DigitalOcean API

DIY DynDNS with DigitalOcean API

Can you remember the good old times where the only reliable way of getting a domain for your router at home was DynDNS. This was a thing at the end of the 90s and nearly everyone was using it. It was the industry standard of an industry never existing. Probably they had a super weird ratio between free lurkers like me and real paying customers and some business developer, in a time where business development wasn't even a term, went crazy and then they started to add tons of restrictions and nag functions. I went off when they wanted me to log in every 30 days or something like that. Anyway, back to the topic: How do one build a DynDNS like thingy in the year 2016? I think the simplest way is, when the DNS service is using, has an API you can program against. In this example I am using DigitalOcean but Amazon AWS, SimpleDNS and other services like that work in the same way. I provide a few varieties of the script, just copy and adjust to your needs.

with cURL

ACCESS_TOKEN="abcdef"
DOMAIN="example.com"
RECORD_ID="1234567"
MY_IP=`curl -s -X GET http://whatismyip.akamai.com/`
curl -s -X PUT -H 'Content-Type: application/json' -H 'Authorization: Bearer '"$ACCESS_TOKEN"'' -d '{"data":"'"$MY_IP"'"}' 'https://api.digitalocean.com/v2/domains/'"$DOMAIN"'/records/'"$RECORD_ID"'' 2>&1
echo -e "\nip set to $MY_IP" 2>&1

with cURL one liner

export MY_IP=`curl -s -X GET http://whatismyip.akamai.com/` && curl -s -X PUT -H 'Content-Type: application/json' -H 'Authorization: Bearer ACCESS_TOKEN' -d '{"data":"'"$MY_IP"'"}' "https://api.digitalocean.com/v2/domains/DOMAIN/records/RECORD_ID" 2>&1 && echo -e "\nip set to $MY_IP" 2>&1

with wget

ACCESS_TOKEN="abcdef"
DOMAIN="example.com"
RECORD_ID="1234567"
MY_IP=`wget -q -O - http://whatismyip.akamai.com/`
wget -q -O - --method=PUT --header 'Content-Type: application/json' --header 'Authorization: Bearer '"$ACCESS_TOKEN"'' --body-data='{"data":"'"$MY_IP"'"}' 'https://api.digitalocean.com/v2/domains/'"$DOMAIN"'/records/'"$RECORD_ID"'' 2>&1
echo -e "\nip set to $MY_IP"

Dial in forever!