Created
January 18, 2016 12:01
-
-
Save adrianmo/92e305123b521b7a4400 to your computer and use it in GitHub Desktop.
Mikrotik script to update IPsec peer and policy when remote IP changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##############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