Currently, I have a internet provider that seems to change my IP quite frequently, and with a home server that I like to ssh into, store music/movies/files on, and do other fun/hacky things with, it is been a pain to not have a way to access it consistently.
Thankfully, I have bought my domain names through dnsimple, and they have an API that you are able to access, edit, and create records with that works quite nicely. This is by no means a perfect/preferred solution (I don't really like relying on a seperate service just to find out what my public IP address is, nor do I like saving the last know IP address in a "dot file"), but this does the trick for the moment.
Just a few things explainations and ramblings on why I did some of things the way I did:
- logging
I wasn't too confident in my ability write decent shell scripts, I made sure to log as much as I could, and surpress what I didn't need. A lot of tips came from googling "linux" stuff, but most of it can be summed up in the "cron setup" link in the Credits section below.
- curl -s -S
curl
has the annoying tendency to spit out garbage like this when it is piped
or pushed into a log file:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 10660 0 10660 0 0 21873 0 --:--:-- --:--:-- --:--:-- 88099
This clutters up a log file and has no useful purpose when digging through a
log, so when I was using curl, I made sure to use the -s
and -S
options
together. -s
(or --silent
) suppresses errors and almost all output from
curl, which is nice, except when stuff breaks. Thankfully, if you use -S
along with it (or --show-errors
), it will redisplay those errors when you
need them.
Like usual, I didn't pioneer this idea, so here is where I got some help:
- Original Idea by Jason Seifer: http://jasonseifer.com/2011/04/04/auto-update-ip-dnsimple
- A helpful reference for working with cron (I was rusty... and suck): http://kvz.io/blog/2007/07/29/schedule-tasks-on-linux-using-crontab/