Skip to content

Instantly share code, notes, and snippets.

@rsutphin
Created December 4, 2013 23:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rsutphin/7797281 to your computer and use it in GitHub Desktop.
Save rsutphin/7797281 to your computer and use it in GitHub Desktop.
Use linode's DNS API for dynamic DNS with curl from cron

Use Linode's DNS Manager API for one-line dynamic DNS

This can be useful for cron, for instance.

Prereqs

  • You are using Linode's DNS Manager to manage a zone for your domain
  • You have already created an A record for the name you want to make dynamic
  • You have an API key for Linode's API
  • curl and jsonpp (jsonpp is not necessary but makes the manual steps easier)

Setup

You need the DOMAINID and RESOURCEID for the A record you previously created. First, find the DOMAINID by listing all the domains you can manage:

$ curl -v -u u:THE_API_KEY 'https://api.linode.com/?api_action=domain.list' | jsonpp

Let's say the DOMAINID you find is 10000.

Next, find the RESOURCEID for the A record you want to update dynamically. You do this by getting another list and looking through it:

$ curl -v -u u:THE_API_KEY 'https://api.linode.com/?api_action=domain.resource.list&DOMAINID=10000' | jsonpp

Let's say the RESOURCEID you find is 800.

Update

Those two pieces of info, plus the API key and curl, are all you need to update that DNS record to point to the address from which the request originates:

$ curl -v -u u:THE_API_KEY 'https://api.linode.com/?api_action=domain.resource.update&DOMAINID=10000&RESOURCEID=800&TARGET=%5Bremote_addr%5D' | jsonpp

Re-get the resource info to see that it was updated:

$ curl -v -u u:THE_API_KEY 'https://api.linode.com/?api_action=domain.resource.list&DOMAINID=10000&RESOURCEID=800' | jsonpp

Cron

You can have the update run automatically every hour via your crontab:

$ crontab -e
# edit to contain:
0 * * * * curl -v -u u:THE_API_KEY 'https://api.linode.com/?api_action=domain.resource.update&DOMAINID=10000&RESOURCEID=800&TARGET=%5Bremote_addr%5D' > ~/dyndns.log 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment