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.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.4.tar.gz (11.5 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.4-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cloudflare_ddns_updater-1.0.4.tar.gz
  • Upload date:
  • Size: 11.5 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.4.tar.gz
Algorithm Hash digest
SHA256 ea21c5e9a061c41eac57ea399d391eda04f6ef61986a3f2413b7621f059fd93f
MD5 ef852fc8b119df7e85c8ff537d915c94
BLAKE2b-256 b499b3cc3615854eba1870b685fa15ba3fb2421c5747028beb431b866a2608b0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cloudflare_ddns_updater-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 72018a728ee50b18e477d3e861a14807f4b3c24f8ea5f6d2c5acfc8e75905f26
MD5 268aaa9370d01750ed97a6cbbd20c6bd
BLAKE2b-256 fbbf1a31c205cfccdc9cb01820e1365fc4269c9d8b2fb05e3e1cfa5ce96b585e

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