Community discussions

MikroTik App
 
sploit
just joined
Topic Author
Posts: 5
Joined: Sat Oct 19, 2013 8:53 pm

OVH.com Dynamic DNS Service update script

Fri Jul 28, 2017 8:49 pm

If anyone is interested, I made (read modified DynDNS script) an update script for the OVH.com Dynamic DNS Service. Feel free to use, copy, modify, re-publish.

https://github.com/acidsploit/mikrotik-routeros-scripts
:global ovhddnsuser "<OVH DynDNS USER>"
:global ovhddnspass "<OVH DynDNS PASS>"
:global theinterface "<INTERFACE THAT HAS YOUR PUBLIC IP>"
:global ovhddnshost "<OVHDynDNS HOSTNAME>"
:global ipddns [:resolve $ovhddnshost]
:global ipfresh [ /ip address get [/ip address find interface=$theinterface ] address ]
:if ([ :typeof $ipfresh ] = nil ) do={
   :log info ("OVHDynDNS: NO IP address on $theinterface")
} else={
   :for i from=( [:len $ipfresh] - 1) to=0 do={ 
      :if ( [:pick $ipfresh $i] = "/") do={ 
    :set ipfresh [:pick $ipfresh 0 $i]
      } 
}
 
:if ($ipddns != $ipfresh) do={
   :log info ("OVHDynDNS: $ovhddnshost DNS RECORD IP = $ipddns")
   :log info ("OVHDynDNS: $theinterface CURRENT IP = $ipfresh")
   :log info ("OVHDynDNS: UPDATING $ovhddnshost -> $ipfresh")
   :global str "nic/update?system=dyndns&hostname=$ovhddnshost&myip=$ipfresh&wildcard=OFF&backmx=NO&mx=NOCHG"

   # DEBUG fetch command
   #:log info ("OVHDynDNS: /tool fetch address=www.ovh.com host=www.ovh.com src-path=$str mode=https user=$ovhddnsuser password=$ovhddnspass dst-path=(\"/OVHDynDNS.$ovhddnshost\")")
   /tool fetch address=www.ovh.com host=www.ovh.com src-path=$str mode=https user=$ovhddnsuser password=$ovhddnspass dst-path=("/OVHDynDNS.".$ovhddnshost)
   :delay 1

   :global ovhresult [/file get "OVHDynDNS.$ovhddnshost" contents]
   :log info "OVHDynDNS: OVH response: $ovhresult"

   :global str [/file find name="OVHDynDNS.$ovhddnshost"]
   /file remove $str
   
   :if ($ovhresult = "good $ipfresh\n" ) do={
      :log info "OVHDynDNS: SUCCESS"
   } else={
       :log info "OVHDynDNS: FAILED"
   }

   :global ipddns $ipfresh
   :log info "OVHDynDNS: $ovhddnshost DNS RECORD = $ipfresh!"
    } else={
     :log info "OVHDynDNS: We good!"
    }
}
Maybe publish this on the wiki, it could be useful for future reference.

Cheers!
 
mniewiera
just joined
Posts: 7
Joined: Wed Dec 27, 2017 4:52 pm

Re: OVH.com Dynamic DNS Service update script

Sat Jan 06, 2018 3:52 pm

Thanks sploit for the script!
I just found out that OVH has this dynhost option and i thought it would be perfect to use with a mikrotik script.
I'll give it a try later.
Thanks again!
 
User avatar
sebastia
Forum Guru
Forum Guru
Posts: 1782
Joined: Tue Oct 12, 2010 3:23 am
Location: Antwerp, BE

Re: OVH.com Dynamic DNS Service update script

Sat Jan 06, 2018 10:07 pm

Some constructive criticism: all these :global could be changed to :local. There is no need to store "state" between runs.
 
mniewiera
just joined
Posts: 7
Joined: Wed Dec 27, 2017 4:52 pm

Re: OVH.com Dynamic DNS Service update script

Sat Jan 06, 2018 10:59 pm

Some constructive criticism: all these :global could be changed to :local. There is no need to store "state" between runs.
So i can just replace the :global with :local ?
I'm not very good at scripting and very new to mikrotik ;-)
 
User avatar
sebastia
Forum Guru
Forum Guru
Posts: 1782
Joined: Tue Oct 12, 2010 3:23 am
Location: Antwerp, BE

Re: OVH.com Dynamic DNS Service update script

Tue Jan 09, 2018 12:09 am

Correct, and you could clean up your environment (/system/scripts/environment) of these variables.
 
mniewiera
just joined
Posts: 7
Joined: Wed Dec 27, 2017 4:52 pm

Re: OVH.com Dynamic DNS Service update script

Sat Jan 20, 2018 9:25 am

Thanks!
This works very well.
I think in a further step i'm going to remove the "OVHDynDNS: We good!" message if the update was successful.
This is spamming my log/syslog server very much ;-)
 
Maxke
just joined
Posts: 9
Joined: Sun Jan 13, 2019 10:27 pm

Re: OVH.com Dynamic DNS Service update script

Sun Jan 13, 2019 10:29 pm

Hi,

I'm new here.
Can you tell me what to do if the router is behind een modem ?
So my router has no external ip adres.

Thanks
 
User avatar
kinx
just joined
Posts: 13
Joined: Mon Sep 04, 2017 9:16 pm
Location: 127.0.0.1
Contact:

Re: OVH.com Dynamic DNS Service update script

Wed Oct 30, 2019 4:10 pm

I had a custom domain at Dyn (DynDNS) which has now been taken over by Oracle. And I'm very disappointed they are ending custom dynamic domains as of next year in March.
I'm keeping a Dyn account for legacy old clients, but I'm moving all my other more recent customers that need Dynamic DNS to OVH DynHost.

Can someone modify this script so it fetches the external IP (not from the eth1 / wan interface), since the MikroTik eth1/wan interface doesn't always have an external IP...
I saw another 'DynDNS' script here first getting the external IP from an OpenDNS website. https://diagnostic.opendns.com/myip
But I could also make my own website instead of OpenDNS for example...

Found another ipv4 checker from Google. https://domains.google.com/checkip
 
sploit
just joined
Topic Author
Posts: 5
Joined: Sat Oct 19, 2013 8:53 pm

Re: OVH.com Dynamic DNS Service update script

Wed Nov 06, 2019 10:38 am

I had a custom domain at Dyn (DynDNS) which has now been taken over by Oracle. And I'm very disappointed they are ending custom dynamic domains as of next year in March.
I'm keeping a Dyn account for legacy old clients, but I'm moving all my other more recent customers that need Dynamic DNS to OVH DynHost.

Can someone modify this script so it fetches the external IP (not from the eth1 / wan interface), since the MikroTik eth1/wan interface doesn't always have an external IP...
I saw another 'DynDNS' script here first getting the external IP from an OpenDNS website. https://diagnostic.opendns.com/myip
But I could also make my own website instead of OpenDNS for example...

Found another ipv4 checker from Google. https://domains.google.com/checkip
Here is a nifty trick for nginx to make a simple checkip service:
location = / {                                         
        add_header Content-Type text/plain; return 200 $remote_addr;                                                   
    }

Then doing:
curl myip.mydomain.com

Will give you your public ip. I don't think it can be done any more simple.
 
dot02
Member Candidate
Member Candidate
Posts: 108
Joined: Tue Jun 15, 2021 1:23 am

Re: OVH.com Dynamic DNS Service update script

Fri Jun 03, 2022 2:27 pm

Hi,

the script works great as long as the IP address on the WAN really is a public IP. In my case for instance, I have a remote site router behind CG-NAT (LTE connection thanks to a MT LDF LTE6 kit), so the IP I grab is a NAT-ed 100.64.0.0/10, which is to be expected since this is the IP that the ISP allocates to my external WAN interface. Sadly this doesn't help me much if my dns name resolves to this NAT-ed address of course...

I tried modifying the script to grab the "read" public IP from public IP resolvers for instance v4.ident.me, so I replaced the line
:global ipfresh [ /ip address get [/ip address find interface=$theinterface ] address ]
by
:global ipfresh [ /ip address get [curl v4.ident.me] address ]

but I doesn't work without any specific fail in the logs...

Could you guys give me a hint of what I'm doing obviousely wrong?
You may have noticed that I'm very bad at scripting, so this may be a good exercice for practicing...

cheers
Denis
 
User avatar
gyto6
just joined
Posts: 7
Joined: Wed Jun 15, 2022 8:07 pm

Re: OVH.com Dynamic DNS Service update script

Wed Jun 15, 2022 8:16 pm

This script has stopped working for me. I'm lockerd on "UPDATING" status.

