This Cloudflare Worker provides a secure, dynamic DNS update endpoint. It accepts public IP updates from routers or scripts and uses Cloudflare’s API to update or create A, AAAA, or CNAME records as needed.
Originally written for the UniFi Network, but it will likely work with any DDNS-capable device that can call a custom URL.
-
✅ Automatically updates DNS records
-
✅ Automatically creates missing records
-
✅ Supports
A,AAAA, andCNAMEtypes -
✅ Configurable TTL and proxying
-
✅ Basic Authentication (to protect endpoint)
-
✅ Fully deployable via a single interactive CLI command
- A domain managed in Cloudflare
- A Cloudflare API Token with:
- Zone → DNS → Edit permissions
- Wrangler CLI
- Node.js 18 or later
This project includes an interactive deployment script that handles required secrets, variables, and deployment — no .env or wrangler.toml required.
git clone https://github.com/chedaroo/cloudflare-ddns-worker.git
cd cloudflare-ddns-worker
npm installwrangler loginThis opens a browser window to authenticate your Cloudflare account.
npm run deployThe script will prompt you for:
BASIC_AUTH_USER– protects the endpointBASIC_AUTH_PASS– protects the endpointCLOUDFLARE_API_TOKEN– used internally for Cloudflare API calls, see requirements above
Then it will:
- Deploy the Worker
- Apply the Worker secrets
- Print a summary and your deployed endpoint URL
Your deployed endpoint will look like:
https://cloudflare-ddns-worker.YOURNAME.workers.dev/update
| Parameter | Description | Default |
|---|---|---|
hostname |
Fully-qualified domain name to update | required |
ip |
IP address to assign | required |
proxied |
Whether to proxy via Cloudflare | true |
ttl |
Time-to-live (seconds) | 1 (auto) |
type |
DNS record type (A, AAAA, CNAME) |
A if new |
- Open UniFi Network Console
- Go to Settings → Internet → WAN → Advanced → Dynamic DNS
- Click Create New Dynamic DNS
- Fill out the form:
| Field | Value |
|---|---|
| Service | Custom |
| Hostname | Your FQDN (e.g., home.example.com) |
| Username | Your Basic Auth username (from the deploy prompt) |
| Password | Your Basic Auth password (from the deploy prompt) |
| Server | https://cloudflare-ddns-worker.YOURNAME.workers.dev/update?hostname=%h&ip=%i |
%hand%iare automatically replaced by UniFi with the configured hostname and your current public IP.
You can also append options like:
&proxied=false&ttl=300&type=A
- Protected via HTTP Basic Auth
- The username is passed as a runtime var
- The password and Cloudflare token are securely stored as Worker secrets
- No secrets or sensitive data are committed to version control
Cloudflare doesn't offer native Dynamic DNS functionality. This Worker bridges the gap by securely updating DNS records using standard HTTP requests from routers, servers, or home automation tools.
It’s lightweight, serverless, and requires no dedicated backend — a modern solution that integrates seamlessly with the Cloudflare ecosystem.