ip cloud set ddns-enabled=yes
> ip cloud print ddns-enabled: yes public-address: 1.1.1.1 dns-name: 111111111111.sn.mynetname.net status: updated
:if ([:len [/system script job find script=SetIpSecDstAddrFromDns]]>1) do={ :error } :local DnsNameFromComment :local ResolvedIpFromComment :local ResolvedIpWithMaskFromComment :local IpDstAddr :local IpSaDstAddr :foreach IpSecPolicyCount in=[/ip ipsec policy find] do={ :set DnsNameFromComment [/ip ipsec policy get $IpSecPolicyCount comment] :if ($DnsNameFromComment!="") do={ :do { :set ResolvedIpFromComment ([:resolve $DnsNameFromComment]) :set ResolvedIpWithMaskFromComment ($ResolvedIpFromComment . "/32") :set IpDstAddr [/ip ipsec policy get $IpSecPolicyCount dst-address] :set IpSaDstAddr [/ip ipsec policy get $IpSecPolicyCount sa-dst-address] :if ($ResolvedIpWithMaskFromComment!=$IpDstAddr or $ResolvedIpFromComment!=$IpSaDstAddr) do={ :log warning ("[SetIpSecDstAddrFromDns] Change IpSec policy dst-addr from " . $IpSaDstAddr . " to " . $ResolvedIpFromComment) /ip ipsec policy set $IpSecPolicyCount dst-address=$ResolvedIpWithMaskFromComment sa-dst-address=$ResolvedIpFromComment } } on-error={ :set ResolvedIpFromComment "unknown" :log error ("[SetIpSecDstAddrFromDns] Cant resolve name " . $DnsNameFromComment) } } } :local IpPeerAddr :foreach IpSecPeerCount in=[/ip ipsec peer find] do={ :set DnsNameFromComment [/ip ipsec peer get $IpSecPeerCount comment] :if ($DnsNameFromComment!="") do={ :do { :set ResolvedIpFromComment [:resolve $DnsNameFromComment] :set ResolvedIpWithMaskFromComment ($ResolvedIpFromComment . "/32") :set IpPeerAddr [/ip ipsec peer get $IpSecPeerCount address] :if ($ResolvedIpWithMaskFromComment!=$IpPeerAddr) do={ :log warning ("[SetIpSecDstAddrFromDns] Change IpSec peer addr from " . $IpPeerAddr . " to " . $ResolvedIpFromComment) /ip ipsec peer set $IpSecPeerCount address=$ResolvedIpWithMaskFromComment } } on-error={ :set ResolvedIpFromComment "unknown" :log error ("[SetIpSecDstAddrFromDns] Cant resolve name " . $DnsNameFromComment) } } }
Source: https://habr.com/ru/post/252917/
All Articles