Skip to content

Dynamic DNS (DDNS) service based on Cloudflare! Access your network remotely via a custom domain name without a static IP!

Notifications You must be signed in to change notification settings

selcarpa/cloudflare-ddns

Repository files navigation

Cloudflare-ddns

简体中文

introduce

This is a simple application for updating the current public IP address to Cloudflare DNS records. Applicable scene:

  • The device uses dynamic public network IPv4 to access the Internet
  • The device does not have public IPv4, but has public IPv6
  • Do not have administrative rights to the router, but want to use a domain name to access a device on the LAN

The project provides:

  1. Native version (including docker support), supports Windows (x86), Linux (x86), Linux (Arm), waiting for dependency updates
  2. Java version (including docker support), supports jvm-17 compatible platform

Features provided:

  • Support ipv4/ipv6
  • Super quick to start and generate configuration files
  • Detailed custom configuration, including:
    • Multi-domain name support, cross-zone support, cross-account support
    • Customize the URL for checking ipv4/ipv6 addresses
  • Quick functions
    • One-time operation
    • Clean DNS records

Quick start

native version

  1. Go to release to download the latest version of the current system and rename it to cf-ddns (Windows: cf-ddns.exe)
  2. Open the terminal under the current path and run
    #Linux
    ./cf-ddns -gen -zoneId=xxxXXxxXXXxzoneIdxxxXXXx -authKey=XXXxauthKeyxxxXXXx -domain=ex.example.com -v4=true -v6=false
    #Windows
    ./cf-ddns.exe -gen -zoneId=xxxXXxxXXXxzoneIdxxxXXXx -authKey=XXXxauthKeyxxxXXXx -domain=ex.example.com -v4=true -v6=false
  3. Observe whether DNS records in Cloudflare are updated
Start using Docker

native-docker version

  1. Create docker-compose.yml file
    services:
      cf-ddns:
        image: selcarpa/cloudflare-ddns:latest
        # network_mode: "host" # If -v6 is true, you need to use the host network mode
        container_name: cf-ddns
        # environment: # In the default comment of cf-ddns, the update time is recorded, and the time zone can be set here
        #  - TZ=Asia/Shanghai
        restart: unless-stopped # Restart strategy
        command: ["-gen","-zoneId=xxxXXxxXXXxzoneIdxxxXXXx","-authKey=XXXxauthKeyxxxXXXx","-domain=ex.example.com","-v4=true","-v6=false"] # Start command
  2. Start
     docker-compose up -d
A Java version is also provided.

java version

  1. Go to release to download the latest jar version and rename it to cf-ddns.jar
  2. run
    java -jar -Xmx30m cf-ddns.jar -gen -zoneId=xxxXXxxXXXxzoneIdxxxXXXx -authKey=XXXxauthKeyxxxXXXx -domain=ex.example.com -v4=true -v6=false

java-docker version

  1. Create docker-compose.yml file
    services:
      cf-ddns:
        image: selcarpa/cloudflare-ddns-jvm:latest
        # network_mode: "host" # If -v6 is true, you need to use the host network mode
        container_name: cf-ddns
        # environment: # In the default comment of cf-ddns, the update time is recorded, and the time zone can be set here
        #  - TZ=Asia/Shanghai
        restart: unless-stopped # Restart strategy
        command: ["-gen","-zoneId=xxxXXxxXXXxzoneIdxxxXXXx","-authKey=XXXxauthKeyxxxXXXx","-domain=ex.example.com","-v4=true","-v6=false"] # Start command
  2. Start
     docker-compose up -d

More features

Custom start cloudflare-ddns

Starting Cloudflare-ddns through the configuration file can achieve more functions, such as:

  • Multiple domain names support
  • Customize the URL for checking ipv4/ipv6 addresses
  • Custom ttl
  • Automatically clean DNS records
  • cloudflare proxy support
  • ttl check

Write configuration file

The configuration file supports toml and json/json5 formats. Here json5 is used as an example.

//Complete example:
{
  "common": {
    "zoneId": "xxxXXxxXXXxzoneIdxxxXXXx",
    "authKey": "XXXxauthKeyxxxXXXx",
    "v4": false,
    "v6": true,
    "ttl": 300,
    "ttlCheck": true,
    "checkUrlV4": "https://w4.tain.one/",
    "checkUrlV6": "https://w6.tain.one/",
    "autoPurge": true,
    "proxied": true,
    "comment": "cf-ddns auto update",
    "reInit": 5
  },
  "domains": [
    {
      "name": "ex.example.com",
      "properties": {
        "zoneId": "xxxXXxxXXXxzoneIdxxxXXXx",
        "authKey": "XXXxauthKeyxxxXXXx",
        "v4": true,
        "v6": false,
        "ttl": 300,
        "ttlCheck": true,
        "checkUrlV4": "https://w4.tain.one/",
        "checkUrlV6": "https://w6.tain.one/",
        "autoPurge": true,
        "proxied": true,
        "comment": "cf-ddns auto update",
        "reInit": 5
      }
    }
  ]
}
Toml example
[common]
zoneId = "xxxXXxxXXXxzoneIdxxxXXXx"
authKey = "XXXxauthKeyxxxXXXx"
v4 = false
v6 = true
ttl= 300
ttlCheck= true
checkUrlV4= "https://w4.tain.one/"
checkUrlV6= "https://w6.tain.one/"
autoPurge= true
proxied= true
comment= "cf-ddns auto update"
reInit= 5

