Eugene Smiley on 23 Apr 2014 10:48:22 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Fwd: Your Dyn account status will change in 14 days


I use Namecheap for my domain services and they provide dynamic DNS via ddclient if you use their DNS servers, https://www.namecheap.com/support/knowledgebase/article.aspx/583/11/how-to-configure-ddclient

You can also update via cron using their "browser" update feature, https://www.namecheap.com/support/knowledgebase/article.aspx/29/11/how-to-use-the-browser-to-dynamically-update-hosts-ip


On Wed, Apr 23, 2014 at 9:39 AM, brent timothy saner <brent.saner@gmail.com> wrote:
If you have a linode[0] (or, rather, are using their nameservers), you
can use their API.

I have a cronjob that updates various records that looks a little
something like this (partdon the linebreaks):

#!/bin/bash

curl --globoff -s -o /dev/null
'https://api.linode.com/?api_key=YOUR_API_KEY_HERE&api_action=domain.resource.update&DomainID=YOUR_DOMAIN_UUID_HERE&ResourceID=YOUR_A_RECORD_UUID_HERE&Target=[remote_addr]'

You can generate your API key by logging in and going to
https://manager.linode.com/profile/api

Once that's done (let's say your API key is ABC123, though the real
value should be much more complex), to get a list of domains you can do:

 curl --globoff -s
'https://api.linode.com/?api_key=ABC123&api_action=domain.list' | sed
-e 's/[{}]/''/g' | awk -v k="text" '{n=split($0,a,","); for (i=1;
i<=n; i++) print a[i]}' | sed -e 's/^\("DOMAINID.*\)/\n\1/g'

Now, let's say the domain you want to update has a UUID of 000000.

You can then get a list of *RECORDS* for that domain this way:

curl --globoff -s
'https://api.linode.com/?api_key=ABC123&DOMAINID=000000&api_action=domain.resource.list'
| sed -e 's/[{}]/''/g' | awk -v k="text" '{n=split($0,a,","); for
(i=1; i<=n; i++) print a[i]}' | sed -e 's/^\("DOMAINID.*\)/\n\1/g'

Let's say that the A record for sub.domain.tld has a UUID of 111111.
The final kit and kaboodle to update your A record would be:

curl --globoff -s -o /dev/null
'https://api.linode.com/?api_key=ABC123&api_action=domain.resource.update&DomainID=000000&ResourceID=111111&Target=[remote_addr]'

I recommend setting the TTL to 5 mins and running the cron every 10 mins.

You can do a lot of other neat stuff[1] with their API as well.

NOTE: This passes the API key and other sensitive information via a
URL, so this should only be done with a trusted upstream.

If you want to implement a bit more security, you could run a PHP
script on somewhere static and trusted (liiiike, a Linode! or
whatever.) that will take the visitor IP and use that as a variable to
make the same API call (you'd replace [remote_addr] with the variable
or a hardcoded value, so something like ....Target=123.123.123.321).
That would let you lock down the PHP script with HTDIGEST and HTTPS or
the like.


[0] https://www.linode.com/
[1] https://www.linode.com/api/
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug