Skip to content

Jackarain/ddns

Repository files navigation

DDNS 工具

actions workflow
中文 | English

一个用于动态更新 IP 到域名配置的工具,支持 dnspodf3322oraygodaddynamesilohe.netalidnscloudflare 平台.

环境准备

在开始编译前,需要安装 golang/git 环境,并使用 git 命令将项目克隆到本地

git clone https://github.com/Jackarain/ddns.git

编译方法

在项目目录下执行以下命令

go build

编译完成后,会生成名为 ddns 的可执行程序。

使用方法

通常可以将 ddns 程序放在 crontab 中定时执行,也可以使用 systemd 定时执行,以下是 crontab 的使用示例

# 每 5 分钟执行一次
*/5 * * * * /path/to/ddns --dnspod --domain example.com --subdomain test --dnstype AAAA --token "1111111:123123123"

以下是 systemd 的使用示例

# 编辑 /etc/systemd/system/ddns.service
[Unit]
Description=DDNS Service
After=network.target

[Service]
WorkingDirectory=/tmp/
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=no
ExecStart=/path/to/ddns --dnspod --domain example.com --subdomain test --dnstype AAAA --token "1111111:123123123"

[Install]
WantedBy=multi-user.target
# 编辑 /etc/systemd/system/ddns.timer
[Unit]
Description=DDNS Timer

[Timer]
OnBootSec=5min
OnUnitActiveSec=5min

[Install]
WantedBy=timers.target
# 启动定时服务
systemctl start ddns.timer

# 设置开机自启
systemctl enable ddns.timer

以上示例中,ddns 程序会在开机后 5 分钟执行一次,之后每 5 分钟执行一次,如果需要修改执行时间,可以修改 ddns.timer 文件中的 OnBootSecOnUnitActiveSec 参数,具体使用方法可以参考 systemd.timer 的文档。

ddns 可以运行在路由器或 NAS 等设备上,这样就可以实现在路由器或 NAS 上实现动态更新 IP 到域名配置的功能

提示ddns 支持 --interval 参数让程序自身按指定间隔循环执行,无需依赖 crontabsystemd timer
例如 --interval 5m 表示每 5 分钟执行一次(支持 m 分钟、h 小时、d 天,纯数字表示秒)。

参数说明及使用示例

godaddy 使用示例

/path/to/ddns --godaddy --domain example.com --subdomain test --dnstype AAAA --token "1111111:123123123"

在这个示例中,token 是由 "API_KEY:API_SECRET" 组成的字符串,域名为:test.example.com

cloudflare 使用示例

/path/to/ddns --cloudflare --domain example.com --subdomain test --dnstype AAAA --token "123123123"

在这个示例中,token"api-token" 字符串, 域名为:test.example.com

dnspod 使用示例

/path/to/ddns --dnspod --domain example.com --subdomain test --dnstype AAAA --token "1111111:123123123"

namesilo 使用示例

/path/to/ddns --namesilo --domain example.com --subdomain test --dnstype AAAA --token "1111111123123123"

f3322 使用示例

/path/to/ddns --f3322 -user root -passwd xxxxxxxx --domain example.f3322.net

oray 使用示例

/path/to/ddns --oray -user root -passwd xxxxxxxx --domain example.vicp.net

he.net 使用示例

/path/to/ddns --henet --domain example.com --subdomain test --dnstype AAAA --token "A6z56I89bUghPk8h"

通过 curl 请求 ipv4.seeip.org 获取公网 ip 使用示例

/path/to/ddns --dnspod --domain example.com --subdomain test --dnstype A --token "1111111:123123123" --command "curl https://ipv4.seeip.org"

默认情况下,ddns 请求 ipify.org 以获取公网 ip

定时执行

--interval 参数可以让程序自行定时循环,无需依赖 crontabsystemd timer

# 每 5 分钟执行一次
/path/to/ddns --dnspod --domain example.com --subdomain test --dnstype AAAA --token "1111111:123123123" --interval 5m

# 每 2 小时执行一次
/path/to/ddns --godaddy --domain example.com --subdomain test --dnstype A --token "1111111:123123123" --interval 2h

# 每 300 秒执行一次(纯数字表示秒)
/path/to/ddns --namesilo --domain example.com --subdomain test --dnstype AAAA --token "1111111123123123" --interval 300

使用配置文件

通过 --config 参数可以指定配置文件,将参数统一写入文件便于管理。配置文件每行一个 key=value,参数名与命令行一致:

创建配置文件 ddns.conf

# DDNS 配置文件
dnspod = true
domain = example.com
subdomain = test
dnstype = AAAA
token = 1111111:123123123
interval = 5m

直接使用配置文件运行:

/path/to/ddns --config ddns.conf

也可以在配置文件基础上,通过命令行参数覆盖某些配置(命令行优先级更高):

/path/to/ddns --config ddns.conf --dnstype A

支持和反馈

如果您在使用过程中遇到任何问题,或有任何建议和反馈,欢迎通过本项目的 Github 页面提交 IssuePull Request

About

一个用于动态更新IP到指定域名的工具,支持 dnspod, cloudflare, godaddy, namesilo, he.net, f3322, oray, alidns 平台。

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages