Hi, I’m new to mikrotik. I’m starting to learn about it and every step I go, I am finding it more and more interesting. At the moment I’ve managed to create an ipsec vpn between two mikrotik’s. Right now my issue is how to make this work with dynamic ip addresses on both sides since I don’t find a way to put domains instead of ip addresses on the remote peer fields and on the action tab of the ipsec policy.
This has traditionally been done with scripts. It’s now integrated within RouterOS as of the latest 6.41rc releases. I believe it is still command line only still though (hasn’t been implemented in WinBox or WebFig).
Thank you. Do you have a sample script that you can share with me?
Also I’ve just installed 6.41rc23 an it allows me to specify dns on Peer on winbox. The issue still persist on specifying SA Src. Address and SA Dst. Address on the policy action. Any ideas?
I just need one more thing. I’ve created a schedule to run the script, but since it won’t compare actual address when updating, it ends up writing every time. This causes the vpn to go down until refresh, and that is not good. So, do you think you can help me make the script compare actual address and only change it when necessary?
I’ve ended up learning and writing my own script. I leave it here in case someone needs it.
# Set needed variables and resolve remotedomain and local domain
:global RemoteIp [:resolve remotedomain]
:global LocalIp [:resolve mydomain]
# get actual values of sa-dst-address and sa-src-address
:global actual [/ip ipsec policy get 1 sa-dst-address]
:global actuallocal [/ip ipsec policy get 1 sa-src-address]
#change policy if remote or local ip changed
:if ($RemoteIp !=$actual) do={
:log info "CheckRemoteIp: Update required $RemoteIp"
/ip ipsec policy set 1 sa-dst-address=$RemoteIp sa-src-address=$LocalIp} else= {:log info "No need to update"}
:log info "Remote update done, next local"
:if ($LocalIp !=$actuallocal) do={
:log info "CheckRemoteIp: Update required $LocalIp"
/ip ipsec policy set 1 sa-dst-address=$RemoteIp sa-src-address=$LocalIp} else= {:log info "No need to update"}
:log info "IPSEC update done"
I’ve used version 6.41rc23 that allows to specify the peer with dynamic address.
The code is the same for both routers, only thing that changes is to invert remotedomain/mydomain on the other router.
I’m a bit confused about this. How is the new IP “passed” to the other peer ? I understand that you check the local IP and if it change you modify the IPsec profiles - locally it is pretty trivial but how do you “signal” the remote peer to adapt ?`