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.5 - Added date-time to Cloudflare record comment
Added log file path when --log option is used
1.0.4 - Fixed bug that would try to change the TXT or MX record\ if trying to change the root domain (mydomain.xxx)
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.5.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cloudflare_ddns_updater-1.0.5-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for cloudflare_ddns_updater-1.0.5.tar.gz
Algorithm Hash digest
SHA256 8ff22e86e975c288a724b3d5cdd42b346b99525b74d8161a2943539fcc9feb77
MD5 8a8eccddc7c43b98368ea6d09a88fa9d
BLAKE2b-256 f56ab4af199cfeed8dfdad4e5abc667ceb68e211fc84233585d40a14e8b4fb97

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cloudflare_ddns_updater-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3251f9490ebc8e647b58674d23bdfc3d9ed0f40ef694b82ead2a52cbafdc595c
MD5 83a72e80202d00cb93f65eb5c56084e8
BLAKE2b-256 aab40f78f959d9fb906abd3eacb80a2f874fcfa0914c3011aec0103fdbe3dd48

See more details on using hashes here.

Supported by

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