CHANGEIP script for V3.0

I edited and got the v2.9 script for Dynamic DNS running on V3.0.

Here is my script

:log info “DDNS: Begin”

:global ddnsuser “YOURUSERNAME”
:global ddnspass “YOURPASSWORD”
:global ddnshost “*1”
:global ddnsinterface “YOUREXACTINTERFACENAME”

:global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface] address ]

:if ([ :typeof ddnslastip ] = nil ) do={ :global ddnslastip 0.0.0.0/0 }

:if ([ :typeof $ddnsip ] = nil ) do={

:log info ("DDNS: No ip address present on " . $ddnsinterface . “, please check.”)

} else={

:if ($ddnsip != ddnslastip) do={

:log info “DDNS: Sending UPDATE!”
:log info [ /tool dns-update name=$ddnshost address=[:pick $ddnsip 0 [:find $ddnsip “/”] ] key-name=$ddnsuser key=$ddnspass ]
:global ddnslastip $ddnsip

} else={

:log info “DDNS: No change”

}

}

:log info “DDNS: End”



Hope it works for you

You can try this new and improved script that is compatible with 3.0:

http://wiki.mikrotik.com/wiki/Dynamic_DNS_Update_Script_for_ChangeIP.com

If there are problems with interface detection in this version please let me know. This should automatically figure out which interface the current default gateway is using and send us updates using that IP - in effect allowing failover for multiple WANs as well.

I tried the script you sugested.


When I run from the terminal it runs fine. But when I add it to scripts and setup a schedule to run the script, then it the log it just says "DDNS: Sending update" DDNS is the name of my script. But the update never goes through.

Also what I need is a bit diferent from what the script is.

I have 2 interface connected to the internet. The first one is a Public Fixed ip on ether5 on a RB150. That is used for browsing and email. It is also my default GW.

The second one is a ADSL 4MB line which is used for VoIP. As this is a capped account I only allow the VoIP traffic going through it. A have a route set to route the traffic through the ADSL Line. That words fine. My interface is called "ADSL". This is how I changed the script. Pleas see if I made any mistakes


Define User Variables

:global ddnsuser "ChangeIPUsername"
:global ddnspass "ChangeIPPassword"
:global ddnshost "*1" # Also tried the ddns url something.changeip.net

Define Global Variables

:global ddnsip
:global ddnslastip
:global ddnsinterface "ADSL" # I added this
: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]

}

#}** # I hassed this out

Grab the current IP address on that interface.

:global ddnsip [ /ip address get [/ip address find interface=@ddnsinterface ] address ]

Did we get an IP address to compare?

:if ([ :typeof $ddnsip ] = nil ) do={
:log info ("DDNS: No ip address present on " . $ddnsinterface . ", please check.")
} else={

:if ($ddnsip != $ddnslastip) do={

:log info "DDNS: Sending UPDATE!"
:log info [ :put [/tool dns-update name=$ddnshost address=[:pick $ddnsip 0 [:find $ddnsip "/"] ] key-name=$ddnsuser key=$ddnspass ] ]
:log info "DDNS: After UPDATE!" # It never gets to this.
:global ddnslastip $ddnsip

} else={
:log info "DDNS: No update required."
}

}




If I past this in the terminal, it runs fine?

URGENT Please

I was getting timeouts (on 2.9) and i found out that port 443 needs to be open for the update to work.
http://forum.mikrotik.com/t/changeip-errors/18622/1

On this line:

:global ddnsip [ /ip address get [/ip address find interface=@ddnsinterface ] address ]

Are you really using an @ sign instead of a $ sign ?

Also - reboot the router and manually run the script. Then go to terminal and type ‘:env print’ to see what the variables show. If there are some global variables missing maybe thats the problem. It seems like 3.0 does global variables a little differently… like they are only global sometimes : )

Sam

Typing error when I typed on the forum, I’m using a $

Ckecked Global Variables with :env print

All values are correct. But update not happening. When I run the script it give the “Sending Update” ion the log but nothing happens.

Then I copy the following line into the terminal

:log info [ :put [/tool dns-update name=$ddnshost address=[:pick $ddnsip 0 [:find $ddnsip “/”] ] key-name=$ddnsuser key=$ddnspass ] ]

And the Log replies " Updates Suceed" so according to that it shows me that it is picking up the variables but the dns-update don’t work from the script.

Anything else I can try?

