项目作者: RatJuggler

项目描述 :
Sync a dynamic public IP address with Gandi DNS.
高级语言: Python
项目地址: git://github.com/RatJuggler/sync-gandi-dns.git
创建时间: 2019-11-27T15:25:54Z
项目社区:https://github.com/RatJuggler/sync-gandi-dns

开源协议:MIT License

下载


sync-gandi-dns

Test & QA
GitHub release (latest by date)

This is a simple Python package which allows the IP address records for domains registered with Gandi
to be kept up to date with the dynamic public values assigned to you by your ISP.

It can be used to update the resource record for either IPV4 (A) or IPV6 (AAAA) or both, for a single or multiple domains.

How it works

It uses the Gandi LiveDNS API to query the current settings and make changes. The API is
marked as (beta), but I’ve not experienced any issues with it. To access the API you need to obtain a key via the Security tab
under “User Settings”, “Manage the user account and security settings”.

It also needs to find out what the latest IP address is before deciding if an update is required. To do this it uses the ipify API
which provides simple endpoints for finding your public IPV4 and IPV6 address.

Installing

Checkout the source code from here:

  1. $ git clone https://github.com/RatJuggler/sync-gandi-dns.git
  2. $ cd sync-gandi-dns

Then install/update as a Python package:

  1. $ sudo pip3 install -U .

Running

  1. $ syncgandidns --help
  2. Usage: syncgandidns [OPTIONS]
  3. Sync a dynamic IP address (V4 & V6) with a Gandi DNS domain entry.
  4. The external IP address is determined automatically by default.
  5. Domains can be set using the GANDI_DOMAINS environment variable. For
  6. multiple domains separate with a ';'.
  7. The Gandi API key can be set using the GANDI_APIKEY environment variable.
  8. Options:
  9. --version Show the version and exit.
  10. -d, --domain DOMAIN A domain to update the DNS for. Repeat the
  11. option to update multiple domains.
  12. [required]
  13. -a, --apikey TEXT Your Gandi API key. [required]
  14. -ipv4, --ipv4-address IPV4_ADDRESS
  15. Override the IPV4 address to update the
  16. domain DNS with.
  17. -no-ipv4, --no-ipv4-update Don't update the IPV4 address, will override
  18. '-ipv4'.
  19. -ipv6, --ipv6-address IPV6_ADDRESS
  20. Override the IPV6 address to update the
  21. domain DNS with.
  22. -no-ipv6, --no-ipv6-update Don't update the IPV6 address, will override
  23. '-ipv6'.
  24. -l, --log-level [DEBUG|VERBOSE|INFO|WARNING]
  25. Show additional logging information.
  26. [default: INFO]
  27. -m, --metrics URL Push metrics to this URL.
  28. -t, --test Test the Gandi API key and exit. [default:
  29. False]
  30. --help Show this message and exit.

There are a number of ways of configuring the domain(s) to update, and the API key. You can set them directly with options on the
command line or provide them pre-set in environment variables, but probably the easiest way to do this is to create a
sync-gandi-dns.env file from the supplied template, then edit the file and set them there.

  1. $ cp sync-gandi-dns.env.template sync-gandi-dns.env

The edited file should then look something like this (not real data):

  1. GANDI_APIKEY="12345abcde67890fghij12kl"
  2. GANDI_DOMAINS="mydomain.com;otherdomain.co.uk;anyothers.io"

It will always start by looking for this file in the current directory and then search upwards. Test that your configuration is
working by using:

  1. $ syncgandidns --test

Docker

Note: IPV6 connectivity is not enabled by default for docker containers, so the ipify IPV6 lookup will always fail, and the
IPV6 address cannot then be kept up to date. I am currently @skleeschulte/how-to-enable-ipv6-for-docker-containers-on-ubuntu-18-04-c68394a219a2">researching
how best to proceed with configuring this.

Docker build and compose files are available which create a standalone image to run the sync on an hourly schedule using the push
metrics option to record its activity.

Edit the docker/crontab.txt file to set your preferred timings and change the options used.

Create the image with:

  1. $ docker build -f docker/Dockerfile -t sync-gandi-dns:local .

Environment variables should be used to set the domains to update, and the Gandi API key. It is important that the API key is not
included in the image in case it is pushed to a public repository (and it’s also just best practice). There are a number of ways
to do this but probably the easiest is to create a sync-gandi-dns.env file as described above and then run the image with the
--env-file option.

  1. $ docker run sync-gandi-dns:local -d --env-file sync-gandi-dns.env

Or just use the compose file to do everything:

  1. $ docker-compose up -d

Environment variables can also be used to configure image tagging (see the file), and a simple health check, using the --test
option, is available if running under orchestration.

Development

For development one of the tests requires access to a key, and an accessible domain to show a working API call. These need to be
set as the environment variables GANDI_TEST_APIKEY and GANDI_TEST_DOMAINS. No tests attempt to make any changes.