If I uncomment the debug log, that's all I got :
failure: closing connection: <301 Moved Permanently location="https://www.ovhcloud.com/fr/"> 198.27.92.1:443 (5)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: OVH.com Dynamic DNS Service update script

Wed Jun 15, 2022 8:36 pm

I read on script
www.ovh.com
not
www.ovhcloud.com/fr/

try to change ovh to ovhcloud on script, without put /fr/
 
User avatar
gyto6
just joined
Posts: 7
Joined: Wed Jun 15, 2022 8:07 pm

Re: OVH.com Dynamic DNS Service update script

Wed Jun 15, 2022 9:38 pm

I read on script
www.ovh.com
not
www.ovhcloud.com/fr/

try to change ovh to ovhcloud on script, without put /fr/
Well, this edit won't work. The OVH DynHost need to reach this address in fact

https://www.ovh.com/nic/update?system=d ... E&myip=$IP
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: OVH.com Dynamic DNS Service update script

Wed Jun 15, 2022 10:11 pm

But if this: <301 Moved Permanently location="https://www.ovhcloud.com/fr/">
something say to rb that the site is moved, and fetch do not follow redirect....
 
User avatar
gyto6
just joined
Posts: 7
Joined: Wed Jun 15, 2022 8:07 pm

Re: OVH.com Dynamic DNS Service update script

Wed Jun 15, 2022 10:40 pm

But if this: <301 Moved Permanently location="https://www.ovhcloud.com/fr/">
something say to rb that the site is moved, and fetch do not follow redirect....
Well, only the root is redirected actually. I dont understand why fetch is stopped. I might I've done a mistake with this DEBUG command, but I don't know why it did stop working. Does it still work for the others?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: OVH.com Dynamic DNS Service update script

Wed Jun 15, 2022 11:05 pm

I can't test the service I hope someone that use it try and reply
 
User avatar
gyto6
just joined
Posts: 7
Joined: Wed Jun 15, 2022 8:07 pm

Re: OVH.com Dynamic DNS Service update script

Wed Jun 15, 2022 11:38 pm

Well, I installed ddns-updater docker container on my server and succeded to update my A record... So it doesn't seems that OVH service's down.

Might it be a firewall filter that might interfer with it?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: OVH.com Dynamic DNS Service update script

Wed Jun 15, 2022 11:44 pm

Not, with that reply: <301 Moved Permanently location="https://www.ovhcloud.com/fr/">
can be only an error on script when recomposing the URL....
 
dot02
Member Candidate
Member Candidate
Posts: 108
Joined: Tue Jun 15, 2021 1:23 am

Re: OVH.com Dynamic DNS Service update script

Thu Jun 16, 2022 1:37 am

sorry guys, I didnt see there were replies.

Here is an updated version of the script that updates the real Public IP, even if your router is behind CGNAT, I tested it and it works. Comments are more than welcome if anyone sees anything that could be improved.
:local ovhddnsuser "<OVH_USERNAME>"
:local ovhddnspass "<OVH_PWD>"
:local theinterface "<INTERFACE_NAME>"
:local ovhddnshost "<OVH_DYNDNS_NAME>"
:local ipddns [:resolve $ovhddnshost]
:local ipfresh [:resolve myip.opendns.com server=208.67.222.222]
:if ([ :typeof $ipfresh ] = nil ) do={
   :log info ("OVHDynDNS: NO public IP address linked to $theinterface")
} else={
   :for i from=( [:len $ipfresh] - 1) to=0 do={ 
      :if ( [:pick $ipfresh $i] = "/") do={ 
    :set ipfresh [:pick $ipfresh 0 $i]
      } 
}
 
:if ($ipddns != $ipfresh) do={
   :log info ("OVHDynDNS: $ovhddnshost DNS RECORD IP = $ipddns")
   :log info ("OVHDynDNS: $theinterface CURRENT IP = $ipfresh")
   :log info ("OVHDynDNS: UPDATING $ovhddnshost -> $ipfresh")
   :local str "nic/update?system=dyndns&hostname=$ovhddnshost&myip=$ipfresh&wildcard=OFF&backmx=NO&mx=NOCHG"

   # DEBUG fetch command
   #:log info ("OVHDynDNS: /tool fetch address=www.ovh.com host=www.ovh.com src-path=$str mode=https user=$ovhddnsuser password=$ovhddnspass dst-path=(\"/OVHDynDNS.$ovhddnshost\")")
   /tool fetch address=www.ovh.com host=www.ovh.com src-path=$str mode=https user=$ovhddnsuser password=$ovhddnspass dst-path=("/OVHDynDNS.".$ovhddnshost)
   :delay 1

   :local ovhresult [/file get "OVHDynDNS.$ovhddnshost" contents]
   :log info "OVHDynDNS: OVH response: $ovhresult"

   :local str [/file find name="OVHDynDNS.$ovhddnshost"]
   /file remove $str
   
   :if ($ovhresult = "good $ipfresh\n" ) do={
      :log info "OVHDynDNS: SUCCESS"
   } else={
       :log info "OVHDynDNS: FAILED"
   }

   :local ipddns $ipfresh
   :log info "OVHDynDNS: $ovhddnshost DNS RECORD = $ipfresh!"
    } else={
     :log info "OVHDynDNS: We good!"
    }
}
 