[[domains]]
name = "ex1.example.com"

[domains.properties]
zoneId = "xxxXXxxXXXxzoneIdxxxXXXx"
authKey = "XXXxauthKeyxxxXXXx"
v4 = false
v6 = true
ttl= 300
ttlCheck= true
checkUrlV4= "https://w4.tain.one/"
checkUrlV6= "https://w6.tain.one/"
autoPurge= true
proxied= true
comment= "cf-ddns auto update"
reInit= 5

[[domains]]
name = "ex2.example.com"

[domains.properties]
zoneId = "xxxXXxxXXXxzoneIdxxxXXXx"
authKey = "XXXxauthKeyxxxXXXx"
v4 = false
v6 = true
ttl= 300
ttlCheck= true
checkUrlV4= "https://w4.tain.one/"
checkUrlV6= "https://w6.tain.one/"
autoPurge= true
proxied= true
comment= "cf-ddns auto update"
reInit= 5
The top level of the configuration file
Field name Type Required Description
domains Array (Domain) Yes Domain name configuration
common Properties Yes Common configuration
Domain
Field name Type Required Description
name String yes domain name
properties Properties No Domain name configuration, if it exists, will overwrite the configuration in common. If any configuration here is empty, use the configuration in common
Properties
Field name Type Required Description
zoneId String yes zone id from cloudflare
authKey String yes authKey from cloudflare
checkUrlV4 String No Check the url of ipv4, the default is https://api4.ipify.org?format=text
checkUrlV6 String No Check the url of ipv6, the default is https://api6.ipify.org?format=text
v4 Boolean type No Whether to enable ipv4, the default is true
v6 Boolean type No Whether to enable ipv6, the default is false
ttl Integer number No DNS record ttl, seconds, default is 300
autoPurge Boolean type No Whether to automatically clean up DNS records, the default is false
proxied Boolean type No Whether to enable cloudflare proxy, the default is false
comment String No Comments, which are used to display on cloudflare dashboard and do not have any impact on functionality, default to "cf-ddns auto update", if you need not to display, please manually override to empty string
ttlCheck Boolean type No Whether to enable ttl check, the default is false
reInit Integer number No After the number of tasks, re-initialize the basic information of the domain name, the default is 300 divided by the TTL value, if it is 0, the reinit-task will not invoke, after the number of tasks, re-check the record of the domain name on Cloudflare, to avoid deleting the domain name due to other operations, resulting in the failure to automatically re-create the domain name

Start cloudflare-ddns via the configuration file

native version

#Linux
./cf-ddns -c=config.json5
# Windows
./cf-ddns.exe -c=config.json5
Docker version
    services:
      cf-ddns:
        image: selcarpa/cloudflare-ddns:latest
        # network_mode: "host" If you have an IPv6 DDNS item, you need to use the host network mode
        container_name: cf-ddns
        # environment: # In the default comment of cf-ddns, the update time is recorded, and the time zone can be set here
        #  - TZ=Asia/Shanghai
        volumes:
          - /path/to/config.json5:/cf-ddn/config.json5 # Mount the configuration file. Note that /path/to/config.json5 needs to be replaced with the actual path.
        restart: unless-stopped # Restart strategy
        command: [ "-c=/cf-ddn/config.json5" ] # Start command

java version

java -jar -Xmx30m cf-ddns.jar -c=config.json5
Docker version
     services:
       cf-ddns:
         image: selcarpa/cloudflare-ddns-jvm:latest
         # network_mode: "host" If you have an IPv6 DDNS item, you need to use the host network mode
         container_name: cf-ddns
         # environment: # In the default comment of cf-ddns, the update time is recorded, and the time zone can be set here
         #  - TZ=Asia/Shanghai
         volumes:
           - /path/to/config.json5:/cf-ddns/config.json5 # Mount the configuration file. Note that /path/to/config.json5 needs to be replaced with the actual path.
         restart: unless-stopped # Restart strategy
         command: [ "-c=/cf-ddn/config.json5" ] # Start command

Startup parameters realize the function of single operation

  • -once will only be executed once and will not start the scheduled task
  • -purge cleans DNS records and does not start scheduled tasks
  • -debug turns on debug mode and will output more logs
  • -gen generates a configuration file template. This is the quick start command above and needs to be used with the following parameters.
    • -zoneId zone id from Cloudflare, required
    • -authKey authKey from Cloudflare, required
    • -domain domain name, required
    • -v4 Whether to enable ipv4, optional, default is true
    • -v6 Whether to enable ipv6, optional, default is false