RouterOS 動態更新IP到 Namecheap

之前用的好好的DDNS動態更新ChangeIP與No-IP,為什麼要換到Namecheap呢?

轉換DNS代管的過程大約半天內可以搞定,這又是另一個故事了,之後有時間再寫。

先把要換的重點列出來。

  • GoDaddy DNS域名續約很貴
  • ChangeIP與No-IP免費版的,都有數量上的限制,年費也不便宜
  • Namecheap提供無限數量的DDNS,而且也可以綁定自己的域名

換到Namecheap當然RouterOS的script也要調整,以下程式供需要的人參考

2021/11/19 更新script,把原本http的方式改成https。不知道是不是namecheap把http拿掉了,一直403

#Script在#Script在RouterOS 6.42.1中測試通過
#Date:2018/05/07
#Script Name:namecheap DDNS Update

:local ddnsserver "dynamicdns.park-your-domain.com"
:local ddnspass "你的密碼"
:local ddnshostname "於Namecheap中的ddnshostname。例:test"
:local ddnsdomain "於Namecheap中的ddnsdomin。例:ddns.yourdomain.com"
:local ddnscomment "要更新的PPPoE撥接實體註解說明內容。例:Router_ADSL-1_RouterOS"
#一定要先宣告,不然後面程式無法使用
:global ddnslastipADSL1
:global ddnsipADSL1 [ /ip address get [/ip address find interface=[/interface get [/interface find comment=$ddnscomment] name]] address ]
#舊的IP有存在就用舊的,不存在就建0.0.0.0/0
:if ([:typeof [:global ddnslastipADSL1]] = nil ) do={ :global ddnslastipADSL1 0.0.0.0/0 } else={ :set ddnslastipADSL1 $ddnslastipADSL1 }
:if ([:typeof [:global ddnsipADSL1]] = nil ) do={
  :log info ("DDNS: No ip address present on " . $ddnscomment . ", please check.")
} else={
  :if ($ddnsipADSL1 != $ddnslastipADSL1) do={
    :log info "DDNS: Update DDNS! (CHT:開始更新 $ddnscomment)"
    :local ipFormat [:pick $ddnsipADSL1 0 [:find $ddnsipADSL1 "/"]];
    :log info ([/tool fetch url="https://dynamicdns.park-your-domain.com/update\?host=$ddnshostname&domain=$ddnsdomain&password=$ddnspass&ip=$ipFormat" mode=https dst-path=("/DDNS-".$ddnshostname)] . "CHT:更新IP:" . $ddnsipADSL1)
    :log info ($ddnshostname . "." . $ddnsdomain "  更新回傳值-->" . [/file get "DDNS-$ddnshostname" contents])
    :global ddnslastipADSL1 $ddnsipADSL1
  } else={

  }
}

參考資料:Dynamic DNS Update Script for Namecheap

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *