cloudflare-ddns

cloudflare-ddns

Cloudflare DDNS更新器,高效管理动态DNS记录

Cloudflare DDNS更新器是一款高效的动态DNS管理工具。它能自动检测公网IP并更新DNS记录,支持多种域名类型,包括国际化域名和通配符域名。该工具兼容IPv4和IPv6,集成了Cloudflare特有功能,如代理和DNS记录注释。此外,它还注重隐私保护,提供多种通知方式,满足不同用户的动态DNS管理需求。

CloudflareDDNSDNSIP地址更新DockerGithub开源项目

🌟 Cloudflare DDNS

Github Source Go Reference Codecov Docker Image Size OpenSSF Best Practices OpenSSF Scorecard

A feature-rich and robust Cloudflare DDNS updater with a small footprint. The program will detect your machine's public IP addresses and update DNS records using the Cloudflare API.

📜 Highlights

⚡ Efficiency

  • 🤏 The Docker image takes less than 5 MB after compression.
  • 🔁 The Go runtime re-uses existing HTTP connections.
  • 🗃️ Cloudflare API responses are cached to reduce the API usage.

💯 Complete Support of Domain Names

  • 😌 You can simply list domains (e.g., www.a.org, hello.io) without knowing their DNS zones.
  • 🌍 Internationalized domain names (e.g., 🐱.example.org and 日本。co。jp) are fully supported.
  • 🃏 Wildcard domains (e.g., *.example.org) are also supported.
  • 🕹️ You can toggle IPv4 (A records) and IPv6 (AAAA records) for each domain.

🌥️ Enjoy Cloudflare-specific Features

🕵️ Privacy

By default, public IP addresses are obtained via Cloudflare debugging page. This minimizes the impact on privacy because we are already using the Cloudflare API to update DNS records. Moreover, if Cloudflare servers are not reachable, chances are you cannot update DNS records anyways.

👁️ Notification

  • 🩺 The updater can work with Healthchecks or Uptime Kuma so that you receive notifications when it fails to update IP addresses.
  • 📣 The updater can also actively send you notifications via any service supported by the shoutrrr library, including emails, major notification services, major messaging platforms, and generic webhooks.

🛡️ Security

  • 🛡️ The updater uses only HTTPS or DNS over HTTPS to detect IP addresses. This makes it harder for someone else to trick the updater into updating your DNS records with wrong IP addresses. See the Security Model for more information.

  • <details><summary>✍️ You can verify the Docker images were built from this repository using the cosign tool <em>(click to expand)</em></summary>
    cosign verify favonia/cloudflare-ddns:latest \ --certificate-identity-regexp https://github.com/favonia/cloudflare-ddns/ \ --certificate-oidc-issuer https://token.actions.githubusercontent.com

    Note: this only proves that a Docker image is from this repository. It cannot prevent malicious code if someone hacks into GitHub or this repository.

  • <details><summary>📚 The updater uses only established open-source Go libraries <em>(click to expand)</em></summary>
    • cloudflare-go:
      The official Go binding of Cloudflare API v4.
    • cron:
      Parsing of Cron expressions.
    • go-retryablehttp:
      HTTP clients with automatic retries and exponential backoff.
    • go-querystring:
      A library to construct URL query parameters.
    • shoutrrr:
      A notification library for sending general updates.
    • ttlcache:
      In-memory cache to hold Cloudflare API responses.
    • mock (for testing only):
      A comprehensive, semi-official framework for mocking.
    • testify (for testing only):
      A comprehensive tool set for testing Go programs.
    </details>

⛷️ Quick Start

(Click to expand the following items.)

<details><summary>🐋 Directly run the Docker image.</summary>
docker run \ --network host \ -e CF_API_TOKEN=YOUR-CLOUDFLARE-API-TOKEN \ -e DOMAINS=example.org,www.example.org,example.io \ -e PROXIED=true \ favonia/cloudflare-ddns:latest
</details> <details><summary>🧬 Directly run the updater from its source.</summary>

You need the Go tool to run the updater from its source.

CF_API_TOKEN=YOUR-CLOUDFLARE-API-TOKEN \ DOMAINS=example.org,www.example.org,example.io \ PROXIED=true \ go run github.com/favonia/cloudflare-ddns/cmd/ddns@latest
</details>

🐋 Deployment with Docker Compose

📦 Step 1: Updating the Compose File

Incorporate the following fragment into the compose file (typically docker-compose.yml or docker-compose.yaml). The template may look a bit scary, but only because it includes various optional flags for extra security protection.

services: cloudflare-ddns: image: favonia/cloudflare-ddns:latest # Choose the appropriate tag based on your need: # - "latest" for the latest stable version (which could become 2.x.y # in the future and break things) # - "1" for the latest stable version whose major version is 1 # - "1.x.y" to pin the specific version 1.x.y network_mode: host # This bypasses network isolation and makes IPv6 easier (optional; see below) restart: always # Restart the updater after reboot user: "1000:1000" # Run the updater with specific user and group IDs (in that order). # You can change the two numbers based on your need. read_only: true # Make the container filesystem read-only (optional but recommended) cap_drop: [all] # Drop all Linux capabilities (optional but recommended) security_opt: [no-new-privileges:true] # Another protection to restrict superuser privileges (optional but recommended) environment: - CF_API_TOKEN=YOUR-CLOUDFLARE-API-TOKEN # Your Cloudflare API token - DOMAINS=example.org,www.example.org,example.io # Your domains (separated by commas) - PROXIED=true # Tell Cloudflare to cache webpages and hide your IP (optional)

(Click to expand the following important tips.)

<details> <summary>🔑 <code>CF_API_TOKEN</code> is your Cloudflare API token</summary>

The value of CF_API_TOKEN should be an API token (not an API key), which can be obtained from the API Tokens page. (The less secure API key authentication is deliberately not supported.)

  • To update only DNS records, use the Edit zone DNS template to create a token.
  • To update only WAF lists, choose Create Custom Token and add the Accounts - Account Filter Lists - Write permission to create a token.
  • To update DNS records and WAF lists, use the Edit zone DNS template and add the Accounts - Account Filter Lists - Write permission to create a token.

You can also grant new permissions to existing tokens at any time!

</details> <details> <summary>📍 <code>DOMAINS</code> is the list of domains to update</summary>

The value of DOMAINS should be a list of fully qualified domain names (FQDNs) separated by commas. For example, DOMAINS=example.org,www.example.org,example.io instructs the updater to manage the domains example.org, www.example.org, and example.io. These domains do not have to be in the same zone---the updater will identify their zones automatically.

</details> <details> <summary>🚨 Remove <code>PROXIED=true</code> if you are <em>not</em> running a web server</summary>

The setting PROXIED=true instructs Cloudflare to cache webpages and hide your IP addresses. If you wish to bypass that and expose your actual IP addresses, remove PROXIED=true. If your traffic is not HTTP(S), then Cloudflare cannot proxy it and you should probably turn off the proxying by removing PROXIED=true. The default value of PROXIED is false.

</details> <details> <summary>📴 Add <code>IP6_PROVIDER=none</code> if you want to disable IPv6 completely</summary>

The updater, by default, will attempt to update DNS records for both IPv4 and IPv6, and there is no harm in leaving the automatic detection on even if your network does not work for one of them. However, if you want to disable IPv6 entirely (perhaps to avoid all the detection errors), add the setting IP6_PROVIDER=none.

</details> <details> <summary>📡 Expand this if you want IPv6 without bypassing network isolation (without <code>network_mode: host</code>)</summary>

The easiest way to enable IPv6 is to use network_mode: host so that the updater can access the host IPv6 network directly. This has the downside of bypassing the network isolation. If you wish to keep the updater isolated from the host network, remove network_mode: host and follow the steps in the official Docker documentation to enable IPv6. Use newer versions of Docker that come with (much) better IPv6 support.

</details> <details> <summary>🛡️ Change <code>user: "1000:1000"</code> to the user and group IDs you want to use</summary>

Change 1000:1000 to USER:GROUP for the USER and GROUP IDs you wish to use to run the updater. The settings cap_drop, read_only, and no-new-privileges in the template provide additional protection, especially when you run the container as a non-superuser.

</details>

🚀 Step 2: Building the Container

docker-compose pull cloudflare-ddns docker-compose up --detach --build cloudflare-ddns

❓ Frequently Asked Questions

(Click to expand the following items.)

<details> <summary>😠 I simulated an IP address change by editing the DNS records, but the updater never picked it up!</summary>

Please rest assured that the updater is working as expected. It will update the DNS records immediately for a real IP change. Here is a detailed explanation. There are two causes of an IP mismatch:

  1. A change of your actual IP address (a real change), or
  2. A change of the IP address in the DNS records (a simulated change).

The updater assumes no one will actively change the DNS records. In other words, it assumes simulated changes will not happen. It thus caches the DNS records and cannot detect your simulated changes. However, when your actual IP address changes, the updater will immediately update the DNS records. Also, the updater will eventually check the DNS records and detect simulated changes after CACHE_EXPIRATION (six hours by default) has passed.

If you really wish to test the updater with simulated IP changes in the DNS records, you can set CACHE_EXPIRATION=1ns (all cache expiring in one nanosecond), effectively disabling the caching. However, it is recommended to keep the default value (six hours) to reduce your network traffic.

</details> <details> <summary>😠 Why did the updater detect a public IP address different from the WAN IP address on my router?</summary>

