Cron job to auto update a DNS record when WAN IP changes using Gandi Live DNS API on Debian GNU/Linux
Find a file
Lab 8916100448256 307d442f3b Update README.md
2020-02-29 19:17:08 +00:00
etc First version of files 2020-02-27 14:48:28 +01:00
usr/local/bin First version of files 2020-02-27 14:48:28 +01:00
install.sh Update install.sh 2020-02-28 16:11:23 +00:00
README.md Update README.md 2020-02-29 19:17:08 +00:00

Gandi Dynamic DNS

Cron job to auto update a DNS record when WAN IP changes using Gandi Live DNS API on Debian GNU/Linux

To install

git clone https://gitlab.com/lab.8916100448256/gandi-dynamic-dns.git ./gandi-dynamic-dns
cd ./gandi-dynamic-dns
sudo bash ./install.sh

Then configure DNS record info and API key in file /etc/live-dns/live-dns.conf

How it works

/etc/cron.d/live-dns-update

Cron job definition to check for WAN IP change and call Live DNS API to update the DNS record if necessary. By default runs the check/update script 2 times per hour, at every hour past 12 and 42 minutes.

/etc/live-dns/live-dns.conf

Configuration file for the check/update script Needs to contains 3 environment variable definitions

  • DOMAIN="domain.tld" : Replace domain.tld with your domain name
  • RECORD="host" : Replace host with the sub domain you want to update when WAN IP changes
  • APIKEY="Your-API-Key" : Replace with you API key generated on the Gandi web interface.

Check this page if you don't know your APIKey : https://docs.gandi.net/en/domain_names/advanced_users/api.html

/usr/local/bin/live-dns-update.sh

This is the script that is called by the cron job.

  • First the WAN (external) IPV4 and IPV6 adresses are determined using http://me.gandi.net
  • Then they are compared to DNS records for the configured host and domain.
  • In case of mismatch Gandi live DNS API is called to update the DNS records

Information logs are written to system log. Exemple :

Feb 29 20:12:02 passerelle root: WAN IPv4 : 1.2.3.4
Feb 29 20:12:02 passerelle root: WAN IPv6 : 1111:2222:3333:4444:5555:6666:7777:8888
Feb 29 20:12:02 passerelle root: DNS IPv4 : 1.2.3.4
Feb 29 20:12:02 passerelle root: DNS IPv6 : 1111:2222:3333:4444:5555:6666:7777:8888
Feb 29 20:12:02 passerelle root: No need to update IPv4 DNS record for sub.domain.tld
Feb 29 20:12:02 passerelle root: No need to update IPv6 DNS record for sub.domain.tld

This script is based on this sample provided by Gandi on their GitHub : mywanip.sh