Here is a script that will update the ChangeIP.com dynamic DNS system whenever your DHCP interface changes IP addresses.
This script checks for changed IPs each 30 seconds.
This script will run with no one logged into the router.
This script needs to be modified to fit your environment. See below:
Step 1.
Copy this script into Notepad or other editor.
Step 2.
Modify the values in the ‘ddnsInit’ script to fit your particular environment.
u = Your Username on ChangeIP.com
p = Your Password on ChangeIP.com
s = System Name. You can leave this as default, this is for our stats.
h = Hostname to update. *1 means set 1 - many hosts at once.
dhcpInterface = This is the interface name on Mirkotik that you want to monitor.
ddnsProxyEmail = The address to send the updates to. Leave this as default.
ddnsFromEmail = The email address you want the results emailed to upon update.
ddnsSmtpServer = The default is our mail server. Feel free to use any mail server capable of delivering mail to us reliably.
Step 3.
Save this script somewhere for later use. Now copy and paste the script as is into the command line environment of Mikrotik. This will remove the previous scripts, if any, and enter the new ones.
Step 4.
Let the script run for 1 minute at least. You should receive an email with the results of the update.
This script should be complete. There are a few items that we are completing on the backend proxy service, ie: cleaned up result email, etc. We will also, if anyone wishes, create a proxy that can be used for any other DDNS providers. how nice right? We like you to use ChangeIP.com, but if you need to get this going asap before you switch over we can help you.
Here is the script. Paste into terminal window once modified for your credentials.
/system scheduler remove ddnsJob
/system script remove ddnsCheck
/system script remove ddnsInit
/system script remove ddnsReset
/system script remove ddnsSendUpdate
/system script add name="ddnsInit" source={
:log message="ddnsInit: Creating Dynamic DNS update system."
:global u
:set u "USERID"
:global p
:set p "PASSWORD"
:global s
:set s "Mikrotik"
:global h
:set h "*1"
:global dhcpInterface
:set dhcpInterface "ether0"
:global ddnsProxyEmail
:set ddnsProxyEmail "ddnsUpdate@ChangeIP.com"
:global ddnsFromEmail
:set ddnsFromEmail "youremail@domain.tld"
:global ddnsSmtpServer
:set ddnsSmtpServer "63.210.174.75"
:global a
:set a [ \
/ip address get \
[/ip address find interface=$dhcpInterface] \
address \
]
}
/system script add name="ddnsCheck" source={
:if ([/system scheduler get ddnsJob run-count]<=1) do={
/system script run ddnsInit
}
:global temp
:global b
:set temp $a
:set b [ \
/ip address get \
[/ip address find interface=$dhcpInterface] \
address \
]
:if ($temp != $b) do={
:log message="ddnsCheck: Found new IP address."
/system script run ddnsSendUpdate
:set a $b
}
}
/system script add name="ddnsSendUpdate" source={
:log message=("ddnsSendUpdate: Sending Dynamic DNS smtp update to " . $ddnsSmtpServer)
/tool e-mail send \
to=$ddnsProxyEmail \
from=$ddnsFromEmail \
server=$ddnsSmtpServer \
subject="New Dynamic IP" \
body=("u=" . $u . "&p=" . $p . "&hostname=" . $h . "&system=" . $s . "&myip=" . $b)
}
/system script add name="ddnsReset" source={
:log message="ddnsReset: Resetting global values."
/system scheduler set ddnsJob run-count=0
:unset u
:unset p
:unset s
:unset h
:unset dhcpInterface
:unset ddnsProxyEmail
:unset ddnsFromEmail
:unset ddnsSmtpServer
:unset a
:unset b
:unset temp
}
/system scheduler add name=ddnsJob interval=30s on-event=ddnsCheck
For support of this script as well as any other questions you can send an email to Support@ChangeIP.com. We’d love to get a few people setup to beta test this … please email us if you are helping out.
I have been working with this for some time… I emailed your support, got some advise but then the line went cold. so for the benefit of everyone I thought I would post my finding here.
\
If you are using the default pppoe name it won’t work. The script dosn’t like ‘PPPoe-out1’. Chang the name to something without the ‘-’ (PPPoe works fine)
in the line with the ‘*1’ This caused an error on my system. The changeip guys suggested using ‘-1’ This worked.
Being new to Mikrotik, I am unable to send the email. The system says it times out. Am I missing a basic setup step?
I wonder if its possible your ISP is blocking port 25 outbound. Can you try changing the outgoing smtp server in the script to your ISPs SMTP server, or whichever server that you can reliably deliver mail with? I guess if you really needed to you could add an outgoing masquerade on port 25 to 5072 to our server - this would get around any port blocks your ISP has placed on you. If you need help configuring this let me know, I’ll help you out.
I will post a modified script here shortly that will fix the *1 -1 problem, I didn’t realize Mikrotik would have a problem with the * character in a string field.
Can you try something out - try from a machine inside your network the following command: ‘telnet smtp.changeip.com 25’ and see if you get response header. If that does not work, try ‘telnet smtp.changeip.com 5072’ and see if that works. If the second works let me know and we can setup a masquerade rule that will translate that outgoing connection to port 5072 ( I think )
Here is an updated script to perform dynamic dns updates from the Mikrotik router. Changes include finding the dhcp interface automatically, performing a dns lookup to the smtp servername, and a few other clean up items.
# Dynamic DNS Update Script v1.1
# ------------------------------
# This script will perform automatic dynamic dns updates on the Mikrotik
# router platform. (http://www.mikrotik.com/) Since Mikrotik does not
# support sending http requests we have created a smtp -> ddns proxy service
# which will take the http URL querystring used for a dynamic dns update and
# process it via email.
# ------------------------------
# Written by Sam Norris, ChangeIP.com
# 7/31/04 - Created script.
# 12/9/04 - Made some values dynamic (smtp server, dhcp interface)
# ------------------------------
#
# Instructions:
# There are a few variables down below that you need to configure for your
# specific setup. Please modify the variables in the 'ddnsInit' script to
# reflect your specific information, ie userid, password, hostname to update.
#
# Blow away any existing script code, if necessary.
/system scheduler remove ddnsJob
/system script remove ddnsCheck
/system script remove ddnsInit
/system script remove ddnsReset
/system script remove ddnsSendUpdate
# Setup global variables needed to keep track of changing IP address.
/system script add name="ddnsInit" source={
:log message="ddnsInit: Creating Dynamic DNS update system."
# ENTER YOUR CHANGEIP.COM USER ID HERE.
:global u
:set u "USERID"
# ENTER YOUR CHANGEIP.COM PASSWORD HERE.
:global p
:set p "PASSWORD"
:global s
:set s "Mikrotik"
# ENTER THE TARGET HOSTNAME TO UPDATE, *1 is Set 1.
:global h
:set h "*1"
:global dhcpInterface
:set dhcpInterface [ /ip dhcp-client get interface ]
:log message=("ddnsInit: Found dhcp interface " . $dhcpInterface )
# EMAIL PROXY ADDRESS - DO NOT CHANGE FOR PRODUCTION.
:global ddnsProxyEmail
:set ddnsProxyEmail "ddnsUpdate@ChangeIP.com"
# ENTER YOUR EMAIL ADDRESS FOR CONFIRMATIONS.
:global ddnsFromEmail
:set ddnsFromEmail "youremail@domain.tld"
# SMTP DDNS PROXY SERVER - CHANGE ONLY IF NECESSARY (port 25 blocked?)
:global ddnsSmtpServer
:set ddnsSmtpServer [:resolve smtp.changeip.com]
:global a
:set a [ \
/ip address get \
[/ip address find interface=$dhcpInterface] \
address \
]
}
/system script add name="ddnsCheck" source={
:if ([/system scheduler get ddnsJob run-count]<=1) do={
/system script run ddnsInit
}
:global temp
:global b
:set temp $a
:set b [ \
/ip address get \
[/ip address find interface=$dhcpInterface] \
address \
]
:if ($temp != $b) do={
:log message="ddnsCheck: Found new IP address."
/system script run ddnsSendUpdate
:set a $b
}
}
/system script add name="ddnsSendUpdate" source={
:log message=("ddnsSendUpdate: Sending Dynamic DNS smtp update to " . $ddnsSmtpServer)
/tool e-mail send \
to=$ddnsProxyEmail \
from=$ddnsFromEmail \
server=$ddnsSmtpServer \
subject="New Dynamic IP" \
body=("u=" . $u . "&p=" . $p . "&hostname=" . $h . "&system=" . $s . "&myip=" . $b)
}
/system script add name="ddnsReset" source={
:log message="ddnsReset: Resetting global values."
/system scheduler set ddnsJob run-count=0
:unset u
:unset p
:unset s
:unset h
:unset dhcpInterface
:unset ddnsProxyEmail
:unset ddnsFromEmail
:unset ddnsSmtpServer
:unset a
:unset b
:unset temp
}
/system scheduler add name=ddnsJob interval=30s on-event=ddnsCheck
This script is for 2.8 only. 2.9 has native support for our Dynamic DNS. Please use this script for 2.9 - and schedule it to run once every few minutes.
I use the script to update my IP adress on my MikroTik 2.9.13 device.
Everything works… but I have 2x ADSL connections on my MikroTik and would like to update both IP addresses
I did configure the full hostname and servers, but both scripts (Interface_Name and Hostname changed) do update the SAME address on the changeip server.
The above scripts are for 2.8 - and are using a SMTP to DDNS proxy to get the addresses updated. 2.9 has Dynamic DNS for ChangeIP.com built in natively and can update much more efficiently.
If you want to setup round-robin to both of your dsl modems you can do that as well - or modify the script to send an update for each connection and its appropriate ip, however i think the first option is best.
I am trying to set up the DDNS support on my Mikrotik router, however I have the problem: telneting you there is no answer on the port 25 which you suggested to check below. I may log in through the 5072 port.
“Can you try something out - try from a machine inside your network the following command: ‘telnet smtp.changeip.com 25’ and see if you get response header. If that does not work, try ‘telnet smtp.changeip.com 5072’ and see if that works. If the second works let me know and we can setup a masquerade rule that will translate that outgoing connection to port 5072 ( I think )”
Would you help me out with a solution you mentioned above?
An other thing, when I past the scrit to my command line session and run the script in the log I find the following post:
It sounds like port 25 is blocked to your router from your ISP. Is it possible to enter their SMTP server and have it forward ? Or any smtp server that will relay for you.
:global ddns-interface “EXACTINTERFACENAME”
Check the above variable and make sure the interface name is exactly as it is in mikrotik… if it can’t find the interface it will give you the error you are seeing.
The 2.9 script is much more robust, are you planning on upgrading to 2.9 anytime soon ?
:global dhcpInterface
:set dhcpInterface [ /ip dhcp-client get interface ]
:log message=("ddnsInit: Found dhcp interface " . $dhcpInterface )
script part to get the global and it find it since it sends a message in the log. (It finds the ether0 called WAN on my router, should not I use the pppoe interface name which sits on the WAN interface?) Anyway that does not work neither, I tryed.
Is it possible to enter their SMTP server and have it forward?
I am not sure how to forward that.
Or any smtp server that will relay for you.
Maybe I will try some.
The 2.9 script is much more robust, are you planning on upgrading to 2.9 anytime soon ?
[quote=“Vendég”]If you mean better, I will upgrade.[quote]
2.9 is way ahead of 2.8 : ) I don’t want you to upgrade though until you are ready, but its ddns functionality is much better. The ddns via smtp proxy was a temporary hack for 2.8 because it did not support our services yet.
hi ,
I am a newbie to mikrotik scripts,
can some one pls let me know hot to schedule to mikrotik to run the scripr for 2.9 every 30 seconds.
many thanks in advance
SAT DAVE
If you are using 2.9 or above please do not use this SMTP proxy version. 2.9 is much more efficient at ddns updates, search the wiki or forums to find the new script. Then, once you paste the script into the RouterOS, make a scheduler job with the name of that script. I suggest scheduling it no more than 1 time per minute, 5 minutes is normal.