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.
- 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.
- Python 3.7 or newer
- A Cloudflare API Token with permissions:
- Zone:Read
- DNS:Edit
pip
to install dependencies
curl -X GET "https://api.cloudflare.com/client/v4/user/tokens/verify" \
-H "Authorization: Bearer WRxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type:application/json"
-
Clone this repository:
git clone https://github.com/BaseMax/cloudflare-dns-ip-migrator.git cd cloudflare-dns-ip-migrator
-
Install required packages:
pip install -r requirements.txt
-
Ensure your API token is set in the environment:
export CF_API_TOKEN="your_cloudflare_api_token"
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
-
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
andtest.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
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. |
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.
This project is licensed under the MIT License
© 2025 Max Base.