RouterOS 動態更新IP到 ChangeIP.com

MikroTikRouterOS RB450G
回覆文章
yehlu
Site Admin
文章: 3244
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

RouterOS 動態更新IP到 ChangeIP.com

文章 yehlu »

http://www.minitw.com/archives/180

RouterOS裡有一個內建的工具dns-update

是用來把IP更新到DDNS上去的

首先先到ChangeIP.com申請一個帳號,並建立一個免費的Domain

網路上所找到的Script在RouterOS 3.7版上使用會有問題

所以我做了一些修改,使Script可以在RouterOS 3.7版上面使用

先到RouterOS裡新增一個Script,System->Script。



內容如下。記得把Script的名字改為ddnsUpdate

代碼: 選擇全部

#以下程式碼於RouterOS 3.7下測試通過
 
:log info "DDNS: Begin"
:local ddnsuser "你的帳號"
:local ddnspass "你的密碼"
:local ddnshost "名稱(如為test.changeip.net的話,請填test)"
:local ddnszone "網域(如為test.changeip.net的話,請填changeip.net)"
:local ddnsinterface "你要更新上去IP所使用的介面名稱(pppoe-out)"
#一定要先宣告,不然後面程式無法使用
:global ddnslastip
:global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface] address ]
#舊的IP有存在就用舊的,不存在就建0.0.0.0/0
:if ([:typeof [:global ddnslastip]] = nil ) do={ :global ddnslastip 0.0.0.0/0 } else={ :set ddnslastip $ddnslastip }
:if ([:typeof [:global ddnsip]] = nil ) do={
:log info ("DDNS: No ip address present on " . $ddnsinterface . ", please check.")
} else={
    :if ($ddnsip != $ddnslastip) do={
        :log info "DDNS: 開始更新DDNS!"
        :log info ([/tool dns-update key-name=$ddnsuser key=$ddnspass name=$ddnshost address=[:pick $ddnsip 0 [:find $ddnsip "/"] ] zone=$ddnszone] . "更新IP:" . $ddnsip)
 
        :global ddnslastip $ddnsip
} else={
        :log info "DDNS: IP無變動"
}
}
:log info "DDNS: End"
然後再到Scheduler,System->Scheduler。新增1個排程



內容如下。更新時間可以依你的喜好來設定,我是設定3分鍾更新一次

?
1
/system script run ddnsUpdate
回覆文章

回到「RouterOS」