{"id":19303319,"url":"https://github.com/pboymt/ddns-at-home","last_synced_at":"2025-04-22T11:32:03.168Z","repository":{"id":40243456,"uuid":"189009556","full_name":"pboymt/ddns-at-home","owner":"pboymt","description":"同时支持IPv4与IPv6！利用各DNS提供商的API（现已支持阿里云的OpenAPI），在具有公网IP的前提下，实现动态修改域名解析的功能，脱离花生壳的昂贵服务，将自己的域名解析为自家的IP地址。","archived":false,"fork":false,"pushed_at":"2023-07-19T05:35:27.000Z","size":273,"stargazers_count":49,"open_issues_count":3,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-01T22:47:00.587Z","etag":null,"topics":["aliyun","aliyun-ddns","ddns","ddns-updater","dns","ipv4-ipv6","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pboymt.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["pboymt"],"patreon":"pboymt"}},"created_at":"2019-05-28T10:48:30.000Z","updated_at":"2024-12-07T03:25:22.000Z","dependencies_parsed_at":"2022-07-25T18:47:37.335Z","dependency_job_id":null,"html_url":"https://github.com/pboymt/ddns-at-home","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pboymt%2Fddns-at-home","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pboymt%2Fddns-at-home/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pboymt%2Fddns-at-home/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pboymt%2Fddns-at-home/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pboymt","download_url":"https://codeload.github.com/pboymt/ddns-at-home/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250232187,"owners_count":21396588,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aliyun","aliyun-ddns","ddns","ddns-updater","dns","ipv4-ipv6","typescript"],"created_at":"2024-11-09T23:26:00.850Z","updated_at":"2025-04-22T11:32:02.858Z","avatar_url":"https://github.com/pboymt.png","language":"TypeScript","funding_links":["https://github.com/sponsors/pboymt","https://patreon.com/pboymt"],"categories":[],"sub_categories":[],"readme":"# DDNS@Home 动态更改DNS解析记录（原aliyun-ddns）\n\n![GitHub](https://img.shields.io/github/license/pboymt/aliyun-ddns.svg?style=flat-square)\n![](https://img.shields.io/badge/Language-TypeScript-blue?style=flat-square)\n\n## 新版本亮点\n\n### 1.2.0\n\n- 优化代码\n- 接入 Cloudflare 服务，但不支持直接添加 Zone\n\n### 1.1.0\n\n- 代码重构，更易阅读\n- 将阿里云服务从单页代码中独立，方便 **接入其他服务**\n- 配置文件规则优化（版本为2），可以配置 **多服务、多域名、多记录**\n- 不再提供 crontab 配置，请使用 PM2 守护进程配置或自行配置 systemd 等系统工具。\n\n\u003e **已移除V1版本支持**\n\n本项目利用各大 DNS 服务提供商（例如：阿里云云解析 DNS）的 API，在具有公网 IP 的前提下，实现动态修改域名解析的功能，脱离花生壳的昂贵服务，将自己的域名解析为自家的 IP 地址。\n\n\u003e **代码请求**\n\u003e \n\u003e 由于作者还未使用过其他提供商的 DNS，所以本项目暂时仅支持阿里云的 DNS 服务。欢迎提供其他提供商的兼容代码。\n\n**本项目同时支持IPv4与IPv6。**\n\n\u003e **服务征集**\n\u003e \n\u003e 由于 test-ipv6.com 等服务的 IP 探测服务存在一定的不稳定性，欢迎大家提供同时包含IPv4和IPv6的免费探测服务。未来将会增加配置 IP 探测链接。\n\n本项目使用 TypeScript 编写，确保稳定运行。\n\n本工具可以使用三种模式部署：\n\n- PM2：推荐，适用于非 Windows 系统，配置简洁\n- ~~Crontab~~：不再支持\n- Systemd：适用于 Linux 大部分发行版，*项目内未实现相关配置，欢迎贡献代码*。\n- Service：适用于 Windows 系统，使用 `node-windows` 模块设置相关服务，*项目内未实现相关配置，欢迎贡献代码*。\n- Docker：适用于所有能够运行 Docker 的操作系统，*项目内未实现相关配置，欢迎贡献代码*。\n\n## 注意事项\n\n- 本服务需要域名已设置好需要使用的服务商托管，并且准备好使用账号的 API Key 与 API Secret / API Token 等相关内容。\n- 如果 DNS 列表不存在配置中的域名，工具可能将会使用 API 进行添加，具体行为视服务有所区别：\n  - 在阿里云服务下，请确保域名属于对应账号所有。\n  - 在 Cloudflare 服务下，将不会自动添加域名，请自行对 Zone 进行添加。\n- IPv4网络下，如果您家中有路由器，请将您的路由器设置 `DMZ主机` 到使用本工具的设备（比如路由器 IP 为 `192.168.31.1`，设备 IP 为 `192.168.31.10`，那就把路由器中的 `DMZ主机` 设置为 `192.168.31.10`），以确保设置DNS后能够正常使用公网 IPv4 访问该设备。\n- 如果要将 IP 地址设置为客户端所在的公网 IP 地址, 要确保客户端被当地运营商分配的不是**内网 IP**（即使用万网查询 IP 地址时会出现两个 IP 地址，其中一个是 NAT 的 IP 地址，此时您自身的 IP 不是公网 IP）。如果是内网的 IPv4 地址, 可以给客服打电话要求更换为公网 IPv4 地址（长城宽带等二次转售宽带就别想了）。\n- 大多数设备在国内环境都是可以获取公网 IPv6 地址的。如果您家中网络结构是“光猫（路由模式，大多数运营商默认）-路由器-设备”，请将路由器（以小米路由器为例）设置为有线中继模式，由路由模式的光猫进行 DHCPv6 分配；或者联系运营商服务支持，将光猫由路由模式改为桥接模式，使用路由器进行拨号及 DHCPv6 分配，此方法已经在北京联通、北京电信成功验证。\n\n\u003e 如果获取不到公网 IPv4 地址，禁用 IPv4 配置只使用 IPv6 同样可行。\n\n## 使用方法\n\n\u003e 不再支持V1配置\n\n\u003e 使用前请务必阅读[注意事项](#注意事项)\n\n请确保您已经安装了 Node.js 16.x（较早版本并未测试不过理论上 Node.js 8.x 及以上版本均支持）并且能够运行 npm。您可以通过以下代码在命令行测试：\n\n```bash\n$ node -v # v16.13.0\n$ npm -v # 8.1.3\n```\n\n（建议）全局安装 TypeScript：\n\n```bash\n# 推荐\n$ yarn global add typescript\n# 或\n$ npm install -g typescript\n```\n\n将项目 `git clone` 到目录：\n\n```bash\n$ git clone https://github.com/pboymt/ddns-at-home.git\n# 国内用户请配置好代理/Hosts/可靠性高的DNS服务，或者直接使用码云Gitee的镜像\n$ git clone https://gitee.com/pboymt/ddns-at-home.git\n```\n\n切换到目录：\n\n```bash\n$ cd ddns-at-home\n```\n\n安装依赖：\n\n```bash\n# 本项目不再推荐使用yarn，因为没测试过\n$ npm install\n```\n\n编译代码：\n\n```bash\n$ npx tsc # 如果没有报错就是编译成功\n```\n\n复制配置样板，修改设置，配置模式文件请查看 [settings.schema.json](./settings.schema.json) ：\n\n\u003e 强烈使用 VSCode 等编辑器支持 JSON Schema 验证的编辑器编辑配置文件。\n\n```bash\n$ cp settings.sample.json settings.json\n$ nano settings.json # 请完全遵照schema设定的规则进行配置\n```\n\n如果配置无效会在运行的第一时间抛出错误。\n\n安装完毕后可以运行一次进行测试：\n\n```bash\n$ npm start\n```\n\n\u003e 如果您使用了计划任务，建议等待第一次计划任务执行成功后结束测试。\n\n## 版本更新\n\n您只需要重新拉取后再次执行安装依赖和编译代码流程即可，如果您配置了守护进程，请重启它们（PM2会默认监控编译生成的lib目录变化自动重启）。\n\n## 守护进程配置\n\n版本 `1.1.0` 后，由于内置定时执行 DDNS 功能，Crontab 配置暂被删去，您可以自行配置，**但请务必注意配置文件需要移除 `schedule` 字段以禁用定时执行功能！**\n\n如果您在 V2 配置文件中配置了计划任务，那么可以使用提供的 PM2 配置文件，甚至自行设置 Systemd 将本工具设置为服务或者。\n\n### PM2\n\n\u003e PM2 对 Windows 的支持存在一些问题，具体请参考，建议在非 Windows 系统上使用。\n\n本工具提供了 [ecosystem.config.js](./ecosystem.config.js) 作为PM2的环境配置。\n\n您可以全局安装pm2：\n\n```bash\n$ npm install -g pm2\n```\n\n配置文件需要配置 `schedule` 字段：\n\n\u003e 由于诸多服务的 API 存在防滥用机制，因此本工具的计划任务只支持到分钟级，如果您愿意作死可以直接修改源代码添加秒级甚至微秒级计划任务。\n\n```json\n{\n    ...\n    \"schedule\": {\n        \"immediate\": true, // 是否立即执行一次任务\n        \"hour\": \"*\", // 每小时均可执行\n        \"minute\": \"/5\" // 每封五的背书分钟执行一次任务（默认配置）\n    }\n}\n```\n\n\u003e `hour` 和 `minute` 字段语法规则类似于 Cron，详细语法可在 [Timexe 文档](https://github.com/paragi/timexe#examples-og-timer-expressions)查看：\n\u003e - 当为 `*` 时，每小**小时/分钟**执行一次\n\u003e - 当为 `n` 时，每逢 n **时/分**时可执行，最终决定权在 `minute` 字段\n\u003e - 当为 `/n` 时，每逢 n 的倍数**时/分**执行一次\n\n\n然后使用 pm2 运行本工具：\n\n```bash\n# 输出更多日志\n$ pm2 start ecosystem.config.js # 可不写 ecosystem.config.js，pm2 会默认搜寻目录中的配置。\n# 或（输出更少日志）\n$ pm2 start ecosystem.config.js --env production\n```\n\n可使用命令查看监控：\n\n```bash\n$ pm2 monit\n```\n\n停止守护进程：\n\n```bash\n$ pm2 stop\n```\n\n保存守护进程（防止 pm2 重启丢失配置）：\n\n```bash\n$ pm2 save\n```\n\n配置 PM2 自启动：\n\n\u003e **注意：** 可能需要管理员权限或root权限，在Linux下，root权限执行的pm2和普通用户权限执行的pm2配置不在同一目录，如果您使用的是 `sudo pm2 startup` ，那么请使用 `sudo pm2 start` 运行守护进程，并且把普通权限运行的守护进程删除，防止重复多次运行。\n\n```bash\n$ pm2 startup\n```\n\n### Systemd\n\n*探寻中 WIP*\n\n### Docker\n\n*探寻中 WIP*\n\n\n## 本项目使用的模块\n\n### 依赖\n\n| 包名 | 用途 | 使用版本 |\n| :- | :- | :- |\n| @alicloud/pop-core | 用于请求阿里云OpenAPI | ![@alicloud/pop-core](https://img.shields.io/static/v1?label=@alicloud/pop-core\u0026message=^1.7.10\u0026color=important\u0026style=flat-square) |\n| cloudflare | 用于请求Cloudflare API | ![cloudflare](https://img.shields.io/static/v1?label=cloudflare\u0026message=^2.9.1\u0026color=important\u0026style=flat-square) |\n| @kocal/logger | 格式化日志输出 | ![@kocal/logger](https://img.shields.io/static/v1?label=@kocal/logger\u0026message=^2.0.12\u0026color=important\u0026style=flat-square) |\n| ajv | 用于验证JSON Schema | ![ajv](https://img.shields.io/static/v1?label=ajv\u0026message=^8.11.0\u0026color=important\u0026style=flat-square) |\n| axios | 探测IP地址 | ![axios](https://img.shields.io/static/v1?label=axios\u0026message=^0.27.2\u0026color=important\u0026style=flat-square) |\n| date-fns | 格式化日志时间 | ![date-fns](https://img.shields.io/static/v1?label=date-fns\u0026message=^2.28.0\u0026color=important\u0026style=flat-square) |\n| timexe | 执行定时任务 | ![timexe](https://img.shields.io/static/v1?label=timexe\u0026message=^1.0.5\u0026color=important\u0026style=flat-square) |\n\n### 开发依赖\n\n| 包名 | 使用版本 |\n| :- | :- |\n| @types/node | ![@types/node](https://img.shields.io/static/v1?label=@types/node\u0026message=16.11.36\u0026color=important\u0026style=flat-square) |\n| @types/cloudflare | ![@types/cloudflare](https://img.shields.io/static/v1?label=@types/cloudflare\u0026message=2.7.8\u0026color=important\u0026style=flat-square) |\n| @typescript-eslint/eslint-plugin | ![@typescript-eslint/eslint-plugin](https://img.shields.io/static/v1?label=@typescript-eslint/eslint-plugin\u0026message=5.25.0\u0026color=important\u0026style=flat-square) |\n| @typescript-eslint/parser | ![@typescript-eslint/parser](https://img.shields.io/static/v1?label=@typescript-eslint/parser\u0026message=5.25.0\u0026color=important\u0026style=flat-square) |\n| cross-env | ![cross-env](https://img.shields.io/static/v1?label=cross-env\u0026message=7.0.3\u0026color=important\u0026style=flat-square) |\n| eslint | ![eslint](https://img.shields.io/static/v1?label=eslint\u0026message=8.15.0\u0026color=important\u0026style=flat-square) |\n| markdown-table | ![markdown-table](https://img.shields.io/static/v1?label=markdown-table\u0026message=3.0.2\u0026color=important\u0026style=flat-square) |\n| typescript | ![typescript](https://img.shields.io/static/v1?label=typescript\u0026message=4.6.4\u0026color=important\u0026style=flat-square) |\n\n## 开源协议\n\n本项目随便就用了 LGPLv3 协议。","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpboymt%2Fddns-at-home","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpboymt%2Fddns-at-home","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpboymt%2Fddns-at-home/lists"}