-
-
Save iDanielLaw/9df5a40adca6aa4482f51987df3ebdd3 to your computer and use it in GitHub Desktop.
Mikrotik script to update IPsec peer and policy when remote IP changes
This file contains hidden or 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