<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/ DTD/wml_1.1.xml">

<wml>
<head>
<meta http-equiv="cache-control" content="max-age=180,private" />
</head>
<card title="新建ROS的ALIDDNS脚本更新项目">
<p>
作者:<a href="index.php?action=showuser&amp;userid=1&amp;hash=">熊茂祥</a><br />时间:2025-06-25 17:40<br />分类:<a href="index.php?action=list&amp;cid=3&amp;hash=">ROS</a><br />标签:<a href="index.php?action=tags&amp;item=ali&amp;hash=">ali</a>, <a href="index.php?action=tags&amp;item=%E8%A7%A3%E6%9E%90&amp;hash=">解析</a>, <a href="index.php?action=tags&amp;item=ddns&amp;hash=">ddns</a>, <a href="index.php?action=tags&amp;item=ipv6&amp;hash=">ipv6</a>, <a href="index.php?action=tags&amp;item=%E5%8A%A8%E6%80%81&amp;hash=">动态</a><br />内容:








本项目完全免费公开脚本源码。




服务语言环境：golang


 


ROS的ALIDDNS脚本更新：

1.可对接阿里云的DDNS进行更新。

2.一个脚本可以支持IPV4和IPV6的DDNS更新。

3.检测子域名不存在时自动创建。

4.支持域名使用V4+V6双栈，2个IP共用一个域名。

5.支持更新不同线路的记录值。

6.支持自定义TTL记录值。 

7.支持接口状态回显，方便调试错误。

8.支持对单域名解析多IP的DDNS更新，实现域名形式的负载平衡，并且支持按不同运营商分配负载平衡。(仅限IPV4，本站接口不限制负载均衡的IP个数，但是可能会受到上级接口的规则限制。) 


 


使用条件：

1.必须在阿里云开通AccessKey功能，获取AccessKey ID和密匙。

2.必须将域名托管到阿里云DNS。

3.也兼容其他系统使用get提交。(id必填，secret必填，domain必填，IP选填，line选填，renew选填)

4.仅支持123.ros6.com这样的2级域名，不支持123.456.ros6.com这样的更多级域名，也不支持更新ros6.com这样的顶级域名。


 




