Python Cloudflare DDNS updater that auto-syncs DNS with current public IP
700
A Python-based Dynamic DNS (DDNS) updater for Cloudflare that automatically updates DNS records with your current public IP address. This tool focuses on IP address updates only and preserves existing TTL and proxy settings.
.env file with your configuration:API_TOKEN=your_cloudflare_api_token
ZONE_NAME=example.com
RECORDS=subdomain.example.com,another.example.com
docker run -d --env-file .env your-registry/cloudflare-ddns
pip install -r requirements.txt
export API_TOKEN=your_cloudflare_api_token
export ZONE_NAME=example.com
export RECORDS=subdomain.example.com
python main.py
| Variable | Description | Example |
|---|---|---|
API_TOKEN | Cloudflare API token with Zone:Read and DNS:Edit permissions | abc123... |
ZONE_NAME | The domain name of your Cloudflare zone | example.com |
Choose one of these approaches:
| Variable | Description | Example |
|---|---|---|
RECORDS | Comma or space-separated list of DNS records to update | home.example.com,vpn.example.com |
| Variable | Description | Default |
|---|---|---|
AUTO_DISCOVER | Automatically discover and update all A records in the zone | false |
| Variable | Description | Default |
|---|---|---|
INTERVAL | Update interval in seconds (0 = run once and exit) | 300 |
UPDATE_AAAA | Enable IPv6 (AAAA) record updates | false |
CREATE_IF_NOT_EXIST | Create DNS records if they don't exist (only when not using auto-discovery) | false |
VERBOSE | Enable verbose logging | false |
IP_SOURCE4 | IPv4 detection service URL | https://api.ipify.org |
IP_SOURCE6 | IPv6 detection service URL | https://api64.ipify.org |
Update specific DNS records every 5 minutes:
API_TOKEN=your_token
ZONE_NAME=example.com
RECORDS=home.example.com,vpn.example.com
INTERVAL=300
Automatically update all A records in your zone:
API_TOKEN=your_token
ZONE_NAME=example.com
AUTO_DISCOVER=true
INTERVAL=600
Enable both IPv4 and IPv6 updates:
API_TOKEN=your_token
ZONE_NAME=example.com
RECORDS=home.example.com
UPDATE_AAAA=true
Run once and exit (useful for cron jobs):
API_TOKEN=your_token
ZONE_NAME=example.com
RECORDS=home.example.com
INTERVAL=0
version: '3.8'
services:
cloudflare-ddns:
image: your-registry/cloudflare-ddns
restart: unless-stopped
environment:
- API_TOKEN=your_cloudflare_api_token
- ZONE_NAME=example.com
- RECORDS=home.example.com,vpn.example.com
- INTERVAL=300
- VERBOSE=false
docker build -t cloudflare-ddns .
Zone:Read - Include All zonesDNS:Edit - Include Specific zone:your-domain.comThe application provides comprehensive logging:
Example log output:
2023-10-09 12:00:00 - cloudflare-ddns - INFO - Starting Cloudflare DDNS updater
2023-10-09 12:00:00 - cloudflare-ddns - INFO - Zone: example.com
2023-10-09 12:00:01 - cloudflare-ddns - INFO - Current IPv4 address: 203.0.113.42
2023-10-09 12:00:01 - cloudflare-ddns - INFO - Update A home.example.com: 203.0.113.1 → 203.0.113.42
2023-10-09 12:00:02 - cloudflare-ddns - INFO - No change for A vpn.example.com (still 203.0.113.42)
The application includes robust error handling:
ZONE_NAME matches exactly with CloudflareEnable verbose logging for troubleshooting:
VERBOSE=true
This project is open source. See the LICENSE file for details.
Contributions are welcome! Please feel free to submit issues and pull requests.
Content type
Image
Digest
sha256:037696cce…
Size
24.1 MB
Last updated
11 months ago
docker pull swaya1125/cloudflare-ddns