How to setup dynamic server dns mikrotik

Ditulis oleh: -
How to setup dynamic server dns mikrotik - How to Set Update Dynamic DNS in MikroTik, DDNS (Dynamic DNS) IS a system in the network that allows to translate domain names into dynamic Public IPs (changing). The administrator does not need to update the DNS server every time there is an IP update request. The given IP Public will change when the ADSL modem breaks or when the modem turns off and then on again, for example if we use telkom speedy service. In mikrotik we can take advantage of script and scheduler features for automatic update of our IP Dynamic DNS.
How to Set Update Dynamic DNS in MikroTik

When do you need Dynamic DNS service?

There are several scenarios that determine when you use the Dynamic DNS service, which does not want to mess around with a changing IP Public. When you need Dynamic DNS service:

  • When you use an ISP service that delivers dynamic public IP (changing).
  • You have a server or application on your internal network. With IP Public & DDNS we can do some things, such as:
  • Want remote mikrotik with winbox from outside, for example remote from home, office, campus or internet cafe for example.
  • Monitoring offices, homes, campuses or internet cafes via CCTV cameras from anywhere. Like the example of DVR / CCTV forwarding setting in Mikrotik in my previous article.
  • Internal server application that can be accessed from outside / internet, for example web server, VPN server, FTP, email server etc.


What to prepare for Dynamic DNS settings in MikroTik?

To implement dynamic dns in mikrotik, there are some steps you should do and know the network scenario. 

Register to a dynamic DNS service site in this article site that provides free Dynamic DNS service and support with mikrotik. Example in this script I use 2 free Dynamic DNS service sites: 

ChangeIP.com 
Free 7 sub domains, in the sense you can have 7 sub domain names with different Public IP. 

NoIP.com 
Free 3 sub domains, in the sense you can have 3 sub domain names with different Public IP. 

Example of network scenario with ADSL modem telkom speedy
ADSL Modem -----> MikroTik -> IP Server Internal 
Bridge / IP Forwarding-> NAT ---> Local IP destination

In the above scenario, we will determine the setting of our ADSL / speedy modem. Whether the bridge mode ( Dial PPPoE Speedy in MikroTik ), or use forwarding mode (Setting Forwarding in ADSL Modem). If in forwarding mode, it means that your mikrotik is behind the ADSL NAT modem, or my language is routed by the modem. You must first forwarding settings (virtual server, port mapping, etc) on your ADSL modem. If in bridge mode, your IP public speedy will be directly in interfaces wan mikrotik you.

Setting Script Update Dynamic DNS in MikroTik For Dyndns, No-IP or ChangeIP


As I mentioned earlier, we can take advantage of the script and scheduler features for automatic update of our IP Dynamic DNS. In this script has the function:

  • Automatic update of our IP Dynamic DNS for Dyndns, No-IP or ChangeIP services.
  • IP public catch option behind NAT or not.
  • Log update date, and previous IP changes with new IP.
  • Automatically deletes our internal DNS records (mikrotik flush DNS) to keep the DDNS hostname updated with its new IP.


Enter this script in winbox System> Scripts , column " Name: update_ip_ddns" and in the " Source: " field fill in the script below:

# ************************************************************** * * * * * * * * * * * * * * * *
# Script Update Dynamic DNS in MikroTik For Dyndns, No-IP and ChangeIP
# Thanks to: forum . mikrotik . com , the thread forgot ^ _ ^
# Adam Rachmad / Tested & Work @ ROS v.6.13 18-6-2014
# http : // adamonline . the web . id
# ************************************************************** * * * * * * * * * * * * * * * *
# replace with your account information, your username / password / DDNS hostname
# ************************************************************** * * * * * * * * * * * * * * * *
 
: local username "username_anda"
: local password "password_anda"
: local hostname "hostname.anda"
 
# 2 option to capture your public IP "http" or "iface"
# - http: will catch / search the public IP you use (the scenario if you are behind the ADSL ADSL modem)
# - iface: will use public ip which is set in your mikrotik WAN interface
 
: local discoverBy "http"
 
