Community discussions

MikroTik App
 
mayagamer
just joined
Topic Author
Posts: 10
Joined: Fri Oct 01, 2021 2:40 pm

Is it possible to make script to update domain record everytime when pppoe is connected?

Thu Nov 04, 2021 10:42 am

Sorry, English is not my first language...
Few days ago, I just bought heX S which is my first time to deal with routeros, and it works really great. However, it's so different from my old devices running mostly openwrt. Then I need to transit some of the works i did on openwrt to routeros.
A little of background. I have a domain pointing my home server. The ISP provides pppoe connection only to my house, and it reboots every 60 hours to change my public ip address. And I can't afford a static ip because it is too expansive. So my solution is to change domain record every time when pppoe is connected by a piece of bash script running on an openwrt router.
This script involves retrieving some secret code from domain provider's cloud api, create the request msg, doing some encryption (hmac-sha1 or hmac-sha256, base64) to the msg and sending it back to the cloud.
So my question is whether it is possible to do it on routeros? If it is, can you show some demonstration code? Thanks in advance!
 
holvoetn
Forum Guru
Forum Guru
Posts: 5481
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Is it possible to make script to update domain record everytime when pppoe is connected?

Thu Nov 04, 2021 12:43 pm

Good morning
RouterOS comes with a free DDNS service, maybe easier to use it instead of scripting.

Winbox - IP - Cloud - Enable DDNS. DNS name will become visible on the bottom of that dialog.

Alternative using terminal: /ip cloud set ddns-enabled=yes
Then print and you will see your DDNS name.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3297
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Is it possible to make script to update domain record everytime when pppoe is connected?

Thu Nov 04, 2021 1:17 pm

You can setup your DNS for your server to point to the cloud DNS as holvoetn describe.
No need for script :)
 
mayagamer
just joined
Topic Author
Posts: 10
Joined: Fri Oct 01, 2021 2:40 pm

Re: Is it possible to make script to update domain record everytime when pppoe is connected?

Thu Nov 04, 2021 1:56 pm

Thank you guys! I use Linux so WinBox doesn't work for me. I see DDNS in WebFig, but it seems unable to update whenever pppoe connection is established. Because the ip changes every time.
And to be honest, I still prefer my own domain name which is prettier :-P
 
holvoetn
Forum Guru
Forum Guru
Posts: 5481
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Is it possible to make script to update domain record everytime when pppoe is connected?

Thu Nov 04, 2021 3:06 pm

Thank you guys! I use Linux so WinBox doesn't work for me. I see DDNS in WebFig, but it seems unable to update whenever pppoe connection is established. Because the ip changes every time.
And to be honest, I still prefer my own domain name which is prettier :-P
If you're a Linux guy, use terminal :lol:

As long as your Mikrotik has a working internet connection, it will update.
Can't you point your pretty domain name to the Mikrotik DDNS ?

And again, if you're on Linux... can't you have that bash script running from another Linux box ?

Sounds like a rather complicated way (but hey, of it works, good for you).
What service is your current DDNS on ?
There should be a scripting solution existing already, depending on what solution you use.
 
mayagamer
just joined
Topic Author
Posts: 10
Joined: Fri Oct 01, 2021 2:40 pm

Re: Is it possible to make script to update domain record everytime when pppoe is connected?

Thu Nov 04, 2021 4:19 pm

As long as your Mikrotik has a working internet connection, it will update.
So in what manner will it update? Like periodically or when a new internet connection established?
Can't you point your pretty domain name to the Mikrotik DDNS ?
This is a good idea, thanks! I did not think this way. If DDNS works as I anticipated, I will make a cname record.
And again, if you're on Linux... can't you have that bash script running from another Linux box ?

Sounds like a rather complicated way (but hey, of it works, good for you).
This is what I planned if RouterOS doesn't support my old solution. Or I will try to use something like cloud worker script. But you know, depending on one other device is more fragile than only one device doing it.

Anyway, thanks for helping me.

Well, I think it's better divide the task into three small ones.
1. Retrieve some data from a remote api server.
2. Encrypt the msg
3. Send the msg

After doing some googling, maybe I can do 1 and 3 with tools/fetch? But I can't find a way to do 2.
 
tdw
Forum Guru
Forum Guru
Posts: 1847
Joined: Sat May 05, 2018 11:55 am

Re: Is it possible to make script to update domain record everytime when pppoe is connected?

Thu Nov 04, 2021 4:56 pm

As long as your Mikrotik has a working internet connection, it will update.
So in what manner will it update? Like periodically or when a new internet connection established?
The default is for the Mikrotik to update every 60 seconds, the TTL on the DNS record is also 60 seconds, see https://wiki.mikrotik.com/wiki/Manual:IP/Cloud#DDNS so worst case it would be one minute before the resolved address matches the actual address.
 
mayagamer
just joined
Topic Author
Posts: 10
Joined: Fri Oct 01, 2021 2:40 pm

Re: Is it possible to make script to update domain record everytime when pppoe is connected?

Fri Nov 05, 2021 3:27 am

That's great! 60s is not a problem as the server only serves my family. Thank you guys!
But what will happen when there are 2 wan connections(both pppoe, probably with load balance) plugged in the device? The wiki article says the submitted ip may not be the one expected. Then how would it decide which one? And will it stick to one of them all the time or pick anyone alternatively? Can I set the one I prefer?
 
holvoetn
Forum Guru
Forum Guru
Posts: 5481
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Is it possible to make script to update domain record everytime when pppoe is connected?

Fri Nov 05, 2021 7:49 am

Theoretically
Firewall rule to drop the request going over the "wrong" interface.
Then it will never be received by Ddns service, and then it can not be changed the wrong way.
 
mayagamer
just joined
Topic Author
Posts: 10
Joined: Fri Oct 01, 2021 2:40 pm

Re: Is it possible to make script to update domain record everytime when pppoe is connected?

Sat Nov 06, 2021 5:01 pm

Sorry, I don't understand. As I know, the msg updating the ip address to DDNS server doesn't pick which interface to go through, because the information is in the msg body, not the header. The firewall doesn't check the body, only check the header. I could be wrong.

Who is online

Users browsing this forum: No registered users and 20 guests