Coder Social home page Coder Social logo

gandi-ddns's Introduction

gandi-ddns

Simple quick & dirty script to update DNS A record of your domain dynamically using gandi.net's API. It is very similar to no-ip and dyndns et al where you can have a domain on the internet which points at your computer's IP address, except it is free (once you have registered the domain) and does not suffer from any forced refreshing etc.

This was designed specifically with Raspberry Pi servers in mind, but could be used anywhere.

Every time the script runs it will get the current domain config from gandi.net's API and look for the IP in the A record for the domain (default name for the record is '@' but you can change that if you want to). It will then get your current external IP from a public "what is my ip" site. Once it has both IPs it will compare what is in the DNS config vs what your IP is, and update the DNS config for the domain as appropriate so that it resolves to your current IP address.

The configuration is stored in the script directory under the file config.txt. The syntax is the standard Python configuration file, and the format is the following:

[local]
# gandi.net API (Production) key
apikey = <CHANGE ME>
# Domain
domain = <CHANGE ME>
# A-record name
a_name = @
# TTL (seconds = 5 mintes to 30 days)
ttl = 900
# Production API
api = https://rpc.gandi.net/xmlrpc/
# Host which IP should be changed
host = localhost
  • Do not forget to replace the values marked with <CHANGE ME> with your 24-character API key and domain.
  • You can have more than one config section ([local] above) if you need to update more than one domain/a_name.
  • host is either localhost in which case the script will fetch the current external address, or any other public name. Using an other ddns account will allow you to sync it with Gandi (useful when you are not running on the same IP than the one you want to update).

Usage

You will need to make sure that your domain is registered on gandi.net, and that you are using the gandi.net DNS servers (if you are using the default gandi.net zone for other domains you have on gandi.net, you might want to create a dedicated zone for the domain you will be using). You'll also need to register for the API to get a key.

Once you have the production key (not the test environment key) and your domain on gandi.net, edit the 'apikey' and 'domain' variables in the script appropriately.

Once you have done this you can then set up the script to run via crontab:

sudo crontab -e

Then add the following line so that the script is run after a reboot:

@reboot python /home/pi/gandi-ddns.py &

And then to make it check for a new IP every 15 mintes you can add:

*/15 * * * * python /home/pi/gandi-ddns.py

You can then start and/or reload the cron config:

sudo /etc/init.d/cron start
sudo /etc/init.d/cron reload

FAQ

I am getting a python trace about Error on object : OBJECT_FQDN (CAUSE_BADPARAMETER) [string '<change me>' does not match '^(?:(?!-)[-a-zA-Z0-9]{1,63}(?<!-)(\\.|$)){2,}$']?

You need to make sure you set the domain variable to match your domain name (no www), e.g. 'example.com'.

I am getting a python trace about Error on object : OBJECT_STRING (CAUSE_BADPARAMETER) [string 'OmQUMmhelfrbXQyA3R4I6Ma' does not match '^[a-z0-9]{24}$']?

You need to make sure you enter the correct gandi.net production API key.

I am getting a python trace about 'Error on object : OBJECT_ACCOUNT (CAUSE_NORIGHT) [Invalid API key]?

Double-check you got the right gandi.net API key. Double-check that you are using a production key!

gandi-ddns's People

Contributors

bentiss avatar crsaracco avatar matt1 avatar michaelsanford avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gandi-ddns's Issues

Indent error

On line 118, you should add an indent to have
return None
instead of
return None

Otherwise, the function read_config will always return None ...

Possible merger with ddnsc

ddnsc is a similar project, however it supports multiple dns providers. I think it would make sense to merge this project with ddnsc so there can be one package that supports many providers, especially since they are both already written in python.

Gandi update speed?

Hi there, this is not a technical issue but more a question about the technique:
How fast do the changes pushed onto gandi take to propagate?

API change in zone list/update

Here's what I got from GANDI

Dear Customer,

We contact you today because you are identified as an active user of our
public production API.

We would like to inform you that an EMERGENCY patch for our public API
has been deployed today [02/08/2017 Paris time] on our producton
platform, in order to counter an incident[1] that impacted all of our
customers.

This corrective action has resulted in significant changes in our public
API.

It is therefore necessary that you check your code, and more precisely
the use of the following method: "gandi.api.domains.zone.record::list"

If this is your case, please note that the use of that method has been
updated, particularly the 'id' field type returned by that fuction. Your
code now needs to accept the fact that the 'id' type is a string of
characters, and no longer an integer (i4 in xmlrpc).

The two functions which use this 'id' as an entry are:

  • gandi.api.domains.zone.record::update
  • gandi.api.domains.zone.record::list (filtre sur l'id)

In order to ensure optimal backward compatibility, those two functions
still accept an "integer" type as entry for the 'id' field, in addition
to the "string of characters" type. It is strongly recommended, however,
to use the "string" type.

Our online public API documentation[2] has been updated as a result of
these changes.

Given the urgency and consequences of this incident, we had no choice
but to deploy this patch without prior notification and we apologize for
any inconvenience.

Our customer service is of course at your disposal to assist you if you
encounter difficulties in the implementation of the modifications.

We thank you for your confidence in Gandi.

Gandi.net

[1] http://status.gandi.net/timeline/events/957
[2] http://doc.rpc.gandi.net/domain/reference.html?zone.record.list#ZoneRecordReturn
& http://doc.rpc.gandi.net/domain/reference.html#RecordUpdateOptions

support IPv6

Hello,
If I understand it correctly, the provider changes the prefix of private IPv6 addresses, so ddns is also needed for IPv6.
The API used to determine the IPv4 address, also works for IPv6: https://api6.ipify.org (only works if you have an IPv6 address)
In case you are interested, I can offer to implement this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.