cloudflare-ddns
A small application to dynamically update a DNS record in CloudFlare.
Purpose
I mainly wrote this app as a way to learn how to write Go. It's taking some getting used to, but I feel like I'm getting the hang of things.
Prerequisites
Build Instructions
Go
- Open a terminal and run
go build at the root of the project.
- Then run
./cloudflare-ddns (.\cloudflare-ddns in Windows).
- You'll need to pass these parameters
./cloudflare-ddns \
-apiToken='{your cloudflare API token}' \ # required
-zoneIdentifier='{your zone (domain) idenfiier}' \ # required
-dnsRecordIdentifier='{your DNS record identifier}' \ # required
-updateInterval='{the interval to update in minutes}' # optional
Docker
- Open a terminal and run
docker build . -t armorynode/cloudflare-ddns:latest
- Then run this in the terminal
docker run -it \
-e APITOKEN='{your API token}' \ # required
-e ZONEIDENTIFIER='{your zone identifier}' \ # required
-e DNSRECORDIDENTIFIER='{your DNS record identifier}' \ # required
-e UPDATEINTERVAL='{the interval to update in minutes}' \ # optional
armorynode/cloudflare-ddns:latest
(If you are using Docker Desktop, after running docker build you can run the image under the "Images" menu item. You'll need to open the "Optional settings" dropdown and add each environment variable)
Once the program verifies your API key and Zone/DNS record identifiers, it will run and update the DNS record at the specified interval.
Getting your DNS record identifier
Cloudflare currently does not have an easy way to view the ids for your DNS records. This is the least painful way to get it I've found.
- Go to this page in Cloudflare's docs.
- Execute the curl command in a terminal, or your preferred REST client. (make sure to strip off the additional query parameters from their example.)
- You can use the same API key that you're using for the project, just be sure it also has the
DNS:Read permission along with edit permission.
- Look for your DNS record and grab the
"id" value.
Once you have that you're good to go.