This script migrates DNS records from Cloudflare to PowerDNS using the PowerDNS-Admin MySQL database. It fetches all DNS records from Cloudflare's API and adds them directly to your PowerDNS instance.
- Fetches DNS records from all zones in Cloudflare.
- Adds records to PowerDNS-Admin MySQL database.
- Supports common record types:
A,AAAA,CNAME,MX,TXT,NS,SRV. - Automatically creates entries in the
recordstable of PowerDNS. - Proxied Cloudflare records are not included in PowerDNS since PowerDNS doesn't support proxying.
- Python 3 installed on your machine.
- MySQL or MariaDB instance running for PowerDNS-Admin.
- Cloudflare API Token with
DNS:Editpermissions. - PowerDNS-Admin MySQL credentials.
git clone https://github.com/MrAriaNet/cloudflare-to-pdns.git
cd cloudflare-to-pdnsInstall the required Python packages:
pip install -r requirements.txtIf you don't have a requirements.txt file, you can manually install the required Python package:
pip install mysql-connector requestsEdit the script to set your Cloudflare API Token and PowerDNS MySQL credentials:
# Cloudflare API settings
CLOUDFLARE_API_TOKEN = "YOUR_CF_API_TOKEN"
CF_API_URL = "https://api.cloudflare.com/client/v4/zones"
# MySQL (PowerDNS-Admin) settings
DB_HOST = "localhost"
DB_USER = "root"
DB_PASSWORD = "password"
DB_NAME = "powerdns"After configuring the script, you can run it with:
python3 cf_to_pdns_mysql.pyAfter running the script, check your PowerDNS-Admin instance to ensure the DNS records have been successfully added.
- Fetches Cloudflare Zones: The script fetches all zones from Cloudflare using the Cloudflare API.
- Fetches DNS Records: For each zone, the script fetches all DNS records associated with that zone.
- Inserts Records into PowerDNS: The script then inserts the DNS records into your PowerDNS MySQL database, specifically into the
recordstable. - Domain Mapping: It uses the domain names from Cloudflare to match records with corresponding domain entries in PowerDNS-Admin.
AAAAACNAMEMXTXTNSSRV
- Proxied Cloudflare Records: This script does not handle Cloudflare’s proxied records (orange cloud). Since PowerDNS doesn’t support proxying, these records will not be included in the migration.
- SRV Records: SRV records are included, but specific handling for CAA or PTR records is not implemented.
If you encounter any issues, make sure:
- The
PowerDNS-AdminMySQL instance is accessible and the correct credentials are provided. - The
recordsanddomainstables exist in the PowerDNS-Admin MySQL database. - The Cloudflare API token has the correct permissions (
DNS:Edit).
This project is licensed under the MIT License - see the LICENSE file for details.