mirror of
https://github.com/0xGingi/cloudflare-dynamic-dns-updater.git
synced 2026-09-21 11:34:21 -04:00
No description
- Shell 96.2%
- Dockerfile 3.8%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .gitignore | ||
| cf-ddns.sh | ||
| docker-compose.yml | ||
| Dockerfile | ||
| env.example | ||
| README.md | ||
Cloudflare Dynamic DNS Updater
This script automatically updates Cloudflare A and AAAA DNS records for specified subdomains across one or multiple zones to match the host's current public IPv4 and IPv6 addresses. It runs continuously, checking for IP changes every hour.
How it Works
The script fetches the current public IPv4 and IPv6 addresses using ifconfig.co. It then uses the Cloudflare API to:
- Get the Zone ID(s) for the specified zone(s).
- For each subdomain in each configured zone:
- Query the existing A and AAAA records.
- If a record doesn't exist, create it with the current IP.
- If a record exists but the IP is different, update it.
- Sleep for one hour before repeating the process.
Requirements
dockerdocker compose- A Cloudflare API Token with
Zone:ReadandDNS:Editpermissions. - Your Cloudflare Zone Name.
Setup
-
Clone the repository:
git clone https://github.com/0xgingi/cloudflare-dynamic-dns-updater cd cloudflare-dynamic-dns-updater -
Create an environment file: Copy the example file:
cp env.example .envEdit
.envand configure your zones. You can use either single zone or multiple zones configuration:Single Zone Configuration (backward compatible):
# Cloudflare API Token (generate from Cloudflare dashboard) # Ensure the token has Zone:Read and DNS:Edit permissions CF_API_TOKEN=YOUR_CLOUDFLARE_API_TOKEN # Your Cloudflare Zone Name (e.g., example.com) CF_ZONE_NAME=yourdomain.com # Space-separated list of subdomains to update (e.g., "www blog api") CF_SUBDOMAINS="sub1 sub2 sub3" # Space-separated list of record types to update (e.g., "A AAAA", "A", "AAAA") CF_RECORD_TYPES="A AAAA"Multiple Zones Configuration:
# Cloudflare API Token (generate from Cloudflare dashboard) # Ensure the token has Zone:Read and DNS:Edit permissions CF_API_TOKEN=YOUR_CLOUDFLARE_API_TOKEN # Multiple zones configuration # Format: "zone1:subdomain1,subdomain2 zone2:subdomain3,subdomain4" CF_ZONE_CONFIGS="example.com:www,blog,api other.com:mail,ftp" # Space-separated list of record types to update (e.g., "A AAAA", "A", "AAAA") CF_RECORD_TYPES="A AAAA"
Run
- Build the Docker image:
docker compose build - Run the container:
docker compose up -d