CloudFlare DNS Service as a Dynamic DNS Provider (DDNS)
This week, I switched to a different telecommunications provider, which led to a dynamic public IP address. Consequently, in today’s blog post, I will discuss the implementation of CloudFlare DNS Service as a Dynamic DNS provider. This configuration ensures that services hosted on the home network remain accessible to remote users through a stable and automatically updated domain name.
Docker implementation
To avoid reinventing the wheel, I searched online to check if there was already a Docker-based service available for automatically updating Cloudflare’s A record with the current public IP. And I found it, I discovered a popular image that fulfills all my requirements: oznu/cloudflare-ddns
To run this service, I configured the docker-compose with the following settings:
1
2
3
4
5
6
7
8
9
10
11
12
13
version: '2'
services:
cloudflare-ddns:
image: oznu/cloudflare-ddns:latest
restart: always
container_name: cloudflare-ddns
environment:
- API_KEY=xxxxxxx
- ZONE=example.com
- SUBDOMAIN=subdomain
- PROXIED=false
- RRTYPE=A
This service every 5min (by default) checks the public IP and updates the DNS A record automatically.
Get Cloudflare API key
- From the Cloudflare dashboard, go to **My Profile ** > API Tokens.
- Select Create Token.
- Select the from the API token templates Edit zone DNS and press Use template.
- Select Continue to summary.
- Review the token summary. Select Edit token to make adjustments. You can also edit a token after creation.
- Select Create Token to generate the token’s secret.
- Copy the secret and use it as the environment variable API_KEY in the docker-compose.