Mikrotik DynDNS help!

acidrain

Executive Member
Joined
Jan 7, 2007
Messages
5,975
Hi Guys,

Hope someone can help. Basically my mikrotik router dials out my dsl account ( reasons being I can monitor access more strictly and easily ). Now i want to be able to access my pc and all the services I have running on it from my office.

What I need is some guidelines on how to setup DynDNS properly ( and which dyndns providers are supported ) and also somehow "forward" connections meant for my pc since I NAT my pc ip on the mikrotik.

Basic setup is:

PC ( 172.18.42.97 ) ---- Mikrotik ( 172.18.42.110 ) --- NAT --- Internet

Is it possible to reverse NAT, so to speak, so when i type in the dns name i dont end up at my mikrotik web login but my pc's webserver? If so how would I do this.

If you need any additional info just ask :)

Thanks

Edit: Above IP's cannot be changed since these are my WUG ip's
 

wetkit

Expert Member
Joined
Oct 27, 2003
Messages
1,126
acidrain, yes it is possable.
TFyre have done it for me in the past.
Think we used myddns for the link, but the RB must send the IP update at regular intervals so the two can be linked.
Once you connected to you RB via the net, you would have to add extra routing to your work PC so that you can access your home network.

Cheers
 

hilton

Expert Member
Joined
Aug 19, 2003
Messages
1,807
Use changeip for your ddns account;
http://www.changeip.com

Then use this script to update the IP regularly and remember to schedule it.
http://wiki.mikrotik.com/wiki/Dynamic_DNS_Update_Script_for_ChangeIP.com

Then use this example to create a dst-nat rule in your firewall to redirect you to your PC behind the firewall but change the port to 80. Remember to set the Mikrotik's web services to port 81;
http://wiki.mikrotik.com/wiki/Redirect_mail_traffic_to_a_specified_server

This should get you started, hope it helps.
 

acidrain

Executive Member
Joined
Jan 7, 2007
Messages
5,975
Just one thing, from the above link, i copied the script under where it says "ROS 3.0 Compatible" Running 3.19. But now I'm not too sure how to do the scheduler... what will the "On Event" be

Edit: Ya I must be doing something wrong since it doesn't show any update request on the website and the script has apparently run twice

Here's the code

Script:
Code:
system script print
Flags: I - invalid 
 0   name="DDNS" owner="admin" 
     policy=ftp,reboot,read,write,policy,test,winbox,password,sniff 
     last-started=jun/28/2010 18:24:35 run-count=1 
     source=
       # Define User Variables
       :global ddnsuser "Toady99"
       :global ddnspass "*****"
       :global ddnshost "jono.changeip.net"
       
       # Define Global Variables
       :global ddnsip
       :global ddnslastip
       :if ([ :typeof $ddnslastip ] = nil ) do={ :global ddnslastip "0" }
       
       :global ddnsinterface
       :global ddnssystem ("mt-" . [/system package get system version] )
       
       # Define Local Variables
       :local int
       
       # Loop thru interfaces and look for ones containing
       # default gateways without routing-marks
 :foreach int in=[/ip route find dst-address=0.0.0.0/0 active=yes ] do={ 
         :if ([:typeof [/ip route get $int routing-mark ]] != str ) do={
            :global ddnsinterface [/ip route get $int interface]
         } 
       }
       
       # Grab the current IP address on that interface.
       :global ddnsip [ /ip address get [/ip address find interface=$ddnsinter>
       
       # Did we get an IP address to compare?
       :if ([ :typeof $ddnsip ] = nil ) do={
          :log info ("DDNS: No ip address present on " . $ddnsinterface . ", p>
       } else={
       
         :if ($ddnsip != $ddnslastip) do={
       
           :log info "DDNS: Sending UPDATE!"
           :log info [ :put [/tool dns-update name=$ddnshost address=[:pick $d>
           :global ddnslastip $ddnsip
       
         } else={ 
           :log info "DDNS: No update required."
  }
       
       }

Scheduler:
Code:
system scheduler print
Flags: X - disabled 
 #   NAME                        ON-EVENT                                                                  START-DATE                     START-TIME                      INTERVAL             RUN-COUNT 
 0   DNS-UPDATE                  DDNS policy=read,write,policy,test,password                                                          startup                             5m                           2
 
Last edited:

hilton

Expert Member
Joined
Aug 19, 2003
Messages
1,807
The 'on event' is the name of your script.

Use lowercase and a single word to keep things easy. So call your script ddns and then reference this in the scheduler. Set it to start on startup and then intervals of 5min.
 

acidrain

Executive Member
Joined
Jan 7, 2007
Messages
5,975
Found a script that seems to be working
Code:
/system script add name=dyndns-update policy=read,test source={
# Set needed variables
:local username "dyndnsUsername"
:local password "dyndnsPassword"
:local hostname "hostname.dyndns.org"

:global dyndnsForce
:global previousIP

# print some debug info
:log info ("dyndns-update: username = $username")
:log info ("dyndns-update: password = $password")
:log info ("dyndns-update: hostname = $hostname")
:log info ("dyndns-update: previousIP = $previousIP")

# get the current IP address from the internet (in case of double-nat)
/tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="/dyndns.checkip.html"
:local result [/file get dyndns.checkip.html contents]

# parse the current IP result
:local resultLen [:len $result]
:local startLoc [:find $result ": " -1]
:set startLoc ($startLoc + 2)
:local endLoc [:find $result "</body>" -1]
:local currentIP [:pick $result $startLoc $endLoc]
:log info "dyndns-update: currentIP = $currentIP"

# Determine if dyndns update is needed
# more dyndns updater request details available at http://www.dyndns.com/developers/specs/syntax.html
:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
    :set dyndnsForce false
    :set previousIP $currentIP
    /tool fetch user=$username password=$password mode=http address="members.dyndns.org" src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/dyndns.txt"
    :local result [/file get dyndns.txt contents]
    :log info ("dyndns-update: Dyndns update needed")
    :log info ("dyndns-update: Dyndns Update Result: ".$result)
    :put ("Dyndns Update Result: ".$result)
} else={
    :log info ("dyndns-update: No dyndns update needed")
}
}

Now onto the reverse natting. I did as you said above, but for some reason this interferes with my browsing as the router is trying to nat me back to my machine when in fact im trying to get out, if you get what i'm trying to say


Question though. Is it easier to go this method or to setup a VPN between the two routers?
 
Last edited:

acidrain

Executive Member
Joined
Jan 7, 2007
Messages
5,975
what does ur Nat/port forward look like?

Code:
 6   chain=dstnat action=dst-nat to-addresses=172.18.42.97 to-ports=80 
     protocol=tcp src-address=!172.16.0.0/12 dst-port=80

The reason for the !172... is because without it I can't browse the net so just specifying to dst-nat all ip's except those in that range.

The above currently doesn't work and guys I have spoken to on the wug seem to think it should work :confused:
 
Top