返回列表 發帖

Dynamic DNS of changeip on RouterOS 6.30.1

本帖最後由 角色 於 2016-2-23 11:37 編輯

Besides the official hostname adddress you can use your own hostname, for example www.changeip.com, which provides many sub-domains you can choose.

Procedure:
1. Goto [System]->[Scripts]
2. Press <+>, it gives a dialog box
3. Put the following code to script window box
4. Name the script, e.g. changeip
5. Click <Run Script> to check whether the code works as expected
  1. #------------------------------------------
  2. # EDIT YOUR DETAILS / CONFIGURATION HERE
  3. #------------------------------------------
  4. :global ddnsuser "your_changeip_login_name"
  5. :global ddnspass "password"
  6. :global ddnshost "registered_hostname"
  7. :global ddnsinterface "ether1_port"
  8. #------------------------------------------
  9. # END OF USER DEFINED CONFIGURATION
  10. #------------------------------------------


  11. :global ddnssystem ("mt-" . [/system package get [/system package find name=system] version] )
  12. :global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface] address ]
  13. :global ddnslastip

  14. :if ([:len [/interface find name=$ddnsinterface]] = 0 ) do={ :log info "DDNS: No interface named $ddnsinterface, please check configuration." }

  15. :if ([ :typeof $ddnslastip ] = "nothing" ) do={ :global ddnslastip 0.0.0.0/0 }

  16. :if ([ :typeof $ddnsip ] = "nothing" ) do={

  17. :log info ("DDNS: No ip address present on " . $ddnsinterface . ", please check.")

  18. } else={

  19.   :if ($ddnsip != $ddnslastip) do={

  20.     :log info "DDNS: Sending UPDATE!"
  21.     :log info [ :put [/tool dns-update name=$ddnshost address=[:pick $ddnsip 0 [:find $ddnsip "/"] ] key-name=$ddnsuser key=$ddnspass ] ]
  22.     :global ddnslastip $ddnsip

  23.   } else={
  24.   
  25.    :log info "DDNS: No changes necessary."

  26.    }
  27. }
複製代碼
When you are happy with the above code, then you can create a scheduled task for the system.

Procedure:
1. [System]->[Scheduler]
2. Put the code "/system script run changeip"



Remarks:

If the router is connected to the Internet via the DHCP method, then
ddnsinterface = ether1-gateway

If the router is connected to the Internet via the PPPoE method, then
ddnsinterface = pppoe-out1
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

一楼的信息,只能读出Public IP address,而不是在WAN口的IP Address,不知道怎样修改才是读出WAN IP address?

为什么我这样问呢?因为有有些Service,需要知道WAN IP Address?

TOP

本帖最後由 角色 於 2018-2-11 00:46 編輯

同一个位置(same variable)。就是Public IP变为local wan IP。global ddnsip。

因为大陆很多WAN都是local IP,而不是public IP。

(我估计以前原作者,没有预计过,RouterOS的WAN IP是local IP而不是Public IP)

不知道是否需要修改下面一句:

:global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface] address ]

TOP

谢谢CHing的scripts。

TOP

本帖最後由 角色 於 2018-2-11 10:48 編輯

回復 6# gfx86674

CHing,用你的changeip不成功,log都没有反应,还有看不到那个interface的IP? 不知道CHing是否有打错东西?

我的RouterOS bugfix 6.39.3版本。

TOP

原来是这样,谢谢CHing那么详细讲解。

因为在大陆,就拿中国移动来说,她的宽带部分给我来的IP都是内部IP,所以我们RouterOS的WAN口都是内部IP。有了这个内部IP不是什么都没有用,而是用中移动手机上网,因为是移动内部网络,所以手机后面的router能把你信息route到你的Router的WAN口(虽然是private IP)。

有了这个IP,我可以后面设置VoIP,那么在外面都可以往办公室的VoIP拨打。

而现在的scripts,都是有一个假设,就是WAN口就是Public IP。(在香港可以正常使用,其他给Public IP的国家)。

而在大陆,很多WAN就是Private IP,在同一个系统内(如移动宽带和移动电话),这个移动公司内的IP是可以互通的。

TOP

本帖最後由 角色 於 2018-2-11 16:52 編輯

首先我们要知道几件事:

1、Internet 有两种IP address,第一种是Public IP address,第二种是Public reserved IP address(在互联网是没有routing的,是自己处理)。
2、ChangeIP的DNS不接纳local private address。
3、确认第一楼的信息是可以update ether1(WAN) IP address (如果IP address是public IP address or public reserved IP address)

今天才明白怎么会事,就是以前中国移动给你光猫,后面modem你自己处理。那个时候同样的changeip DDNS script都可以工作,是否有中国移动给你Reserved IP address,所以那个时候changeip ddns让你update他们的server。

现在呢?移动给你一个盒子,但是拨号过去只得local private address,那么我是changeip ddns script to update WAN address,由于是local private address,ChangeIP不给你update他们的server。所以的Changeip是无法做到的。除非他们修改他们的update限制,就是允许local private IP address。

另外一个方法,就是跟中国移动说,只要光猫,不要光猫+router。

我们可以用下面指令去检验:
  1. /tool dns-update name=hostname_to_be_updated address=123.123.123.123 key-name=$changeip_username key=$changeIP_password
複製代碼

TOP

CHing你说这样都是好方法,但是问题是我么有那个Public IP,他们的router不会给我做什么routing,所以。。。都是采用发方向穿墙方法把两边连起来。

TOP

返回列表