This article is an upgrade of the guide to update dynamic IP for domain names via Cloudflare that I shared before. Instead of using bash script and setting up cron, I now switch to installing using Docker for quickness.
I use Docker image of author timothymiller shared here: https://github.com/timothymiller/cloudflare-ddns
1. Requirements
- Already have a domain name and a Cloudflare account.
- The domain has been transferred to CloudFlare management.
- Linux Server / virtual machine (Ubuntu / Arch / CentOS / …) with Docker and Docker Compose pre-installed
2. Prepare parameters from Cloudflare
You need to prepare the following parameters from Cloudflare
- API Token
- Zone ID
- Subdomain (A record)
3. Install Cloudflare-ddns
Create a new folder on server
mkdir ~/cloudflare-ddns
cd ~/cloudflare-ddns
Code language: Bash (bash)
Create config.json file
nano config.json
Code language: CSS (css)
And enter the Content as below. Note that the parameters need to be changed:
- api_token (line 5): Cloudflare API Token.
- zone_id (line 11): Zone ID of the domain.
- name (line 14): the submain you use to update IP. For example: subdomain is homeserver.markknow.com then just enter homeserver
{
"cloudflare": (
{
"authentication": {
"api_token": "So5eFPERxxxxxxxxxxxxxxxx4U4YRwu80Op",
"api_key": {
"api_key": "",
"account_email": ""
}
},
"zone_id": "aeb40exxxxxxxxxxxxxxxxxaf51a0b",
"subdomains": (
{
"name": "homeserver",
"proxied": false
}
)
}
),
"a": true,
"aaaa": true,
"purgeUnknownRecords": false,
"ttl": 300
}
Code language: JSON / JSON with Comments (json)
Create file compose.yml
enter the content below and save
services:
cloudflare-ddns:
image: timothyjmiller/cloudflare-ddns:latest
container_name: cloudflare-ddns
security_opt:
- no-new-privileges:true
network_mode: 'host'
environment:
- PUID=1000
- PGID=1000
volumes:
- ./config.json:/config.json
restart: unless-stopped
Code language: YAML (yaml)
Activate by command
docker compose up -d
This application will automatically check the Public IP every 15 minutes and update the new IP to Cloudflare if it detects any change.
It is done.