2017-08-14 17:45:08 -04:00
gandi_live_dns
----
This is a simple dynamic DNS updater for the
2017-08-15 12:01:15 -04:00
[Gandi ](https://www.gandi.net ) registrar. It uses their [LiveDNS REST API ](http://doc.livedns.gandi.net/ ) to update the zone file for a subdomain of a domain to point at the external IPv4 address of the computer it has been run from.
2017-08-14 17:45:08 -04:00
2017-08-15 11:54:18 -04:00
It has been developed on Debian 8 Jessie and tested on Debian 9 Sretch GNU/Linux using Python 2.7.
2017-08-14 17:45:08 -04:00
2017-08-15 12:01:15 -04:00
With the new v5 Website, Gandi has also launched a new REST API which makes it easier to communicate via bash/curl or python/requests.
2017-08-14 17:45:08 -04:00
2017-08-15 11:54:18 -04:00
### Goal
2017-08-14 17:45:08 -04:00
2017-08-15 12:25:55 -04:00
You want your homeserver to be always available at `dynamic_subdomain.mydomain.tld` .
2017-08-14 17:45:08 -04:00
2017-08-15 12:01:15 -04:00
### Debian Package Requirements
`apt-get update && apt-get upgrade && apt-get install unzip python-requests python-args python-simplejson`
2017-08-14 17:45:08 -04:00
#### API Key
2017-08-15 08:42:51 -04:00
First, you must apply for an API key with Gandi. Visit
https://account.gandi.net/en/ and apply for (at least) the production API
2017-08-14 17:45:08 -04:00
key by following their directions.
2017-08-15 11:54:18 -04:00
#### A DNS Record
2017-08-14 17:45:08 -04:00
Create the DNS A Records in the GANDI Webinterface which you want to update if your IP changes.
2017-08-15 08:42:51 -04:00
#### Git Clone or Download the Script
2017-08-15 12:25:55 -04:00
Download the Script from here as [zip ](https://github.com/cavebeat/gandi_live_dns/archive/master.zip )/[tar.gz](https://github.com/cavebeat/gandi_live_dns/archive/master.tar.gz) and extract it.
2017-08-15 11:54:18 -04:00
2017-08-15 12:25:55 -04:00
or clone from git
2017-08-15 11:54:18 -04:00
2017-08-15 08:42:51 -04:00
`git clone https://github.com/cavebeat/gandi_live_dns.git`
2017-08-14 17:45:08 -04:00
#### Script Configuration
2017-08-15 08:42:51 -04:00
Then you'd need to configure the script in the src directory.
2017-08-15 11:54:18 -04:00
Copy `example.config.py` to `config.py` , and put it in the same directory as the script.
Edit the config file to fit your needs.
##### api_secret
Start by retrieving your API Key from the "Security" section in new [Gandi Account admin panel ](https://account.gandi.net/ ) to be able to make authenticated requests to the API.
api_secret = '---my_secret_API_KEY----'
##### api_endpoint
Gandiv5 LiveDNS API Location
http://doc.livedns.gandi.net/#api-endpoint
2017-08-15 12:01:15 -04:00
```
2017-08-15 11:54:18 -04:00
api_endpoint = 'https://dns.beta.gandi.net/api/v5'
2017-08-15 12:01:15 -04:00
```
2017-08-15 11:54:18 -04:00
##### domain
2017-08-15 12:01:15 -04:00
Your domain for the subdomains to be updated
2017-08-15 11:54:18 -04:00
##### subdomains
2017-08-15 12:01:15 -04:00
All subdomains which should be updated. They get created if they do not yet exist.
2017-08-14 17:45:08 -04:00
2017-08-15 12:01:15 -04:00
```
subdomains = ["subdomain1", "subdomain2", "subdomain3"]
```
The first subdomain is used to find out the actual IP in the Zone Records.
2017-08-14 17:45:08 -04:00
2017-08-15 08:42:51 -04:00
#### Run the script
2017-08-15 11:54:18 -04:00
And run the script:
2017-08-15 12:01:15 -04:00
```
2017-08-15 11:54:18 -04:00
root@dyndns:~/gandi_live_dns-master/src# ./gandi_live_dns.py
Checking dynamic IP: 127.0.0.1
Checking IP from DNS Record subdomain1: 127.0.0.1
IP Address Match - no further action
2017-08-15 12:01:15 -04:00
```
2017-08-15 11:54:18 -04:00
If your IP has changed, it will be detected and the update will be triggered.
2017-08-15 08:42:51 -04:00
2017-08-15 12:01:15 -04:00
```
2017-08-15 11:54:18 -04:00
root@dyndns:~/gandi_live_dns-master/src# ./gandi_live_dns.py
Checking dynamic IP: 127.0.0.2
Checking IP from DNS Record subdomain1: 127.0.0.1
IP Address Mismatch - going to update the DNS Records for the subdomains with new IP 127.0.0.2
Status Code: 201 , DNS Record Created , IP updated for subdomain1
Status Code: 201 , DNS Record Created , IP updated for subdomain2
Status Code: 201 , DNS Record Created , IP updated for subdomain3
2017-08-15 12:01:15 -04:00
```
2017-08-15 11:54:18 -04:00
#### Command Line Arguments
2017-08-15 12:01:15 -04:00
```
2017-08-15 11:54:18 -04:00
root@dyndns:~/gandi_live_dns-master/src# ./gandi_live_dns.py -h
usage: gandi_live_dns.py [-h] [-f]
optional arguments:
-h, --help show this help message and exit
-f, --force force an update/create
2017-08-15 12:01:15 -04:00
```
2017-08-15 08:42:51 -04:00
2017-08-15 11:54:18 -04:00
The force option runs the script, even when no IP change has been detected.
It will update all subdomains and even create them if they are missing in the
Zone File/Zone UUID. This can be used if additional/new subdomains get appended to the conig file.
2017-08-15 12:25:55 -04:00
### IP address lookup service
There exist several providers for this case, but better is to run your own somewhere.
#### Poor Mans PHP Solution
On a LAMP Stack, place the file [index.php]https://github.com/cavebeat/gandi_live_dns/blob/master/src/example-index.php) in a directory /ip in your webroot.
```
root@laptop:~# curl https://blog.cavebeat.org/ip/
127.0.0.1
```
This should fit your personal needs and you still selfhost the whole thing.
#### https://github.com/mpolden/ipd
A simple service for looking up your IP address. This is the code that powers [https://ifconfig.co ](https://ifconfig.co )
#### use external services
choose one as described in the config file.
### Cron the script
```
*/5 * * * * /root//root/gandi_live_dns-master/src/gandi_live_dns.py >/dev/null 2>& 1
```
### Upcoming Features
* command line Argument for verbose mode
### Inspiration
2017-08-15 11:54:18 -04:00
2017-08-15 08:42:51 -04:00
This DynDNS updater is inspired by https://github.com/jasontbradshaw/gandi-dyndns which worked very well
2017-08-15 12:25:55 -04:00
with the classic DNS from Gandiv4 Website and their XML-RPC API.
Gandi has created a new API, i accidently switched to the new DNS Record System, so someone had to start a new updater.