0

Access Mikrotik Remotely via DynamicDNS

 

~ Article By Syed Jahanzaib ~
Last Updated : 28th January, 2014
If you have Mikrotik Server with DSL connection with dynamic ip , which changes on every reboot / reset, and you want to access mikrotik from the Internet then you can use changeip.com (DynamicDNS) service, using this service, you don’t have to query the DSL IP every time, all you have to remember the domain name that you register on the site, and rest of things will be handled by the DDNS script configured on the Mikrotik.
Following is the the scenario:
  1. …    INTERNET            >>    DSL MODEM          >>> MIKROTIK
    User with WINBox            (with dynamic ip)
  2. DSL MODE IP              =   192.168.30.1
    MIKROTIK WAN IP =  192.168.30.5
Ok Lets Start.

CONFIGURE DSL MODEM TO ENABLE PORT FORWARDING

  • First open you DSL Modem page to enable PORT Forwarding (from DSL Modem to Mikrotik box)
    Now add Port Forwarding rule
  • WINBOX uses TCP Port 8291
    As showed in the image below . . .

Now Click on SAVE / APPLY
.

CREATE NEW ACCOUNT ON CHANGEIP.COM

  1. Now Open http://www.changeip.com in your browser and register new account.
    As showed in the image below . . .
1

2


Now it will send you an confirmation email, Open your mail box, and click on the link it have send you to activate your account.
  1. ADD DOMAIN NAME TO YOUR ACCOUNT

  • Login to see your account , by default no domain name is added, Just click on DNS MANAGER to add your required name

As showed in the image below . . .
3

Now you have to add your own desired name and its domain.  You can select various domains from the drop down list. As showed in the image below . . .
4
After adding your domain name, You can see your domain name in the main page,
As showed in the image below . . .
5
Now its time to configure the DynamicDNS script on the Mikrotik.

CONFIGURE DDNS SCRIPT AND SCHEDULER ON MIKROTIK

 

  • Login to Mikrotik via WINBOX,
    Click on NEW TERMINAL , after login, paste the following text in the TERMINAL window,
  • ddns-script-direct-nat script code:
  • Script taken from
    [Preferred]
    http://www.changeip.com/mikrotik/5.x.txt

 

/system script
 
add name=ddns policy=\
ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
source="# HomingBeacon Main Dynamic DNS Update Script\r\
\n# Written by Sam Norris, ChangeIP.com\r\
\n# 20100728 Tested on RouterOS 4.9\r\
\n# 20110511 Tested on RouterOS 5.2\r\
\n\r\
\n# Set your specific ChangeIP.com preferences here.\r\
\n:global ddnsuser \"your-userid\"\r\
\n:global ddnspass \"your-password\"\r\
\n:global ddnshost \"your-site-name\"\r\
\n# Change ddnsport to 8245 to bypass proxy.\r\
\n:local ddnsport 8245\r\
\n\r\
\n# Do not edit anything below this line.  You have been warned.\r\
\n# Abusive updates to the system will cause firewall blocks.\r\
\n\r\
\n# Please be considerate and\r\
\n# do not let this script run more than once per 3-5 minutes.\r\
\n\r\
\n:log info \"DDNS: Starting.\"\r\
\n\r\
\n# Initialize checkpoint\r\
\n:global ddnscheckpoint\r\
\n:if ([:typeof \$ddnscheckpoint] = \"time\") do={\r\
\n\t:log info (\"DDNS: Last check was \" . ([/system clock get time] - \$d\
dnscheckpoint))\r\
\n} else={\r\
\n\t:log info \"DDNS: Cannot determine checkpoint, set now.\"\r\
\n\t:global ddnscheckpoint ( [/system clock get time] - 1d )\r\
\n}\r\
\n\r\
\n# Get the current IP\r\
\n:if ([/system clock get time] - \$ddnscheckpoint > [:totime 180s] || [/s\
ystem clock get time] - \$ddnscheckpoint < [:totime 0s]) do={\r\
\n   :log info \"DDNS: Performing remote IP detection.\"\r\
\n   /tool fetch address=\"ip.changeip.com\" host=\"ip.changeip.com\" src-\
path=(\"/\?\" . [/int eth get 0 mac-address ]) dst-path=\"ip.changeip.com.\
txt\" mode=http port=\$ddnsport\r\
\n   :global ddnscheckpoint [/system clock get time]\r\
\n} else={\r\
\n   :log info \"DDNS: Please be considerate and wait a few seconds longer\
.\"\r\
\n   :break\r\
\n}\r\
\n\r\
\n# Parse the IP address received from fetch script.\r\
\n\t:global ddnslastip\r\
\n\t:local html [/file get \"ip.changeip.com.txt\" contents]\r\
\n\t:local ddnsip [:pick \$html ([:find \$html \"<!--IPADDR=\"] + 11) [:fi\
nd \$html \"-->\"] ]\r\
\n\r\
\n# Is it a valid IP and is it different than the last one\?\r\
\n\t:if ([:typeof [:toip \$ddnsip]] = \"ip\" AND \$ddnsip != \$ddnslastip \
) do={\r\
\n\t\t:log info \"DDNS: Sending UPDATE with \$ddnsip\"\r\
\n\t\t:log info [/tool dns-update name=\$ddnshost address=\$ddnsip key-nam\
e=\$ddnsuser key=\$ddnspass ]\r\
\n\t\t:global ddnslastip \$ddnsip\r\
\n\t} else={\r\
\n\t\t:log info \"DDNS: No update required.\"\r\
\n\t}\r\
\n}\r\
\n"

As showed in the image below . . .


To verify that the script is pasted and working properly,
Goto SYSTEMS   >  SCRIPTS , and double click on the DDNS to view its contents, Just verify it everything is in place.
As showed in the image below . . .

Okay, as the script is in place, its time to Execute the script so it can update the current WAN IP to your DynamicDNS account.
As showed in the image below . . .

As you can see that the script have updated the record to dynamicDNS account, its time to verify it.

ADDING SCHEDULER (So it can update record after every 5 minutes)

Also add this in scheduler so it can run after every 5 minutes, you can adjust it as per your requirement.
1
2
3
/system scheduler
add disabled=no interval=5m name="Run DDNS every 5 minutes" on-event=update-ddns policy=\
ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api start-date=mar/30/2012 start-time=14:24:00

VERIFY UPDATED IP RECORD ON CHANGEIP.COM

Go back to changeip.com and see your domain name record by clicking on
View Recent DDNS Updates
As showed in the image below . . .
6
Now it will show you the updated Record.
As showed in the image below . . .
7
Everything is now ready and in place.


TEST TIME !!!


CONNECT TO YOUR MIKROTIK FROM INTERNET

Its time to hit the road. From any other Remote PC with separate internet connection, try to ping your domain name and try to connect it via winbox or try open it in your browser,
NTOE: In the image below, I used another domain name, as at the moment I only had old image , so ignore the name, just understand the logic
As showed in the images below . . .

.
.






Post a Comment

 
Top