Skip to content

Instantly share code, notes, and snippets.

@adrianmo
Created January 18, 2016 12:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adrianmo/92e305123b521b7a4400 to your computer and use it in GitHub Desktop.
Save adrianmo/92e305123b521b7a4400 to your computer and use it in GitHub Desktop.
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