Community discussions

MikroTik App
 
Zapnologica
Long time Member
Long time Member
Topic Author
Posts: 594
Joined: Fri Sep 25, 2009 8:15 pm
Location: South frica

Dydns update on certain interface

Sun May 25, 2014 10:25 am

I have two dyndns updater scripts,

I want one to update the one gateway / interface and the other to do the other gateway / interface

What do I need to change in the scripts to specify which one to update?

Here is my script (Both are the same except for user and password)
# Set needed variables
:local username "username"
:local password "password"
:local hostname "hostname"

:global dyndnsForce
:global previousIP

# print some debug info 
:log info ("UpdateDynDNS: username = $username")
:log info ("UpdateDynDNS: hostname = $hostname")
:log info ("UpdateDynDNS: 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 "UpdateDynDNS: currentIP = $currentIP"

# Remove the # on next line to force an update every single time - useful for debugging, but you could end up getting blacklisted by DynDNS!
#:set dyndnsForce true

# 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 ("UpdateDynDNS: Dyndns update needed")
    :log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
    :put ("Dyndns Update Result: ".$result)
} else={
    :log info ("UpdateDynDNS: No dyndns update needed")
}
 
efaden
Forum Guru
Forum Guru
Posts: 1708
Joined: Sat Mar 30, 2013 1:55 am
Location: New York, USA

Re: Dydns update on certain interface

Sun May 25, 2014 1:09 pm

There is no simple way that I know of to do that since you cannot specify an interface for fetch.

Sent from my SCH-I545 using Tapatalk
 
Zapnologica
Long time Member
Long time Member
Topic Author
Posts: 594
Joined: Fri Sep 25, 2009 8:15 pm
Location: South frica

Re: Dydns update on certain interface

Sun May 25, 2014 1:36 pm

I can't some how add a packet mark in the scripts and then route it out the correct interface? Or something to that effect?
 
Zapnologica
Long time Member
Long time Member
Topic Author
Posts: 594
Joined: Fri Sep 25, 2009 8:15 pm
Location: South frica

Re: Dydns update on certain interface

Mon May 26, 2014 7:23 pm

If not the way im doing it, there must be some type of way to do this?
 
efaden
Forum Guru
Forum Guru
Posts: 1708
Joined: Sat Mar 30, 2013 1:55 am
Location: New York, USA

Re: Dydns update on certain interface

Mon May 26, 2014 8:56 pm

If not the way im doing it, there must be some type of way to do this?
Personally I'd do it via a layer-7 filter with packet marks. But I haven't actually tried to do that.

-Eric
 
Zapnologica
Long time Member
Long time Member
Topic Author
Posts: 594
Joined: Fri Sep 25, 2009 8:15 pm
Location: South frica

Re: Dydns update on certain interface

Mon May 26, 2014 9:35 pm

Any ideas on how to possibly do this.

I need to achieve this, as I am routing my SIP trunks out of a different gateway, and they require a host name so that they can reverse connect.

So ie my one script needs to update the VoIP gateway, and the other script the normal internet gateway.
 
efaden
Forum Guru
Forum Guru
Posts: 1708
Joined: Sat Mar 30, 2013 1:55 am
Location: New York, USA

Re: Dydns update on certain interface

Tue May 27, 2014 3:49 am

Any ideas on how to possibly do this.

I need to achieve this, as I am routing my SIP trunks out of a different gateway, and they require a host name so that they can reverse connect.

So ie my one script needs to update the VoIP gateway, and the other script the normal internet gateway.
Not off hand... I'd have to play around with it for a while and don't have the time right now. Maybe someone else has done it?
 
jarda
Forum Guru
Forum Guru
Posts: 7756
Joined: Mon Oct 22, 2012 4:46 pm

Re: Dydns update on certain interface

Tue May 27, 2014 8:28 am

Maybe you can use two different addresses for fetching and route each thru the corresponding gateway. Then you will know both ip addresses. Or always change the routing before fetching. Then one address will be sufficient.
 
Zapnologica
Long time Member
Long time Member
Topic Author
Posts: 594
Joined: Fri Sep 25, 2009 8:15 pm
Location: South frica

Re: Dydns update on certain interface

Mon Jun 02, 2014 10:09 am

Maybe you can use two different addresses for fetching and route each thru the corresponding gateway. Then you will know both ip addresses. Or always change the routing before fetching. Then one address will be sufficient.

How would I use two different addresses?

Does dyndns have multiple IP addresses for their updater service?
 
jarda
Forum Guru
Forum Guru
Posts: 7756
Joined: Mon Oct 22, 2012 4:46 pm

