IP-Update with MikroTik Router

Hello Forum!
I would like to have the IPs updated automatically with my MikroTik router.
Does anyone here already have a script to make this happen?
According to the API I have to call the following page:
https://update.dedyn.io/update?username=MYDOMAIN.dedyn.io&password=PASSWORD&myipv4=1.2.3.4&myipv6=fd08::1234

But here I have to replace the IPv4 and IPv6 with the current address of the interface.
I have a PPPoE connection, through which I get an IPv4 and a prefix (/56) of which I get an IPv6 address.
Currently I still have no plan how to determine the IPs directly on the router for the query :frowning:

In the end, I need to be able to call it something like this:
/tool fetch url="https://update.dedyn.io/update?username=MYDOMAIN.dedyn.io&password=PASSWORD&myipv4=$MyIpV4&myipv6=$MyIpV6" mode=https

Hi Hoerli!

I do not have any experience with MicroTik devices in particular.

However if they use a *NIX OS then you could probably extract current public IPs from ifconfig output or from a similar command.

You could also use wget, curl, etc. to access https://checkipv4.dedyn.io/ and https://checkipv6.dedyn.io/ which would echo back the IPv4/IPv6 address the request came from.

Either way, for IPv6 the result may not be very useful unless you want to access the router itself. As you stated your provider allocates a /56 subnet to your router. Presumably your LAN clients will use SLAAC to allocate their public IPv6 addresses from this subnet. In a normal setup each client has their own public IPv6 address(es). (NATv6 is very uncommon and unnecessary in most cases.)

Thus the IPv6 address of your router will not help when trying to access a service on a client behind the router. There are more issues when trying to run a public service on a dynamic IPv6 address. Suffice to say: it can be done, but…

BTW: Many providers will actually issue a /64 prefix to the router in addition to a /56 prefix for clients behind the router. Your case may be different though.

HTH
fiwswe

Yes that with SLAAC is known.
In fact, I want to first transmit the IPv6 of the router so that I can establish a VPN tunnel via domain.
For internal services I then use ULA addresses and an internal DNS server.

I managed to craft an ugly script.
Unfortunately it just puts data on memory, which will be deleted at the end, I would have preferred something completely in RAM.
But at least it works … :slight_smile:

:log info GO
/tool fetch url="https://checkipv4.dedyn.io/" mode=https src-path="/" dst-path="/deSEC-IPv4.txt"
:delay 1
:local PubIpv4 [/file get deSEC-IPv4.txt contents]

/tool fetch url="https://checkipv6.dedyn.io/" mode=https src-path="/" dst-path="/deSEC-IPv6.txt"
:delay 1
:local PubIpv6 [/file get deSEC-IPv6.txt contents]
:delay 1

/tool fetch url="https://update.dedyn.io/update?username=MYDOMAIN.dedyn.io&password=PASSOWRD&myipv4=$PubIpv4&myipv6=$PubIpv6" mode=https src-path="/" dst-path="/deSEC-Update.txt"
:delay 10

/file remove deSEC-IPv4.txt
/file remove deSEC-IPv6.txt
/file remove deSEC-Update.txt

:log info DONE

Here’s a way to save writing to flash (it’s a bit rough but it works for me)

:local domain "your domain";
:local token "your token";

log info "Starting IP update"

:local ipv4 ([/tool fetch url="https://checkipv4.dedyn.io/" as-value output=user]->"data");
log info "Detected IPv4 address $ipv4"

#:local ipv6 ([/tool fetch url="https://checkipv6.dedyn.io/" as-value output=user]->"data");
#log info "Detected IPv6 address $ipv6"

:local result [/tool fetch user="$domain" password="$token" url="https://update.dedyn.io/update?myipv4=$ipv4" output=user as-value]
:if ($result->"status" = "finished") do={
   log info "IP Updated successfully"
} else={
   log error "Error during IP Updat"
}

This script works great.
Any way to enhance it so it will only update on IP change?

I found a script that does just that, but for DuckDNS. I’ve adapted it for deSEC, you can find it here:

Note: click the ‘master’ button and change it to deSEC for the correct instructions.

Note 2: My public IP hasn’t changed yet since I wrote the script and I can’t force a change, so I’m not 100% sure that it actually works. If you encounter problems, feel free to open an issue on the repository and I’ll look into it when I have the time.