Is your “public” IP address on your router between 100.64.0.0 and 100.127.255.255? If so, you are within your ISP’s CGNAT (Carrier-grade NAT). In practice, there is no way for DDNS to work with CGNAT, because your ISP does not give you a real public IP address, nor does it allow you to forward IP packages to your router using cool protocols such as Port Control Protocol. You have to give up DDNS or switch to another ISP. You may consider other services such as Cloudflare Tunnel that can work around CGNAT.

</details>

🎛️ Further Customization

⚙️ All Settings

(Click to expand the following items.)

<details> <summary>🔑 The Cloudflare API token</summary>
NameValid ValuesMeaningRequired?Default Value
CF_API_TOKENCloudflare API tokensThe token to access the Cloudflare APIExactly one of CF_API_TOKEN and CF_API_TOKEN_FILE should be setN/A
CF_API_TOKEN_FILEPaths to files containing Cloudflare API tokensA file that contains the token to access the Cloudflare APIExactly one of CF_API_TOKEN and CF_API_TOKEN_FILE should be setN/A
</details> <details> <summary>📍 DNS domains to update</summary>
NameValid ValuesMeaningRequired?Default Value
DOMAINSComma-separated fully qualified domain names or wildcard domain namesThe domains the updater should manage for both A and AAAA records(See below)(empty list)
IP4_DOMAINSComma-separated fully qualified domain names or wildcard domain namesThe domains the updater should manage for A records(See below)(empty list)
IP6_DOMAINSComma-separated fully qualified domain names or wildcard domain namesThe domains the updater should manage for AAAA records(See below)(empty list)
<details> <summary>📍 At least one of <code>DOMAINS</code>, <code>IP4/6_DOMAINS</code>, and <code>WAF_LISTS</code> must be non-empty.</summary>

At least something should be listed in DOMAINS, IP4_DOMAINS, IP6_DOMAINS, or WAF_LISTS (for WAF lists, see below). Otherwise, if all of them are empty, then the updater has nothing to do. It is fine to list the same domain in both IP4_DOMAINS and IP6_DOMAINS, which is equivalent to listing it in DOMAINS. Internationalized domain names are supported using the non-transitional processing fully compatible with IDNA2008. See this useful FAQ on internationalized domain names.

</details>
<details> <summary>🃏 What are wildcard domains?</summary>

Wildcard domains (*.example.org) represent all subdomains that would not exist otherwise. Therefore, if you have another subdomain entry sub.example.org, the wildcard domain is independent of it, because it only represents the other subdomains which do not have their own entries. Also, you can only have one layer of *---*.*.example.org would not work.

</details>
</details> <details> <summary>🔍 IP address providers</summary>
NameValid ValuesMeaningRequired?Default Value
IP4_PROVIDERcloudflare.doh, cloudflare.trace, local, url:URL, or noneHow to detect IPv4 addresses, or none to disable IPv4 (see below)Nocloudflare.trace
IP6_PROVIDERcloudflare.doh, cloudflare.trace, local, url:URL, or noneHow

编辑推荐精选

蛙蛙写作

蛙蛙写作

AI小说写作助手,一站式润色、改写、扩写

蛙蛙写作—国内先进的AI写作平台,涵盖小说、学术、社交媒体等多场景。提供续写、改写、润色等功能,助力创作者高效优化写作流程。界面简洁,功能全面,适合各类写作者提升内容品质和工作效率。

AI辅助写作AI工具蛙蛙写作AI写作工具学术助手办公助手营销助手AI助手
Trae

Trae

字节跳动发布的AI编程神器IDE

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
问小白

问小白

全能AI智能助手,随时解答生活与工作的多样问题

问小白,由元石科技研发的AI智能助手,快速准确地解答各种生活和工作问题,包括但不限于搜索、规划和社交互动,帮助用户在日常生活中提高效率,轻松管理个人事务。

热门AI助手AI对话AI工具聊天机器人
Transly

Transly

实时语音翻译/同声传译工具

Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。

讯飞智文

讯飞智文

一键生成PPT和Word,让学习生活更轻松

讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。

AI办公办公工具AI工具讯飞智文AI在线生成PPTAI撰写助手多语种文档生成AI自动配图热门
讯飞星火

讯飞星火

深度推理能力全新升级,全面对标OpenAI o1

科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。

热门AI开发模型训练AI工具讯飞星火大模型智能问答内容创作多语种支持智慧生活
Spark-TTS

Spark-TTS

一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型

Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。

咔片PPT

咔片PPT

AI助力,做PPT更简单!

咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需求。

讯飞绘文

讯飞绘文

选题、配图、成文,一站式创作,让内容运营更高效

讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。

热门AI辅助写作AI工具讯飞绘文内容运营AI创作个性化文章多平台分发AI助手
材料星

材料星

专业的AI公文写作平台,公文写作神器

AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。

下拉加载更多