A lightweight and efficient solution for Dynamic DNS (DDNS) updates using Cloudflare's API. This script checks your public IP address and updates your Cloudflare DNS record if it has changed.
- Updates Cloudflare DNS records dynamically based on public IP changes.
- Can be run as a standalone script or as a Dockerized cron job.
- A Cloudflare API token with permissions to manage DNS records.
- The
zone IDandrecord IDof the DNS record you want to update.
Clone the repository, ensure curl, jq are installed in your system and execute the script:
DOMAIN="your-domain.com" \
CF_API_TOKEN="your-cloudflare-api-token" \
CF_ZONE_ID="your-zone-id" \
CF_RECORD_ID="your-record-id" \
./cf_ddns.shBuild the Docker image:
docker build -t cloudflare-ddns .Run the container:
docker run -d \
-e DOMAIN="your-domain.com" \
-e CF_API_TOKEN="your-cloudflare-api-token" \
-e CF_ZONE_ID="your-zone-id" \
-e CF_RECORD_ID="your-record-id" \
cloudflare-ddnsBy default, the script runs as a cron job every minute. To modify the schedule, set the CRON_SCHEDULE environment variable.
Example:
docker run -d \
-e DOMAIN="your-domain.com" \
-e CF_API_TOKEN="your-cloudflare-api-token" \
-e CF_ZONE_ID="your-zone-id" \
-e CF_RECORD_ID="your-record-id" \
-e CRON_SCHEDULE="*/5 * * * *" \
cloudflare-ddnsThis example runs the script every 5 minutes.
| Variable | Description | Example |
|---|---|---|
DOMAIN |
The Fully Qualified Domain Name (FQDN). | example.com |
CF_API_TOKEN |
Cloudflare API token with DNS permissions. | your-api-token |
CF_ZONE_ID |
The Zone ID for your domain in Cloudflare. | zone-id |
CF_RECORD_ID |
The DNS record ID to update. | record-id |
CRON_SCHEDULE |
(Optional) Cron schedule for the job. | */5 * * * * (default: * * * * *) |
This project is licensed under the MIT License.