Skip to main content

A Python tool to update Cloudflare DNS automatically using DDNS.

Project description

This script updates a dns record in your Cloudflare account to match your current public IP address.
First it checks your IP address, and if it is different from the IP address in your Cloudflare dns record, it updates the dns record in Cloudflare.
It will run automatically at preset intervals.

Prerequisites

To run this script you need a Cloudflare User API Token
with the following Permissions:
Zone - Zone - Read
Zone - DNS - Edit
and the following Zone Resources:
Include - Specific zone - yourdomain.xxx

These permissions are necessary to check the names and IDs of your dns records (Zone Read)
and to change the IP address of a particular record (DNS Edit).

During setup, the script checks if crontab is installed and accessible.
If not, it will exit. In this case you should setup crontab or run the script as root.
In Debian 12 all users have crontab available
In Alpine linux the user needs to run crontab -e, and write a comment line to enable crontab.

How to obtain a Cloudflare API Token

Login to Cloudflare
Click on My Profile (top right)
Click on API Tokens
Click on the 'Create Token' button
Click on the 'Use template' button of Edit zone DNS
Modify Permissions so that you have the following settings:
Zone - Zone - Read
Zone - DNS - Edit
and the following Zone Resources:
Include - Specific zone - yourdomain.xxx
Click on the 'Continue to summary' button
Click on the 'Create Token' button.
Save the Token

Security

The Cloudflare token input is not visible on most terminals (similar to Linux password) and is saved in a json file readable only by the user (and root).

Installation

To install on recent Linux systems use pipx.
On older systems you can use pip.

On Debian or Ubuntu

  • apt install pipx

On Alpine Linux

  • apk add pipx

Once installed:

  • pipx ensurepath
  • Logout and login again (or reboot)
  • pipx install cloudflare-ddns-updater

Setup

To setup the program

  • cloudflare-ddns-updater --setup

To change IP check interval

  • cloudflare-ddns-updater --cron

To stop automatic ip update

  • cloudflare-ddns-updater --stop

To resume automatic IP update

  • cloudflare-ddns-updater --start

To change log level

  • cloudflare-ddns-updater --logs

To remove all files created by the script

  • cloudflare-ddns-updater --cleanup

To check the logs

  • follow the log file path shown after installation

To uninstall

  • cloudflare-ddns-updater --cleanup
  • pipx uninstall cloudflare-ddns-updater

Changes:
1.0.3 - Removed dns proxy from cloudflare and forced ttl to 120 seconds 1.0.2 - Added github repository
1.0.1 - Added log entries for cron changes
1.0.0 - First official release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cloudflare_ddns_updater-1.0.3.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

cloudflare_ddns_updater-1.0.3-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file cloudflare_ddns_updater-1.0.3.tar.gz.

File metadata

  • Download URL: cloudflare_ddns_updater-1.0.3.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for cloudflare_ddns_updater-1.0.3.tar.gz
Algorithm Hash digest
SHA256 a1e863c445ac47c18b69064f7e9ca5fbf979a12e145a76dde678ce3cafb5bfc2
MD5 ad3c5df96b43bac7cbb5f8591fe186d4
BLAKE2b-256 e2bed33fe55f75fd3a4811a3caa2953b3808ab35f73ecd20de125bfe456f4d27

See more details on using hashes here.

File details

Details for the file cloudflare_ddns_updater-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for cloudflare_ddns_updater-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e9b204237c6e373956724a6a2a17f1e1bc5bad8fd86f1a3804b9c13c33321f42
MD5 ca735c8626e4cc385023d53ef24f9a0f
BLAKE2b-256 dcdfc00b0f83ebf370c14f7965b1b47af9da7a6f16c987b7906e8d55d9080b29

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page