This script updates the A or AAAA records of a subdomain managed by Gandi.
It has no external requirements besides Python 3. This facilitates deployment on lightweight systems such as NAS, Raspberry Pi, etc. and running via schedulers (e.g. systemd-timers or cron).
The external IP address can be determined automatically through the service provided by ifconfig.co. Please respect its rate limit policy:
Please limit automated requests to 1 request per minute. No guarantee is made for requests that exceed this limit. They may be rate-limited, with a 429 status code, or dropped entirely.
- Python 3
usage: gandi.py [-h] GANDI_API_KEY subdomain.domain.tld {A,AAAA} [address]GANDI_API_KEYis the API key that can be obtained from the administration interface for the domain on the Gandi website.- Use
Ato update the IPv4 record, andAAAAto update the IPv6 record. - As for the target address to set, there are three options:
$ ./gandi.py GANDI_API_KEY foo.example.com AAAAThis method uses the service of ifconfig.co to determine the external IP address of the current machine. As mentioned before, please be responsible and do not use this service more than once per minute.
$ ./gandi.py GANDI_API_KEY foo.example.com AAAA ::1Now the AAAA record of foo.example.com will point to ::1.
$ ./gandi.py GANDI_API_KEY foo.example.com AAAA fooboxThe IP address of foobox will be resolved and
written to the AAAA record of foo.example.com.
This way one machine can update the records of several other hosts,
e.g. on the local network.
Note that this may not make much sense if foobox is resolved to
a local (IPv4) address as is the case behind NAT.
Regular updates of the domain records can be performed using
systemd timers:
- Edit
gandi-update.shto your needs. - In
gandi-update.servicechange the path inExecStartto the checkout directory. - Link the files to systemd's config:
mkdir -p $HOME/.config/systemd/user ln -s $PWD/gandi-update.{service,timer} $HOME/.config/systemd/user
- Enable the timer:
systemctl --user enable gandi-update.timer - Verify that it worked:
systemctl --user list-timers
An update of the domain records can be done at boot time as follows:
- Edit
gandi-update.shto your needs. - In
gandi-update.servicechange the path inExecStartto the checkout directory. - Link the file to systemd's config:
mkdir -p $HOME/.config/systemd/user ln -s $PWD/gandi-update.service $HOME/.config/systemd/user
- Enable the service:
systemctl --user enable gandi-update.service - In order to run the script at boot (and not wait for the user to log in), enable a lingering systemd user instance:
loginctl enable-linger $USER