I’ve been using DNSimple for most a lot of my domain hosting lately. It’s a great service and I highly recommend checking them out for domain hosting. Recently I went out of town but wanted some way to be able to SSH home if I needed to. Luckily, DNSimple has a nice REST API that lets me update records easily. I created a "home" record for one of my domains and created a script to auto update:
#!/bin/bash LOGIN="" PASSWORD="" DOMAIN_ID="" RECORD_ID="" IP="`curl http://icanhazip.com/" curl -H "Accept: application/json" \ --basic -u "$LOGIN:$PASSWORD" \ -H "Content-Type: application/json" \ -i -X PUT https://DNSimple.com/domains/$DOMAIN_ID/records/$RECORD_ID.json \ -d {"record":{"content":"$IP"}}
It uses the awesome new jsonip service to grab your ip. It then does a quick sed parsing on that output to grab just your ip. Finally it does a put to the record in DNSimple updating it with the new information. You must have already created a record and domain in order for this to work. I saved this script as dnsimple_update.sh in my ~/bin directory.
Fill in your login and password credentials (or set some environment variables) and domain and record ids and you’re good to go. You can get your domain and record ids by hovering over the edit link in the advanced editor in DNSimple for the record you want and copying and pasting the domain and record ids.
Finally, I set it to run as a cronjob every 15 minutes:
# m h dom mon dow command */15 * * * * /home/my_user/bin/DNSimple_update.sh
This worked out very well and with some port forwarding on my home router I was able to ssh in to my home machines without any problems.
Update: Kristopher Murata gave a correction to the script in the comments since jsonip changed their format. Twice!! Thanks, Kris!

Thanks for this Jason. I’ve bookmarked it and will link to it from the DNSimple site shortly.
jsonip looks pretty cool, but for a bash script it’s not actually that helpful.
IP = “`curl http://icanhazip.com`” will give you just the IP address in the response body, no need for sed.
Neat site! I didn’t know about it. Very useful.
Thanks for sharing your script. Copy and paste and away I went!!
Just what the doctor ordered. I hacked away on a few contributions to dyn-dnsimple on Github over the weekend, but it was just too much for such a simple task. This was perfect.
Thanks!
Nice. Also if you’re already using something like ddclient to update another dyndns service, you can just make it call this script after it’s done (add the ‘postscript’ param to your ddclient.conf). That way you get ddclient’s IP caching (it’ll only call the script when the IP has actually changed, instead of every 15 mins). Also it passes the new IP as the first argument so you can avoid looking it up again.
Here’s the version I’m using (added a bit of error handling too):
LOGIN=”"
PASSWORD=”"
DOMAIN_ID=”"
RECORD_ID=”"
IP=”$1″
if [ -z "$IP" ]; then
echo “$0: This script expects an IP address as the first argument” >&2
exit 1
fi
curl -H “Accept: application/json” \
–basic -u “$LOGIN:$PASSWORD” \
-H “Content-Type: application/json” \
-f -s -S -X PUT \
https://dnsimple.com/domains/$DOMAIN_ID/records/$RECORD_ID.json \
-d {“record”:{“content”:”$IP”}} >/dev/null
if [ $? -ne 0 ]; then
echo “Failed to update dnsimple record with IP $IP” >&2
exit 2
fi
echo “Updated dnsimple domain $DOMAIN_ID record $RECORD_ID with IP $IP”
thank you so much for this kind tips, now i am following you on twitter for more updates. !
thank you again
First i had some problems and i was busting my ass on how to do this…but your script helped me.. THx :)
awesome, thank you so much :D
I use this at all of my sites.Great tip for beginners.
ahh thanks for the script that’s exactly what i was looking for!
Thanks for sharing. It’s very userful for me.
good news, and thanks for information….
looks quite simple. will try.
thank you for sharing,
Helmuts
I use DNSimple for my hosting as well! They’re a great company with excellent customer service. I never knew this trick though, so I’ll have to give it a shot :)
The abode entertainment landscape is constantly changing, and amazon.com is here to aid you understand those replacements and locate the great products to fit your wants and allocation. don’t know what you need? we can aid you there too
The abode entertainment landscape is constantly changing, and amazon.com is here to aid you understand those replacements and locate the great products to fit your wants and allocation. don’t know what you need? we can aid you there too.
I prefer DNSimple lately, too, for DNS and SSL certificates.
hi Jason,
have to admit – it is too complicated for me :) … but you can’t ask these knowlwdge from a woman :)
.. tried to understand the topic, but didn’t get a clue :)
i suppose, i will be fine – i’m using proffesional hosting company (they should do all this stuff already)
anyway, good luck,
Jools
Thank you for this bit of script — it was helpful and saved me time. Much appreciated!
Recent jsonip.com update broke this script, because there’s an extra value at the end.
If you replace this line:
IP=”`curl http://jsonip.com | sed ‘s/{“ip”:”\(.*\)”/\1/g’ | sed ‘s/}//’`”
For this one:
IP=”`curl http://jsonip.com | sed ‘s/{“ip”:”\(.*\)”/\1/g’ | sed ‘s/”, “about”:”\/about}//’`”
It will work fine again. :)
Thanks so much for this! I’ve updated the post.
Seems that jsonip.com is playing with their API lately, now there’s no space between the parameters and the script is failing again.
For a more strict approach, we could do this instead:
IP=”`curl http://jsonip.com | grep -Eo ‘([0-9]{1,3}\.){3}[0-9]{1,3}’`”
With grep we are matching any IP address returned by jsonip.com and hopefully they will not start returning two or more IPs! :)
This was causing 500 errors for me, but I was able to fix them by escaping the quotes in the last line of the curl command:
-d {\”record\”:{\”content\”:\”$IP\”}}