Dynamic DNS of changeip on RouterOS 6.30.1
[i=s] 本帖最後由 角色 於 2016-2-23 11:37 編輯 [/i]Besides the official hostname adddress you can use your own hostname, for example [url]www.changeip.com[/url], 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[code]
#------------------------------------------
# EDIT YOUR DETAILS / CONFIGURATION HERE
#------------------------------------------
:global ddnsuser "your_changeip_login_name"
:global ddnspass "password"
:global ddnshost "registered_hostname"
:global ddnsinterface "ether1_port"
#------------------------------------------
# END OF USER DEFINED CONFIGURATION
#------------------------------------------
:global ddnssystem ("mt-" . [/system package get [/system package find name=system] version] )
:global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface] address ]
:global ddnslastip
:if ([:len [/interface find name=$ddnsinterface]] = 0 ) do={ :log info "DDNS: No interface named $ddnsinterface, please check configuration." }
:if ([ :typeof $ddnslastip ] = "nothing" ) do={ :global ddnslastip 0.0.0.0/0 }
:if ([ :typeof $ddnsip ] = "nothing" ) do={
:log info ("DDNS: No ip address present on " . $ddnsinterface . ", please check.")
} else={
:if ($ddnsip != $ddnslastip) do={
:log info "DDNS: Sending UPDATE!"
:log info [ :put [/tool dns-update name=$ddnshost address=[:pick $ddnsip 0 [:find $ddnsip "/"] ] key-name=$ddnsuser key=$ddnspass ] ]
:global ddnslastip $ddnsip
} else={
:log info "DDNS: No changes necessary."
}
}
[/code]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"
[attach]3654[/attach]
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 This script won't work behind NAT.
The simplest way is to replace "/system script run changeip" with[code]/tool fetch url="https://nic.ChangeIP.com/nic/update?hostname=your_hostname&u=your_username&p=your_password" mode=https[/code]for other options, please check [url]http://www.changeip.com/accounts/knowledgebase.php?action=displayarticle&id=34[/url]
There is a risk that
[quote]If omitted your detected IP address will be used. Please be advised that if you are behind a proxy and we detect your IP address we might be using the proxy server address, not your real address.[/quote] 一楼的信息,只能读出Public IP address,而不是在WAN口的IP Address,不知道怎样修改才是读出WAN IP address?
为什么我这样问呢?因为有有些Service,需要知道WAN IP Address? 很容易,但讀出wan的ip後您想將address存到那位置? [i=s] 本帖最後由 角色 於 2018-2-11 00:46 編輯 [/i]
同一个位置(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 ] [i=s] 本帖最後由 gfx86674 於 2018-2-11 01:32 編輯 [/i]
小弟我喜歡用自己的方式{:5_170:}
[size=7]changeip:[/size][code]#==================================
:local host "abcd1234.changeip.org"
:local user "abcd1234@hotmail.com"
:local pass "12345678"
#==================================
/tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path=checkip ; :delay 5s
:local past [:resolve $host]
:local public [/file get checkip contents]
:set public [:pick $public ([:find $public ":"]+1) [:find $public "</body>"]]
/tool dns-update name=$host address=$public key-name=$user key=$pass
:log warning "$host : $past => $public"
/file remove checkip[/code][size=7]
dyndns:[/size][code]#==================================
:local host "abcd1234.dyndns.org"
:local user "abcd1234"
:local pass "12345678"
#==================================
/tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path=checkip ; :delay 5s
:local past [:resolve $host]
:local public [/file get checkip contents]
:set public [:pick $public ([:find $public ":"]+1) [:find $public "</body>"]]
/tool fetch address=members.dyndns.org mode=http user=$user password=$pass dst-path=ddns \
src-path="/nic/update\?hostname=$host&myip=$public&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG" ; :delay 5s
:log warning "$host : $past => $public"
/file remove checkip ; /file remove ddns
[/code][color=Blue]更新結束 ,成果會顯示在log內~[/color] 谢谢CHing的scripts。 [i=s] 本帖最後由 角色 於 2018-2-11 10:48 編輯 [/i]
[b]回復 [url=http://www.telecom-cafe.com/forum/redirect.php?goto=findpost&pid=44207&ptid=6700]6#[/url] [i]gfx86674[/i] [/b]
CHing,用你的changeip不成功,log都没有反应,还有看不到那个interface的IP? 不知道CHing是否有打错东西?
我的RouterOS bugfix 6.39.3版本。 [img]https://i.imgur.com/sGMME4F.png[/img][b]回復 [url=http://www.telecom-cafe.com/forum/redirect.php?goto=findpost&pid=44212&ptid=6700]8#[/url] [i]角色[/i] [/b]
沒使用interface是因為全都是private address沒任何義意.
所以address要透過這網站顯示[url=http://checkip.dyndns.org]http://checkip.dyndns.org[/url],
再下載html頁到router的硬碟,從硬碟抓出address關鍵字再更新到您的ddns.
不過要是您的router打不開checkip.dyndns.org的網站,
就只能再換其它網站抓ip 原来是这样,谢谢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是可以互通的。 [i=s] 本帖最後由 角色 於 2018-2-11 16:52 編輯 [/i]
首先我们要知道几件事:
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。
我们可以用下面指令去检验:[code]/tool dns-update name=hostname_to_be_updated address=123.123.123.123 key-name=$changeip_username key=$changeIP_password [/code] [i=s] 本帖最後由 gfx86674 於 2018-2-11 19:49 編輯 [/i]
就算一堆原因封住,要更新Router地址的手段其實很多
routeros firewall有add-src-to-address-list功能,將來源address存到list裡.
CN-Router ping HK-Router ,
HK-Router只會抓到CN-Router的public-address ,絕不會是private-address...
所以請HK-Router代勞 ,上傳這個抓到的address到DDNS上也是可以的{:4_93:} CHing你说这样都是好方法,但是问题是我么有那个Public IP,他们的router不会给我做什么routing,所以。。。都是采用发方向穿墙方法把两边连起来。
頁:
[1]