User avatar
gyto6
just joined
Posts: 7
Joined: Wed Jun 15, 2022 8:07 pm

Re: OVH.com Dynamic DNS Service update script

Thu Jun 16, 2022 11:29 am

Didn't work for me. But I don't think your modified script is the problem.

One question probably simple, but is there some forbidden caracter inside a string or "" ? Don't see anyone in the doc, but, just in case..
 
dot02
Member Candidate
Member Candidate
Posts: 108
Joined: Tue Jun 15, 2021 1:23 am

Re: OVH.com Dynamic DNS Service update script

Thu Jun 16, 2022 12:17 pm

nope, no hidden chars. You only need to adapt the 1st few lines according to your OVH subscription. You onky need to be careful on the OVH format (which you get from your OVH dashboard).

Let's say your dynamic sub-domain is plop.mydomain.com, then it should look like this (be very careful with the last line, is must match this format!):
:local ovhddnsuser "ThisisMe"
:local ovhddnspass "ThisIsMySecurePWD"
:local theinterface "lte1"
:local ovhddnshost "mydomain.com-plop"
If you wish, you can create a DynDNS user for me on your OVH dashboard and I can try to update the record for you, just to test (in this case, PM me)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: OVH.com Dynamic DNS Service update script

Thu Jun 16, 2022 12:20 pm

if tested on terminal, ? must be replaced with \? (or simply with \3F for every case)

and why probably you get 301 than redrect to main page because "nic/updatesystem" page not exist...
(nic/update?system=)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: OVH.com Dynamic DNS Service update script

Thu Jun 16, 2022 12:37 pm

The scipt contains some errors and after is adapted for CGNAT some parts are superfluos.

added { and } at start and at the end to test it on terminal.
# original author: sploit on MikroTik forum
# modified for CGNAT from: dot02 on MikroTik forum

{

:local ovhddnsuser "<OVH_USERNAME>"
:local ovhddnspass "<OVH_PWD>"
:local ovhddnshost "<OVH_DYNDNS_NAME>"
:local ipddns      [:resolve $ovhddnshost]
:local ipfresh     [:resolve "myip.opendns.com" server=208.67.222.222]

:if ($ipddns != $ipfresh) do={
    :log info "OVHDynDNS: $ovhddnshost DNS RECORD IP  = $ipddns"
    :log info "OVHDynDNS: This RouterBOARD CURRENT IP = $ipfresh"
    :log info "OVHDynDNS: UPDATING $ovhddnshost -> $ipfresh"
    :local url "https://www.ovh.com/nic/update\3Fsystem=dyndns&hostname=$ovhddnshost&myip=$ipfresh&wildcard=OFF&backmx=NO&mx=NOCHG"

    /tool fetch url=$url user=$ovhddnsuser password=$ovhddnspass dst-path="OVHDynDNS.$ovhddnshost"
    :delay 1s

    :local ovhresult [/file get "OVHDynDNS.$ovhddnshost" contents]
    :log info "OVHDynDNS: OVH response: $ovhresult"

    /file remove [find where name="OVHDynDNS.$ovhddnshost"]
   
    :if ($ovhresult = "good $ipfresh\n" ) do={
        :log info "OVHDynDNS: SUCCESS"
        :log info "OVHDynDNS: $ovhddnshost DNS RECORD = $ipfresh!"
    } else={
        :log info "OVHDynDNS: FAILED"
    }

} else={
    :log info "OVHDynDNS: We good!"
}

}
 
