Dyndns at Gandi using Livedns
Running a server at home can be cumbersome as your IP changes, making it difficult for people (including yourself) to find your server when away from home. There are dynamic dns solutions available (e.g. DuckDNS that solve this, but this requires an extra step (i.e. the dynamic dns hostname). Gandi offers an API to edit their domains, meaning that we don’t need the extra step and can update our domain directly. (BTW, besides this, domains also come with 2 mailboxes and a static website, for only ~1€ per month! (no I don’t get sponsored)).
Overview of solutions
It seems several people already solved this problem, so we only need to pick a suitable solution. Below candidates I could find with date of latest commit & number of stars.
- https://github.com/Danamir/dyn-gandi/ (January 2021, 45★⭐️, 409 sloc)
- https://github.com/brianpcurran/gandi-automatic-dns (Nov 2020, 86★, supports LiveDNS, 420 sloc)
- https://github.com/cavebeat/gandi-live-dns (March 2018, 114★, supports LiveDNS, 140 sloc)
- https://github.com/wittypluck/gandi-live-dns (supports Python 3, adds some features)
- https://github.com/driesdeschout/gandi-live-dns (supports Python 3, adds some features)
- https://github.com/dvdme/gandi-live-dns (Supports Python 3, minor update)
- https://github.com/AlessioCasco/gandi-dyndns (April 2017, 0★, does not support LiveDNS)
Requirements are:
- do not steal my private API
- use new LiveDNS api
- be stable
I settled for wittypluck/gandi-automatic-dns
because it’s short and simple, which helps
in auditing nobody steals my API key.
Installation
- Download & unzip the specific version I audited online
wget https://github.com/wittypluck/gandi-live-dns/archive/cf3542714fc52bbf21c1a4d00787a88343b04960.zip -O gandi-live-dns.zip unzip gandi-live-dns.zip
- Configure, ensure nobody can read my key
cp example.config.py config.py chmod og-rwx config.py cat <<EOF >> config.py # My config api_secret='insert key here' domains={'vanwerkhoven.org':['www','tim']} ttl='1800' # our IP doesnt change that often, 30min down is ~OK ifconfig4='https://v4.ident.me' ifconfig6='' # set empty because we don't have ipv6 interface='' # set empty because else we get local ipv6 address EOF
- Testrun
python3 gandi-live-dns.py
- If a record doesn’t exist (yet), you confusingly get an error. Error disappears on subsequent runs.
Error: HTTP Status Code 404 when trying to get IP from subdomain tim Can't find the DNS record tim/AAAA in the zone Going to update/create the DNS Records for the subdomain tim old IP -1 new IP fded:99:0:100:96c6:91ff:fe12:5eec
- If a record doesn’t exist (yet), you confusingly get an error. Error disappears on subsequent runs.
- Automate in cron
crontab -e */5 * * * * python3 /home/tim/workers/gandi-live-dns/src/gandi-live-dns.py >/dev/null 2>&1