A simple, to the point python script to update Cloudflare DNS records with a dynamic IP.
1.4K
A simple, to the point python script to update Cloudflare DNS records with a dynamic IP. Also possible using Docker.
I recently set up my first homelab, using Cloudflare to reverse proxy into it from my own domain. But having an ISP that only provides dynamic IPs, I needed some way to update the IP in the DNS records. There's several solutions for this around, but none that I found were completely to my liking, so I decided to make my own.
pip requirementsFirst, you'll need:
.env file which defines:
API_TOKEN environment variableZONE_ID environment variableAPI_TOKEN_FILE and ZONE_ID_FILERUN_EVERY environment variable which contains the number of seconds to wait before the next IP check. If not included, checks every 60s.domains.json file which defines an array of DNS names to update:
mybestcfzone.org and you want to update the bestest subdomain, only add
bestest to the array)@ as the subdomain nameCreate a docker-compose.yml file with the following content:
services:
app:
image: fedeabella/cloudflare-ddns
container_name: cloudflare-ddns
env_file: .env
environment:
- TZ=America/Montevideo
read_only: true
restart: always
volumes:
- type: bind
source: ./config
target: /app/config
Put the .env in the same directory as the
docker-compose.yml file and create a ./config directory where the domains.json file will be put. Then run
docker compose up -d
You can check the docker logs to see if the container is running the script properly:
docker logs cloudflare-ddns
This was very much built in a couple afternoons to satisfy my personal needs, so it may not have everything you need. For example:
A recordsIf you find something you need, feel free to create an Issue on github and I might look into it, but no promises.
Content type
Image
Digest
sha256:d8cabbc86…
Size
30.5 MB
Last updated
19 days ago
docker pull fedeabella/cloudflare-ddns