ROS脚本(精简版)


    #更新ALIDDNS脚本精简版#    

    #定义更新的域名#    

    :global ddns1 &quot;www.ros6.com&quot;    

    #定义阿里云ID#    

    :global id1 &quot;16或24字节长度AccessKey ID&quot;    

    #定义阿里云Secret#    

    :global secret1 &quot;30字节长度的密匙&quot;    

    #下面内容请勿修改#    

    #更新IPV4#    

    :local results [/tool fetch url=(&quot;https://cmp.ros6.com/aliddns?id=$id1&amp;secret=$secret1&amp;domain=$ddns1&quot;) check-certificate=no as-value output=user]  

    :if ($results-&gt;&quot;status&quot; = &quot;finished&quot;) do={  

    :local result ($results-&gt;&quot;data&quot;)  

    :log warning $result  

    }  

    







 




ROS脚本(负载均衡版)


    #更新ALIDDNS负载均衡#  

    #定义更新的接口名#  

    :local ddnsint1 pppoe-out1,pppoe-out2  

    #定义更新的域名#  

    :local ddns1 &quot;ddns.ros6.com&quot;  

    #定义更新的线路类型(default,unicom,telecom,mobile)#  

    :local ddnsline1 default,default  

    #定义TTL参数#  

    :local ttl1 600  

    #定义阿里云ID#  

    :local id1 &quot;16字节或24字节长度AccessKey ID&quot;  

    #定义阿里云Secret#  

    :local secret1 &quot;30字节长度的密匙&quot;  

    #下面内容请勿修改#  

    :global oldddnsip1  

    #更新IPV4#  

    :local ddnsips1 &quot;&quot;  

    :local ddnsip1 &quot;&quot;  

    :local ddnslines1 &quot;&quot;  

    :local ddnscount 0  

    :foreach ddnsints1 in=$ddnsint1 do={  

    :if ([/ip address find interface=$ddnsints1] != &quot;&quot;) do={  

    :set ddnsip1 [/ip address get [find interface=$ddnsints1] address]  

    :set ddnsip1 [:pick $ddnsip1 0 [:find $ddnsip1 &quot;/&quot;]]  

    :set ddnsips1 ($ddnsips1.&quot;,&quot;.$ddnsip1)  

    :set ddnslines1 ($ddnslines1.&quot;,&quot;.[:pick $ddnsline1 $ddnscount])  

    :set ddnscount ($ddnscount +1)  

    }}  

    :set ddnsips1 [:pick $ddnsips1 1 [:len $ddnsips1]]  

    :set ddnslines1 [:pick $ddnslines1 1 [:len $ddnslines1]]  

    :if ($oldddnsip1 != $ddnsips1) do={  

    :local results [/tool fetch url=(&quot;https://cmp.ros6.com/aliddns?id=$id1&amp;secret=$secret1&amp;domain=$ddns1&amp;ip=$ddnsips1&amp;line=$ddnslines1&amp;ttl=$ttl1&amp;renew=1&quot;) check-certificate=no as-value output=user]  

    :if ($results-&gt;&quot;status&quot; = &quot;finished&quot;) do={  

    :local result ($results-&gt;&quot;data&quot;)  

    :set oldddnsip1 $ddnsips1  

    :log warning (&quot;ALIDDNS:IPV4 &quot;.$result)  

    }  

    }  







ROS脚本(完整版)


    #更新ALIDDNS脚本完整版#  

    #定义更新的接口名#  

    :global ddnsint1 &quot;pppoe-out1&quot;  

    #定义更新的域名#  

    :global ddns1 &quot;www.ros6.com&quot;  

    #定义更新的线路类型(default,unicom,telecom,mobile)#  

    :global ddnsline1 &quot;default&quot;  

    #定义TTL参数#  

    :global ttl1 600  

    #定义更新接口对应的DNS#  

    :global ddnsd1 114.114.114.114  

    #获取更新域名对应的IP#  

    :global ddnsres1  

    :do {:set ddnsres1 [resolve $ddns1 server=$ddnsd1]} on-error={:set ddnsres1 &quot;&quot;}  

    #定义阿里云ID#  

    :global id1 &quot;16字节或24字节长度AccessKey ID&quot;  

    #定义阿里云Secret#  

    :global secret1 &quot;30字节长度的密匙&quot;  

    #下面内容请勿修改#  

    #更新IPV4#  

    :global ddnsip1 [/ip address get [find interface=$ddnsint1] address]  

    :set ddnsip1 [:pick $ddnsip1 0 [:find $ddnsip1 &quot;/&quot;]]  

    :if ($ddnsres1 != $ddnsip1) do={  

    :local results [/tool fetch url=(&quot;https://cmp.ros6.com/aliddns?id=$id1&amp;secret=$secret1&amp;domain=$ddns1&amp;ip=$ddnsip1&amp;line=$ddnsline1&amp;ttl=$ttl1&quot;) check-certificate=no as-value output=user]  

    :if ($results-&gt;&quot;status&quot; = &quot;finished&quot;) do={  

    :local result ($results-&gt;&quot;data&quot;)  

    :log warning (&quot;ALIDDNS:IPV4 &quot;.$result)  

    }  

    #更新IPV6#  

    :if ([/system package find name=&quot;ipv6&quot; disabled=no] !=&quot;&quot;) do={  

    :if ([/ipv6 dhcp-client find interface=$ddnsint1] !=&quot;&quot;) do={  

    :global ddnsipv61 [/ipv6 dhcp-client get [/ipv6 dhcp-client find interface=$ddnsint1] prefix]  

    :set ddnsipv61 [:pick $ddnsipv61 0 [:find $ddnsipv61 &quot;/&quot;]]  

    :if ($ddnsipv61 !=&quot;&quot;) do={  

    :local results [/tool fetch url=(&quot;https://cmp.ros6.com/aliddns?id=$id1&amp;secret=$secret1&amp;domain=$ddns1&amp;ip=$ddnsipv61&amp;line=$ddnsline1&amp;ttl=$ttl1&quot;) check-certificate=no as-value output=user]  

    :if ($results-&gt;&quot;status&quot; = &quot;finished&quot;) do={  

    :local result ($results-&gt;&quot;data&quot;)  

    :log warning (&quot;ALIDDNS:IPV6 &quot;.$result)  

    }  

    }}}  

    }  







更新时间：2025/06/25

更新内容：修正了新注册的AccessKey ID长度为24位时报错的BUG。


更新时间：2025/02/26

更新内容：该项目成立于2021/04/25，已经为大家免费服务了接近4年。由于云管理平台已经整合DDNS和更高级的CDDNS功能，推荐大家迁移到云管理平台使用。本项目依然保留，但是脚本提交地址有所变化，具体参考文章中的脚本示例。（旧服务器2026年11月6日到期，建议在到期前完成接口迁移工作。）
</p><p>
<a href="index.php?action=comments&amp;articleid=247&amp;hash=">查看评论</a><br />
<a href="index.php?action=login&amp;hash=">立即登陆发表评论</a><br />
</p>
<p><a href="index.php?action=list&amp;hash=">返回日志列表</a><br /><a href="index.php?action=index&amp;hash=">返回主页</a></p>
</card>
</wml>
