Table of Contents
Updating Gandi DNS Using the API and a Shell Script #
In this tutorial, we will show you how to update your Gandi DNS records using the Gandi API and a shell script. This approach is useful for those who have dynamic IP addresses and need to keep their DNS records up-to-date.
By using the Gandi API and a shell script, you can automate the process of updating your DNS records, ensuring that your website or application is always available at the correct IP address.
In this tutorial, we will walk you through the process of creating a shell script to update your DNS records, and scheduling the script to run automatically.
Read on to learn how to update your Gandi DNS records using the API and a shell script.
Further Reading If you’re interested in automating dynamic DNS updates with the Gandi API and Docker, you might find my follow-up article Automate Dynamic DNS Updates with Gandi API and Docker helpful. This article goes into more detail on how to set up the Docker container, including how to build the Docker image, run the container, and schedule tasks using cron. It also covers best practices for running Docker containers in production environments. Check out the article for more information and step-by-step instructions.
Dynamic DNS #
Dynamic DNS is a way to associate a changing Dynamic IP address (usually residential xDSL connections) to a static domain name (DNS record)
This allows you to connect to home.example.com -> DNS Lookup & Resolution -> 203.0.113.78. The DNS entry for home.example.com is updated automatically at set intervals or when an IP address change is detected.
Dynamic DNS Providers #
There are a number of Dynamic DNS providers that can be used, a well known provider is https://dyn.com/, but unfortunately some of these services come with a cost.
Gandi Live DNS #
LiveDNS is Gandi’s upcoming DNS platform, a completely new service that offers its own API and its own nameservers.
The new platform offers powerful features to manage DNS Zone templates that you can integrate into your own workflow. Features include bulk record management, association with multiple domains, versioning and rollback.
The below instructions will show you how to create a Dynamic DNS system using a single script and Gandi’s LiveDNS.
Make sure you have the following applications installed:
- curl - https://curl.haxx.se/
- jq - https://stedolan.github.io/jq/
- Gandi LiveDNS API Key - Retrieve your API Key from the “Security” section in the Account Admin Panel
Bash Script #
Create a bash script and put it under “/usr/local/bin/dyndns_update.sh”. (This can of course be kept wherever you want)
Add the API key you got from the Gandi Account Panel.
Run The Script #
I would set this script to run via crontab every 30 minutes. This ensures with an IP change the Dynamic DNS would only be out of date for a maximum of 30 minutes.
Edit crontab with the following command
[root@server ~]# crontab -e
Add the following lines to run the script every 30 minutes.
*/30 * * * * /bin/bash /usr/local/bin/dyndns_update.sh
Once the script runs it should update the dynamic.example.com dns entry with the external IP that was found by the script.