Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mikrotik script to update IPsec peer and policy when remote IP changes
##############Script Settings##################
:local RemoteNOIPHost "domainname.noip.com"
:local IPsecComment "myIPsec"
###############################################
:local TmpIP [/ip ipsec peer get [find comment="$IPsecComment"] address]
:local OldIP [:pick "$TmpIP" 0 ([:len $TmpIP] - 3)]
:local NewIP [:resolve $RemoteNOIPHost]
:if ($NewIP != $OldIP) do={
:log info "IPsec: Remote IP changed: Old: $OldIP, New: $NewIP"
/ip ipsec policy set [find comment="$IPsecComment"] sa-dst-address=$NewIP
:log info "IPsec: Policy updated with new remote IP"
/ip ipsec peer set [find comment="$IPsecComment"] address=$NewIP
:log info "IPsec: Peer updated with new remote IP"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment