DaemonForums  

Go Back   DaemonForums > Miscellaneous > Guides

Guides All Guides and HOWTO's.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 20th February 2013
asemisldkfj's Avatar
asemisldkfj asemisldkfj is offline
Fdisk Soldier
 
Join Date: Aug 2008
Posts: 50
Thanked 1 Time in 1 Post
Default How to achieve dynamic DNS with Gandi.net and the shell

Per J65kno's suggestion, I am creating this thread as an expansion of the thread I created here.

Since Gandi.net doesn't support dynamic DNS, the equivalent has to be accomplished via their XML-RPC API. In addition to the shell script I wrote, there is a Python equivalent, whose functionality I can not attest to. While parsing XML in the shell isn't the most fun thing in the world, I wrote this script both because I'm a masochist and because I wanted an option that didn't require any extra software on my OpenBSD firewall.

If you have a BSD machine that is directly connected to the internet, you can use the -i flag to pass the script your external network interface and it will determine your IP address based on that. Otherwise, OpenDNS is used. Here is the complete usage information:

Code:
gad [-f] [-t] [-v] [-i EXT_IF] -a APIKEY -d EXAMPLE.COM -r "RECORD-NAMES"

-f: Force an update regardless of IP address discrepancy
-t: Only create the new version file; don't activate it
-v: Print information to stdout even if a new zonefile isn't needed
-i: Use ifconfig instead of OpenDNS to determine external IP address

EXT_IF: The name of your external network interface
APIKEY: Your API key provided by Gandi
EXAMPLE.COM: The domain name whose active zonefile will be updated
RECORD-NAMES: A space-separated list of the names of the A records to update or create
Here is an example of a crontab entry that will compare the IP address of interface re0 with the IP address of the @ record in the active zonefile for domain example.com:

Code:
0 * * * * /home/brian/bin/gad -i re0 -a asdf1234 -d example.com -r "@"
asdf1234 is obviously not my actual API key. If you have a Gandi account you can request your own API key here.

With some minimal tweaking (changing User-Agent, Host, and the openssl command) of the rpc() function in the script, it could be modified to talk to any XML-RPC API. The syntax of the rpc() function is:

Code:
rpc "methodName" "datatype" "value" "struct" "name" "datatype" "value"
Thanks to a bunch of nested while loops, you can pass an arbitrary number of datatype/value pairs and structs with their member name/datatype/value tuples. Valid method names for Gandi's API are in their documentation.

Some fun things I learned writing this script: how to parse command line flags/options with the shell, how to use the openssl s_client command as an SSL client, and how to construct XML RPCs. Here are some helpful sites that I used:

Good Shell Coding Practices: Handling Command Line Arguments
XML-RPC Wikipedia page
S_CLIENT section of the openssl man page

The most recent version of the script attached to this post can be found on Google Code.
Attached Files
File Type: sh gad.sh (5.5 KB, 165 views)
__________________
chat.taucher.net #bsd
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic DNS for Gandi.net domain names asemisldkfj Off-Topic 3 20th February 2013 03:01 AM
What tool for dynamic I.P filtering unixjingleman OpenBSD Security 1 2nd March 2011 11:31 AM
Problems with IPSEC and Dynamic GW Roadwarrior bitfrost OpenBSD Security 0 27th October 2010 06:12 AM
Dynamic Traffic Shaping LordZ OpenBSD Security 6 19th January 2009 04:30 PM
Ajax dynamic table/spreadsheet robbak Programming 1 7th June 2008 10:33 PM


All times are GMT. The time now is 02:34 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick