Skip to content

A simple Python CLI tool to bulk update DNS A records in your Cloudflare account, replacing an old IP address with a new one across multiple zones.

License

Notifications You must be signed in to change notification settings

BaseMax/cloudflare-dns-ip-migrator-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cloudflare-dns-ip-migrator

A simple Python CLI tool to bulk update DNS A records in your Cloudflare account, replacing an old IP address with a new one across multiple zones.

Features

  • Connects securely to Cloudflare via API Token.
  • Auto-paginates through all your zones (domains).
  • Filters DNS records by type and current IP value.
  • Supports dry-run mode for safe previews.
  • Outputs results in human-readable or JSON format.
  • Verbose logging for debugging.

Prerequisites

  • Python 3.7 or newer
  • A Cloudflare API Token with permissions:
    • Zone:Read
    • DNS:Edit
  • pip to install dependencies

Testing API Key

curl -X GET "https://api.cloudflare.com/client/v4/user/tokens/verify" \
     -H "Authorization: Bearer WRxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
     -H "Content-Type:application/json"

Installation

  1. Clone this repository:

    git clone https://github.com/BaseMax/cloudflare-dns-ip-migrator.git
    cd cloudflare-dns-ip-migrator
  2. Install required packages:

    pip install -r requirements.txt
  3. Ensure your API token is set in the environment:

    export CF_API_TOKEN="your_cloudflare_api_token"

Usage

The main script is cloudflare_dns_migrator.py. Run it with the following options:

python cloudflare_dns_migrator.py \  
  --old-ip 65.21.1.28 \  
  --new-ip 95.217.195.92 \  
  --type A \               # DNS record type (default: A)
  --zone example.com \     # (Optional) Limit to specific zones
  --dry-run \              # (Optional) Preview changes without applying
  --verbose \              # (Optional) Enable debug logging
  --json                   # (Optional) Output results as JSON

Examples

  • Dry run replacing A records across all zones:

    python cloudflare_dns_migrator.py --old-ip 1.2.3.4 --new-ip 5.6.7.8 --dry-run
  • Update only in example.com and test.org:

    python cloudflare_dns_migrator.py \
      --old-ip 1.2.3.4 \
      --new-ip 5.6.7.8 \
      --zone example.com \
      --zone test.org
  • Verbose JSON output:

    python cloudflare_dns_migrator.py \
      --old-ip 1.2.3.4 --new-ip 5.6.7.8 \
      --verbose --json

Configuration Flags

Flag Description
-o, --old-ip (Required) Old IP address to be replaced.
-n, --new-ip (Required) New IP address to set.
-r, --type DNS record type (A, AAAA, CNAME, TXT). Default: A
-z, --zone Limit to specific zone(s). Repeatable for multiple domains.
--dry-run Preview changes without making updates.
--verbose Enable detailed debug logging.
--json Output results in JSON format.

Contributing

Contributions, issues, and feature requests are welcome! Feel free to:

  • Open an issue to report bugs or request features.
  • Fork the repository and submit a pull request.

Please adhere to the existing code style and write clear commit messages.

License

This project is licensed under the MIT License

© 2025 Max Base.

About

A simple Python CLI tool to bulk update DNS A records in your Cloudflare account, replacing an old IP address with a new one across multiple zones.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages