This Python script is designed to update your DNS records with your current external IP address. It uses the Cloudflare API to fetch and update the DNS records for a specified zone.
This script is currently configured to only update 'A' type DNS records for a single Cloudflare zone. The zone ID is hardcoded in an environment variable, as I only have access to one Cloudflare zone at the moment. If you need to update other record types or manage multiple zones, you will need to modify the script accordingly.
- Retrieves the external IP address of the machine using the
ipify.org
API. - Fetches the existing DNS records for the specified Cloudflare zone.
- Updates the DNS records with the new external IP address.
- Logs all actions to a log file (
py_logs.log
) for debugging purposes.
- Python 3.6 or higher
- Cloudflare API credentials (API key and zone ID)
- Environment variables for Cloudflare credentials and zone ID
- Clone the repository:
git clone https://github.com/your-username/rpi-cloudflare-ddns.git
- Change to the project directory:
cd rpi-cloudflare-ddns
- Create a virtual environment and activate it:
python3 -m venv venv
source venv/bin/activate
- Install the required dependencies:
pip install -r requirements.txt
- Set the environment variables for Cloudflare credentials and zone ID:
export CLOUDFLARE_API_KEY=your_cloudflare_api_key
export ZONE_ID=your_cloudflare_zone_id
- Run the script:
python main.py
The script will automatically update the DNS records with the current external IP address. You can set up a cron job or a systemd service to run the script periodically to keep the DNS records up-to-date.
This project is licensed under the MIT License.
- The Cloudflare Python API library: https://github.com/cloudflare/python-cloudflare
- The
ipify.org
API for retrieving the external IP address