dot02
Member Candidate
Member Candidate
Posts: 108
Joined: Tue Jun 15, 2021 1:23 am

Re: OVH.com Dynamic DNS Service update script

Thu Jun 16, 2022 2:54 pm

Thanks! Your version looks much cooler indeed! I'll update my router this evening!

One question though. If we look at these lines:
:local ovhresult [/file get "OVHDynDNS.$ovhddnshost" contents]
/file remove [find where name="OVHDynDNS.$ovhddnshost"]
is this file only stored in the memory or actually written to the flash card every single time? If so, the flash card might not like the constant writings for extended period of time...
 
User avatar
gyto6
just joined
Posts: 7
Joined: Wed Jun 15, 2022 8:07 pm

Re: OVH.com Dynamic DNS Service update script

Thu Jun 16, 2022 3:43 pm

The scipt contains some errors and after is adapted for CGNAT some parts are superfluos.

added { and } at start and at the end to test it on terminal.
# original author: sploit on MikroTik forum
# modified for CGNAT from: dot02 on MikroTik forum

{

:local ovhddnsuser "<OVH_USERNAME>"
:local ovhddnspass "<OVH_PWD>"
:local ovhddnshost "<OVH_DYNDNS_NAME>"
:local ipddns      [:resolve $ovhddnshost]
:local ipfresh     [:resolve "myip.opendns.com" server=208.67.222.222]

:if ($ipddns != $ipfresh) do={
    :log info "OVHDynDNS: $ovhddnshost DNS RECORD IP  = $ipddns"
    :log info "OVHDynDNS: This RouterBOARD CURRENT IP = $ipfresh"
    :log info "OVHDynDNS: UPDATING $ovhddnshost -> $ipfresh"
    :local url "https://www.ovh.com/nic/update\3Fsystem=dyndns&hostname=$ovhddnshost&myip=$ipfresh&wildcard=OFF&backmx=NO&mx=NOCHG"

    /tool fetch url=$url user=$ovhddnsuser password=$ovhddnspass dst-path="OVHDynDNS.$ovhddnshost"
    :delay 1s

    :local ovhresult [/file get "OVHDynDNS.$ovhddnshost" contents]
    :log info "OVHDynDNS: OVH response: $ovhresult"

    /file remove [find where name="OVHDynDNS.$ovhddnshost"]
   
    :if ($ovhresult = "good $ipfresh\n" ) do={
        :log info "OVHDynDNS: SUCCESS"
        :log info "OVHDynDNS: $ovhddnshost DNS RECORD = $ipfresh!"
    } else={
        :log info "OVHDynDNS: FAILED"
    }

} else={
    :log info "OVHDynDNS: We good!"
}

}
Thanks, I tested your edited code, and it seems to work. But as strange as it's, the previous :log info doesn't show up in the logs, only the final.
OVHDynDNS: We good!
if tested on terminal, ? must be replaced with \? (or simply with \3F for every case)

and why probably you get 301 than redrect to main page because "nic/updatesystem" page not exist...
(nic/update?system=)
I noticed it indeed, I didn't want to flood already more the thread, and I was not aware about the \? or \3F, good to know!
 
User avatar
gyto6
just joined
Posts: 7
Joined: Wed Jun 15, 2022 8:07 pm

Re: OVH.com Dynamic DNS Service update script

Sat Jun 18, 2022 12:46 pm

After some investigations, I think that the original script is still functionnal.

Got an illumination when the script detected the Domain Name with its private address. So each time, it asks to OVH to edit the Public IP address from the domain name. OVH answered with an "nochg" message (no change). And after a while, the script enters a perpetual failure due to OVH blocking the redundant modification queries with the already in place public IP address in its DNS Zone.

I've an DNS Server in my LAN, and I'd troubleshoots with IPv6 not advertising my inner DNS server address. I had to set it in IP->DNS to get it advertised, and I also changed my IPv4 to the inner one whereas the DHCPv4 was functionnal.

So you must set a public DNS IPv4 address in IP->DNS to get the script working and not get blocked by OVH.
 
dot02
Member Candidate
Member Candidate
Posts: 108
Joined: Tue Jun 15, 2021 1:23 am

Re: OVH.com Dynamic DNS Service update script

Sun Jun 19, 2022 10:05 pm

good to know! The script does update 100.64.0.0/10, though.

Who is online

Users browsing this forum: No registered users and 19 guests