Note: No longer maintained as DDNS is now managed by my OpenWrt router
Yet another Cloudflare dynamic DNS record update tool
This is a simple Go utility for updating DNS records via the Cloudflare v4 API. It’s designed for dynamic DNS use cases, and so resolves the current external IP address using the ipify API for determining public IP addresses, and then points DNS A records at it. You may or may not find it useful.
- Download the appropriate binary from Releases
- Create a configuration file
- Run
cf-ddns-updater
- 🏠 A valid domain, hosted at Cloudflare
- 🎫 A Cloudflare API token, with
Zone:Read
andDNS:Edit
permissions for the domain you wish to update - 📛 The DNS record that you wish to update must already exist
- 📶 Internet connectivity
-c Config file (default: "/home/user/.config/cf-ddns-updater/config.json")
-n Check mode (dry run, default: off)
The default configuration filename is config.json
(see below), the exact location is dependent on the operating system; the standard user configuration directories are used (e.g., following the XDG Base Directory Specification for Linux/macOS, which is usually $HOME/.config
, and %APPDATA%
for Windows).
The output from cf-ddns-updater -h
will show the default location in effect. If your configuration file is named otherwise or located elsewhere, use the -c
command line parameter to specify the path/filename to use.
To perform a dry run, where the public IP address is determined but the DNS record is not actually updated, use the -n
flag to enable check mode.
Create a JSON configuration file with the hostname to update, and a valid Cloudflare API token:
{
"FQDN": ["myip.example.com", "myip2.example.com", "myip3.example.com"],
"APIToken": "<Your Cloudflare API token>"
}
💡 N.b. See requirements above: the DNS record (type A
) for the FQDN must already exist. The API token must also have sufficient permissions to read the corresponding domain zone and edit the DNS record.
$ ./cf-ddns-updater
2022/04/21 21:47:38 Current IP address is: 203.0.113.2
2022/04/21 21:47:40 myip.example.com points to 203.0.113.1, the record will be updated.
2022/04/21 21:47:40 Setting myip.example.com => 203.0.113.2 ...
2022/04/21 21:47:41 Success!
$ ./cf-ddns-updater
2022/04/21 21:52:26 Current IP address is: 203.0.113.2
2022/04/21 21:52:28 myip.example.com points to current IP address, no change is needed.
$ ./cf-ddns-updater -n
2022/04/21 21:55:08 Current IP address is: 203.0.113.3
2022/04/21 21:55:11 myip.example.com points to 203.0.113.2, the record will be updated.
2022/04/21 21:55:11 Check mode is active, no changes will be made.
To build the binary yourself, you need Go (version 1.17 or later).
First, clone the repository:
git clone [email protected]:imgrant/cf-ddns-updater.git
Then, change into the cloned directory and use go
to compile the source code:
cd cf-ddns-updater; go build