# the name of the WAN interface to be used to capture your public IP (if the discoverBy = iface option)
 
: local iface "nama_interface_wan_anda"
 
# choose one of the Dynamic DNS services you use: "dyndns", "noip", and "changeip"
 
: local service "changeip"
 
# Schedule (days) to update if the IP does not change (to keep your DDNS account active)
: local forceUpdate 15
 
# ************************************************************** * * * * * * * * * * * * * * * *
# below do not change if you do not know what you are doing
# ************************************************************** * * * * * * * * * * * * * * * *
 
: local force
: global lastUpdate
: local currentIP
 
: if ($ discoverBy = "http") do = { 
   / tool fetch mode = http address = "checkip.dyndns.org" src-path = "/" dst-path = "/ dyndns.checkip.html"
   : local result [/ file get dyndns.checkip.html contents]
   : local resultLen [: len $ result]
   : local startLoc [: find $ result ":" -1]
   : set startLoc ($ startLoc + 2)
   : local endLoc [: find $ result "" -1]
   : set currentIP [: pick $ result $ startLoc $ endLoc]
} else = {
   : set currentIP [/ ip address get [find interface = $ iface disabled = no] address]
   : for i from = ([: len $ currentIP] - 1) to = 0 do = {
      : if ([: pick $ currentIP $ i] = "/") do = {: set currentIP [: pick $ currentIP 0 $ i]} 
   }
}
 
: local resolvedIP [: resolve $ hostname]
: local date [/ system clock get date]
: local months ("jan", "feb", "mar", "apr", "may," "jun", "jul", "aug", "sep", "oct", "nov", "dec ");
: local month [: pick $ date 0 3]; : local day [: pick $ date 4 6]; : local year [: pick $ date 7 11];
: local mm ([: find $ months $ month -1] + 1);
: if ($ mm <10) do = {: set month ("0". $ mm); } else = {: set month $ mm; }
: set date ($ year. $ month. $ day);
 
: if ([: typeof $ lastUpdate] = [: nothing] || (($ date- $ lastUpdate)> = $ forceUpdate && $ forceUpdate> 0)) do = { 
   : set force true 
}
 
: put ("Current IP: $ currentIP ($ discoverBy), Last update: $ lastUpdate")
 
# Determine if dyndns update is needed
: if (($ currentIP! = $ resolvedIP) || ($ force = true)) do = {
    
    : if ($ service = "dyndns") do = {
       / tool fetch user = $ username password = $ password mode = http address = "members.dyndns.org" \
            src-path = "/ nic / update? hostname = $ hostname & myip = $ currentIP" dst-path = "/ output.txt"
    }
    : if ($ service = "noip") do = {
       / tool fetch user = $ username password = $ password mode = http address = "dynupdate.no-ip.com" \
            src-path = "/ nic / update? hostname = $ hostname & myip = $ currentIP" dst-path = "/ output.txt"
    }
    : if ($ service = "changeip") do = {
       / tool fetch user = $ username password = $ password mode = http address = "nic.changeip.com" \
            src-path = "/ nic / update? hostname = $ hostname & myip = $ currentIP" dst-path = "/ output.txt"
    }
    : local result [/ file get output.txt contents]
    : log info ("dynamic-dns-updater: Service = $ service, Hostname = $ hostname")
    : log info ("dynamic-dns-updater: CurrentIP = $ currentIP, Resolved IP = $ resolvedIP")
    : log info ("dynamic-dns-updater: Update result:". $ result)
    / ip dns cache flush
    : set lastUpdate $ date
}

Then we create Schedule for DDNS update every 5 Minutes

/ system scheduler
add disabled = no interval = 5m name = "Update DDNS every 5 minutes" on-event = update_ip_ddns policy = \
ftp, reboot, read, write, policy, test, winbox, password, sniff, sensitive, fire start-date = mar / 30/2014 start-time = 14: 24: 00

Now just verify whether it works well or not, by looking at the updated IP address on your DDNS site. Or try to access with the hostname you have specified.

0 komentar "How to setup dynamic server dns mikrotik", Read or Comment r

Post a Comment