Re: Dydns update on certain interface

Mon Jun 02, 2014 11:16 am

Actually I use such script for dnsExit service:

ros code

# Set needed variables
:local username "somename"
:local password "somepass"
:local hostname "domain.tld"

:global dyndnsForce
:global previousIP
#:global currentIP

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

# get the current IP address from the internet (in case of double-nat)
/tool fetch mode=http address="ip.dnsexit.com" src-path="/" dst-path="usb1/dnsexit.tmp" port=80 host=ip.dnsexit.com
:local result [/file get [/file find name=usb1/dnsexit.tmp] contents]

# parse the current IP result
:local resultLen [:len $result]
:local currentIP [:pick $result 0 ($resultLen-1)]
#:log info "UpdateDnsExit: currentIP = $currentIP"

# Remove the # on next line to force an update every single time - useful for debugging,
# but you could end up getting blacklisted by DnsExit!

#:set dyndnsForce true

# Determine if dyndns update is needed
# more dyndns updater request details on DnsExit.com 

:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
:set dyndnsForce false
:log info "UpdateDnsExit: Current IP $currentIP"
:log info "UpdateDnsExit: Previous IP $previousIP"
:set previousIP $currentIP
/tool fetch mode=http address="www.dnsexit.com" \
src-path="RemoteUpdate.sv?login=$username&password=$password&host=$hostname&myip=$currentIP" \
dst-path="usb1/dnsexit.txt" port=80 host=www.dnsexit.com
:local result [/file get usb1/dnsexit.txt contents]
#:log info "UpdateDnsExit: previousIP = $previousIP"
:log info ("DnsExit: DnsExit update needed")
:log info ("UpdateDnsExit: DnsExit Update Result: ".$result)
:log info ("DnsExit Update Result: ".$result)
} else={
:log info ("UpdateDnsExit: No DnsExit update needed")
}
For you it can be similar or maybe just almost the same.

There is not important from what address I am changing the dns record, it is important which IP I am giving that should be linked to my domain. As you maybe cannot be sure what ip is really your external ip (in case of 1:1 NAT of your ISP), it is smart to ask some service to tell you what is my ip (how it does see you). So therefore I am asking the ip.dnsexit.com which gives you back an text file with your real external IP. Then I put this IP into the dns record. If I had more wans with dynamic IPs, I just need to ask thru first wan then trhu second wan and so on. So my way would be to have for this the special routing rule that will cycle the wans between each request.

The procedure would be:
0) resolve ip.dnsexit.com
1) set the routing thru first wan
2) ask ip.dnsexit.com
3) parse the ip address, check if it changed and if so, make the dns update with "wan1.mydomain.tld"
4) set the routing thru second wan
5) ask ip.dnsexit.com
6) parse the ip address, check if it changed and if so, make the dns update with "wan2.mydomain.tld"
and so on...

As ip.dnsexit.com can also change its ip address, I would make resolve of it first to be able to set static route to it according to my needs (step 0 above).

Unfortunatelly it needs to write a file - I did not managed to get the ip from the response without saving a file to disk.

Do you understand?
 
Zapnologica
Long time Member
Long time Member
Topic Author
Posts: 594
Joined: Fri Sep 25, 2009 8:15 pm
Location: South frica

Re: Dydns update on certain interface

Mon Jun 02, 2014 12:11 pm

This is great.

Thank you so much,

Where do you change the routing? Or how do you decide your routing?

I cant see in the script which part does that?
 
jarda
Forum Guru
Forum Guru
Posts: 7756
Joined: Mon Oct 22, 2012 4:46 pm

Re: Dydns update on certain interface

Mon Jun 02, 2014 12:25 pm

It is not included as i do not need it. You can find routes in ip-route menu.
 
Zapnologica
Long time Member
Long time Member
Topic Author
Posts: 594
Joined: Fri Sep 25, 2009 8:15 pm
Location: South frica

Re: Dydns update on certain interface

Mon Jun 02, 2014 12:34 pm

Ok yes I can find my routes there,

But how do I determine / tell it which route to go out?

I need to give it a routing mark or something to that effect dont I?
 
jarda
Forum Guru
Forum Guru
Posts: 7756
Joined: Mon Oct 22, 2012 4:46 pm

Re: Dydns update on certain interface

Mon Jun 02, 2014 12:57 pm

No.
you just need to know what ip you want to go.

so you resolve ip.dnsexit.com to 67.214.175.69.

then you just add the route for this destination trhu first gateway. You can name it a then you can use "set" to change the destination or the gateway as you need by your script according to the name...

Who is online

Users browsing this forum: No registered users and 21 guests