An open API service indexing awesome lists of open source software.

https://github.com/bigcheeze45/cloudflare_ddns

Update Cloudflare DNS when public IP changes
https://github.com/bigcheeze45/cloudflare_ddns

cloudflare ddns-script ddns-updater python3

Last synced: about 1 month ago
JSON representation

Update Cloudflare DNS when public IP changes

Awesome Lists containing this project

README

          

# Dynamic DNS updater for Cloudflare

This script monitors your public IP address and automatically updates a specified
Cloudflare DNS record when your IP changes. Useful for maintaining access to
home servers or services when using dynamic IP addresses from ISPs.

This project is a Python implemtation of [Paul Sørensen's blog post](
https://paulsorensen.io/configure-ddns-with-cloudflare/) and does
not utilize Cloudflare Workers.

### Prerequisites
This script is helpful if the following conditions apply:

1. You have a domain.
2. Domain points to a server with a dynamic IP.
2. **DNS management is done via Cloudflare**. This script will not work as is if DNS records are managed somewhere else.

## Getting Started
If you use pip:

```shell
pip install --no-deps -r requirements.txt
```

If you use [poetry](https://python-poetry.org/):

```shell
poetry install
```
### Example `main.py`
```python
import requests
from dotenv import dotenv_values
from cloudflare import CloudflareError

from ddns_updater import update_dns_ip

if __name__ == "__main__":
# Load secrets from .env file
secrets = dotenv_values()
try:
record = update_dns_ip(**secrets)
if record:
# DNS updated
pass
except CloudflareError as ce:
pass
except requests.exceptions.HTTPError as htte:
pass
except Exception as e:
pass
```