5.9 KiB
Cloudflare DDNS Updater
Cloudflare DDNS Updater keeps Cloudflare DNS records pointed at the machine's current public IPv4 and/or IPv6 address.
The container reads:
- Environment variables from Docker, usually via
--env-file .env. - DNS update rules from
/home/node/app/configs/UpdaterConfig.jsoninside the container.
Quick Start
Pull the published image:
docker pull ghcr.io/yuzuzensai/cloudflare-ddns-updater:latest
Create .env from the example:
cp .env.example .env
Edit .env and set your Cloudflare API token:
NODE_ENV=production
EXAMPLE_SITE_TOKEN=replace-with-cloudflare-api-token
Create configs/UpdaterConfig.json:
[
{
"token": "{ENV_TOKEN:EXAMPLE_SITE_TOKEN}",
"updateInterval": 60,
"zone": [
{
"id": "cloudflare-zone-id",
"type": "A",
"name": "example.com",
"content": "{CURRENT_IPv4}",
"ttl": 1,
"proxied": false
},
{
"id": "cloudflare-zone-id",
"type": "AAAA",
"name": "example.com",
"content": "{CURRENT_IPv6}",
"ttl": 1,
"proxied": false
}
]
}
]
Run the container:
docker run -d \
--name cloudflare-ddns-updater \
--restart unless-stopped \
--env-file .env \
-v "$(pwd)/configs:/home/node/app/configs" \
ghcr.io/yuzuzensai/cloudflare-ddns-updater:latest
View logs:
docker logs -f cloudflare-ddns-updater
Docker Compose
services:
cloudflare-ddns-updater:
image: ghcr.io/yuzuzensai/cloudflare-ddns-updater:latest
container_name: cloudflare-ddns-updater
restart: unless-stopped
env_file:
- .env
volumes:
- ./configs:/home/node/app/configs
Start it with:
docker compose up -d
Configuration
configs/UpdaterConfig.json is an array of Cloudflare account/token configurations.
Each top-level object uses these fields:
token: Cloudflare API token, or an environment reference like{ENV_TOKEN:EXAMPLE_SITE_TOKEN}.updateInterval: update interval in seconds.zone: DNS records to manage.
Each zone entry uses these fields:
id: Cloudflare zone ID.type: DNS record type, usuallyAorAAAA.name: DNS record name, for exampleexample.comorhome.example.com.content:{CURRENT_IPv4}for anArecord or{CURRENT_IPv6}for anAAAArecord.ttl: Cloudflare TTL. Use1for automatic TTL.proxied: Cloudflare proxy status,trueorfalse.
Important: keep the JSON property order shown in the examples. The current config validator expects exact key order.
Cloudflare Zone ID And Token
You need two Cloudflare values before running the updater:
- Zone ID: identifies the Cloudflare zone/domain that contains the DNS records.
- API token: authorizes the updater to read and edit DNS records in that zone.
The Zone ID goes in configs/UpdaterConfig.json as zone[].id.
The API token should go in .env, then configs/UpdaterConfig.json references it with {ENV_TOKEN:VARIABLE_NAME}. The variable name is up to you. EXAMPLE_SITE_TOKEN, HOME_SITE_TOKEN, MY_DOMAIN_TOKEN, or any other valid environment variable name will work as long as both files use the same name.
Get Your Zone ID
- Log in to the Cloudflare dashboard.
- Select the domain you want to update.
- Open the domain overview page.
- Find
Zone IDin the right sidebar underAPI. - Copy that value into each matching
zone[].idfield inconfigs/UpdaterConfig.json.
Example:
{
"id": "023e105f4ecef8ad9ca31a8372d0c353",
"type": "A",
"name": "home.example.com",
"content": "{CURRENT_IPv4}",
"ttl": 1,
"proxied": false
}
Create an API Token
- Log in to the Cloudflare dashboard.
- Click your profile icon in the top-right corner.
- Open
My Profile. - Open
API Tokens. - Select
Create Token.
The easiest option is the built-in template:
- Find the
Edit zone DNStemplate. - Select
Use template. - Under
Zone Resources, selectInclude>Specific zone> your domain. - Leave the permissions as DNS edit/read permissions.
- Select
Continue to summary. - Review the token summary.
- Select
Create Token. - Copy the token immediately. Cloudflare only shows it once.
If you create a custom token instead, use this setup:
- Select
Create Custom Token. - Give it a clear name, for example
Cloudflare DDNS Updater. - Add these permissions:
Zone>DNS>EditZone>Zone>Read
Set the zone resource scope:
- Under
Zone Resources, chooseInclude. - Choose
Specific zone. - Select the domain this updater will manage.
- Select
Continue to summary. - Review the token summary.
- Select
Create Token. - Copy the token immediately. Cloudflare only shows it once.
Do not use your Global API Key. This app only needs a scoped API token with DNS access for the selected zone.
After creating the token, copy it into .env. The name before = is the environment variable name. You can change it.
EXAMPLE_SITE_TOKEN=your-cloudflare-api-token
If you change the variable name in .env, update the token value in configs/UpdaterConfig.json to match it exactly.
Example:
HOME_SITE_TOKEN=your-token
"token": "{ENV_TOKEN:HOME_SITE_TOKEN}"
Another example with a different name:
MY_DOMAIN_TOKEN=your-token
"token": "{ENV_TOKEN:MY_DOMAIN_TOKEN}"
Do not include the literal token in UpdaterConfig.json unless you intentionally want the secret stored there. Using {ENV_TOKEN:...} keeps the token in .env, which is ignored by git.
Notes
- The updater fetches IPv4 from
https://api.ipify.org?format=json. - The updater fetches IPv6 from
https://api64.ipify.org/?format=json. - If
configs/UpdaterConfig.jsonis missing, the app creates one from the bundled example, but you must edit it before real use.