script doesn't work with variable

The following script works great:
:global currentIPD;
:local pppoePtr [/ip address find interface=“pppoe-out1”];
:local newIPD [/ip address get $pppoePtr address];
:local natPtr [/ip firewall nat find comment=“pppoe-out2”];

:if ($newIPD != $currentIPD) do={
:log info “ip address $currentIPD changed to $newIPD”;
:set currentIPD $newIPD;
}

/ip firewall nat set $natPtr action=src-nat chain=srcnat
src-address=192.168.88.254/24 to-addresses=1.2.3.4



If I try to change the last command to

:global currentIPD;
:local pppoePtr [/ip address find interface=“pppoe-out1”];
:local newIPD [/ip address get $pppoePtr address];
:local natPtr [/ip firewall nat find comment=“pppoe-out2”];

:if ($newIPD != $currentIPD) do={
:log info “ip address $currentIPD changed to $newIPD”;
:set currentIPD $newIPD;
}

/ip firewall nat set $natPtr action=src-nat chain=srcnat
src-address=192.168.88.254/24 to-addresses=$currentIPD

The script “fail”

How can I set to-addresses parameter by a variable?

thanks

IP address that you get from /ip address config contains netmask.
In that dst nat rule netmask should not be added.

To make it work you have to strip off netmask part.

:local mcIPsrcNat [:pick $currentIPD 0 ([:len $currentIPD]-3)]

/ip firewall nat set $natPtr action=src-nat chain=srcnat
src-address=192.168.88.254/24 to-addresses=$mcIPsrcNat



YES!! thanks!