I have no firewall rules set. thus port 443 should be opened.
I also added a rule to accept input traffic on port 443 just in case.

Any ideas?

:open_mouth:

Ok the problem on the V3.0 and V2.9 scripts not working was that I did not press enter after the last command. Thus not going to a new line in my scripts.

Does this make sence?

Ah, that makes sense. I will add some comments at the bottom of the script so that people don’t make that mistake again.

Thx,
Sam

I delete all “$”, “@” etc…

it acts almost well , but

and in all script, I see error here:

:global ddnsip [ /ip address get [/ip address find interface=ddnsinterface ] address ]

exacly here

:/ip address find interface=pppoe-out1 #for me =pppoe-out1 :slight_smile: #

error: ambiguous value of interface, more than one possible value matches input

I don’t understand this erros because I have one pppoe-out1

dont use : in front of that command.

Can you type this in terminal to see what is stored:

:env print

See what the ddnsinterface is showing.

Thx,
Sam

this working correctly for v3.2



:global ddnsuser "user for changeip"
:global ddnspass "pass for changeip"
:global ddnshost "host for changeip"
:global ddnsip
:global ddnslastip # first run --> :global ddnslastip 0 #
:if ([ :typeof $ddnslastip ] = nil ) do={ :global ddnslastip "0" }
:global ddnsinterface

:global ddnssystem ("mt-" . [/system package get system version] ) # unnecessary

:local int
: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]}}
:global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface ] address ]
:if ([ :typeof $ddnsip ] = nil ) do={
:log info ("DDNS: No ip address present on " . $ddnsinterface . ", please check.")
} else={
:if ($ddnsip != $ddnslastip) do={
:log info "DDNS: Sending UPDATE!"
:log info [ :put [/tool dns-update name=$ddnshost address=[:pick $ddnsip 0 [:find $ddnsip "/"] ] key-name=$ddnsuser key=$ddnspass ] ]
:global ddnslastip $ddnsip
} else={
:log info "DDNS: No update required."}}

It wouldn't work for me on version 3.3 so I changed line 5 & 6 to look like this:

:global ddnslastip

first run --> :global ddnslastip 0

instead of this:

:global ddnslastip # first run --> :global ddnslastip 0 #

Hello @all,

perhapes a stupid but short question:

Could I use this script together with DynDNS.com?


Kind Regards

Fabian

Hi Guys,

Still having problems getting this script going... i have been using this script. (Running 3.3)


:global ddnsuser "username"
:global ddnspass "password"
:global ddnshost "myhostname"

:global ddnsip
:global ddnslastip

first run --> :global ddnslastip 0

:if ([ :typeof $ddnslastip ] = nil ) do={ :global ddnslastip "0" }

:global ddnsinterface

:global ddnssystem ("mt-" . [/system package get system version] ) # unnecessary

:local int
: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]}}
:global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface ] address ]
:if ([ :typeof $ddnsip ] = nil ) do={
:log info ("DDNS: No ip address present on " . $ddnsinterface . ", please check.")
} else={
:if ($ddnsip != $ddnslastip) do={
:log info "DDNS: Sending UPDATE!"
:log info [ :put [/tool dns-update name=$ddnshost address=[:pick $ddnsip 0 [:find $ddnsip "/"] ] key-name=$ddnsuser key=$ddnspass ] ]
:global ddnslastip $ddnsip
} else={
:log info "DDNS: No update required."}}


Any help or ideas would be fantastic!
Cheers, Andy

Try running the script via the terminal. It should tell you what line of the script is causing the problem.

My configuration is

Internet-----ADSL Modem (running ppoe) ----- ether1 (10.0.0.1)- MT – RF AP --------- Station — MT — ether1 — PC

When I run this script changeip.com always get the same IP address of ether1 of the edge router (10.0.0.1) and not the one dynamically assigned by ppoe to the adsl modem.

Remove all of the “commented lines”… I have just tried the script that tasmanet posted with all of the comment lines removed and it is working fantastic.

It seems that “hashed-out” comment lines are not supported, or at least not in the correct format. Remove them and all is good!

Upgraded to 3.4 and the script is dead.

This command:
ip route find dst-address=0.0.0.0/0 active=yes

Gives this error:
invalid value of active, must be either yes or no

And as you can clearly see it is already set to “yes”

There are more than likely other errors as well.

Anyone else try 3.4 with this script yet?

Downgraded to 3.3, everything works great…no one has tried 3.4 yet?