标签归档:CCR1016

RouterOS检查远程服务器域名更新IP脚本

ROS的服务器地址不支持域名,当我们填写服务器域名点OK后,域名会被直接转换成IP,当服务器地址是动态IP的时候,服务器IP更换后,连接将失效。以下脚本将以PPTP为例,定时检查域名IP,当检查到域名解析结果与当前IP不同时,自动更新。
脚本如下,通常3-10秒检查一次即可:

:local ddnsym "域名"
:local ips [:resolve $ddnsym]
/interface pptp-client
:local ddnsip [get [find name="pptp-out1"] connect-to ]
:if ($ddnsip!=$ips) do={
/interface pptp-client set [find name="pptp-out1"] connect-to=$ips
}

*pptp-ou1为接口名,依你的实际情况更改。
*脚本依赖DNS解析,使用前检查ip-DNS设置。

DDNS动态域名脚本-ROS RouterOS 中设置 3322 公云

3322域名申请:http://www.pubyun.com/
#将以下脚本加计划每3分钟执行一次即可:

:local ednsuser "登陆用户名"
:local ednspass "登陆密码"
:local ednshost "申请到的域名"
:local ednsinterface "接口名,例:pppoe-out2"
:local members "http://members.3322.org/dyndns/update?system=dyndns"
#:local members "http://members.dyndns.org/nic/update?"
:local status
:local status [/interface get [/interface find name=$ednsinterface] running]
:if ($status!=false) do={
:local ednslastip [:resolve $ednshost]
:if ([ :typeof $ednslastip ] = nil ) do={ :local ednslastip "0" }
:local ednsiph [ /ip address get [/ip address find interface=$ednsinterface ] address ]
:local ednsip [:pick $ednsiph 0 [:find $ednsiph "/"]]
:local ednsstr "&hostname=$ednshost&myip=$ednsip"
:if ($ednslastip != $ednsip) do={/tool fetch url=($members . $ednsstr) mode=http user=$ednsuser password=$ednspass dst-path=$ednshost
:delay 2
:local result [/file get $ednshost contents]
:log info ($ednshost . " " .$result)
/file remove $ednshost ;
}
}

如果无法解析,请核对DNS相关设置:
3322-2


支持版本:ROS3.x,4.x,5.x