Automatically update your Cloudflare A Record.
1.8K

This repository contains a Python script that dynamically updates a Cloudflare DNS "A" record with the machine's current public IP address. The script is intended to be run as a cron-like job, periodically checking the IP address and updating Cloudflare if a change is detected.
| Variable | Description | Required | Default |
|---|---|---|---|
ZONE | The Cloudflare zone (domain) to which the record belongs. | Yes | |
DNS_RECORD | The A Record that needs to be updated. | Yes | |
CLOUDFLARE_AUTH_EMAIL | Cloudflare account email for authentication. | Yes | |
CLOUDFLARE_AUTH_KEY | Cloudflare API key for authentication. | Yes | |
CRON_SCHEDULE | Cron schedule for updates (in cron format). | No | 0 */6 * * * (every 6 hours) |
EXPORT_CF_UPDATE_ERROR_LOGS | Log detailed Cloudflare API errors. | No | false |
EXECUTE_AT_START | Run the update when the script starts. | No | false |
TZ | Timezone for logs. | No | Europe/Berlin |
PUID | User ID for file permissions (useful in containers). | No | 0 (root) |
PGID | Group ID for file permissions (useful in containers). | No | 0 (root) |
ZONE: this is your domain, for example mywebsite.comDNS_RECORD: you need to put the Name of your A Record, for example mywebsite.com.CLOUDFLARE_AUTH_KEY: in the Cloudflare dashboard go to Your Profile > API Token > Global API Keyservices:
cloudflare-ddns-updater:
image: reaper0x1/cloudflare-ddns-updater:latest
container_name: cloudflare-ddns-updater
environment:
# Put your cron schedule.
# You can generate one at https://crontab.guru/
- CRON_SCHEDULE=0 */6 * * *
# Your timezone
- TZ=Europe/Berlin
# Cloudflare
- ZONE=site.com
- DNS_RECORD=site.com
- [email protected]
- CLOUDFLARE_AUTH_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# Set to true if you want to export the json response error during the update of A Record
- EXPORT_CF_UPDATE_ERROR_LOGS=false
# Set to true if you want to start the script at the start of the container
- EXECUTE_AT_START=false
# The users belongs to files.
- PUID=1000
- PGID=1000
# Comment out the following two lines if logs are not needed
volumes:
- ./logs:/app/logs
restart: unless-stopped
services:
cloudflare-ddns-updater:
image: reaper0x1/cloudflare-ddns-updater:latest
container_name: cloudflare-ddns-updater
env_file: .env
# Comment out the following two lines if logs are not needed
volumes:
- ./logs:/app/logs
restart: unless-stopped
services:
cloudflare-ddns-updater:
build: .
container_name: cloudflare-ddns-updater
env_file: .env
# Comment out the following two lines if logs are not needed
volumes:
- ./logs:/app/logs
restart: unless-stopped
This repository provides a bash script you can use if you don't want a Docker container.
Clone the repository:
git clone https://github.com/Reaper0x1/cloudflare-ddns-updater && cd cloudflare-ddns-updater
You have to edit these variables inside the script:
Run the script:
./ddns-updater.sh
If you want to log everything simply redirect the output to a file:
./ddns-updater.sh > log.txt
(Optional) You can set up a cron job to run the script periodically.
crontab -e
0 */6 * * * /usr/bin/bash /path-to-script/ddns-updater.sh
0 */6 * * * /usr/bin/bash /path-to-script/ddns-updater.sh >> /path-to-log/ddns-updater.log
crontab -lContent type
Image
Digest
sha256:679325463…
Size
31.1 MB
Last updated
over 1 year ago
docker pull reaper0x1/cloudflare-ddns-updater