:local new-address
:local status
:local x
:set x 2
:for i from=1 to=$x do={
:set staus [/interface get [/interface find name=(“ppoe”)] runnig]
:if ($status=ture) do={
:set new-address [/ip address get [/ip address find dynamic=yes interface=(“ppoe”)] address]
:set new-address [:pick $new-address 0 ([:len $new-address] -3)]
/ip fir nat set [/ip fir nat find comment=$i] to-addresses=$new-address
}
}
tip: 1.2 this my dstnat rule’s name. ppoe is interface name. i was hope this script can Automatic mapping port . whats wrong? why does work? im very confuse…
Cleaned from bad syntax (you have more than those 2 mentioned above):
:local new-address
:local status
:local x
:set x 2
:for i from=1 to=$x do={
:set status [/interface get [/interface find name="ppoe"] running]
:if ($status=true) do={
:set new-address [/ip address get [/ip address find dynamic=yes interface="ppoe"] address]
:set new-address [:pick $new-address 0 ([:len $new-address] -3)]
/ip firewall nat set [/ip fir nat find comment=$i] to-addresses=$new-address
}
}
Notice: “[:pick $new-address 0 ([:len $new-address] -3)]” - how do you know the last number in ip address will have 3 digits?
interface name “ppoe” is questionable (did you type it right, the correct spelling is “pppoe”
Avoid for x from… at all costs - that causes only problems
DEAR DRAGONMEN
thx for you interset. im follow u guide check my script agagin. im preety sure about that my interface name is "ppoe " and i have no idea this line :set new-address [:pick $new-address 0 ([:len $new-address] -3)] whats mean. if i wanna make ros automatic mapping port. how should i do? can u write a script for me?
thx a loooooooooooooooot.
best regard.
this is bad, because in some cases you will get incorrect IP. To do this correctly you must search for slash ‘/’ from new-address then strip all characters starting from ‘/’ position. Now you will get correct ip.
/ip firewall nat set [/ip fir nat find comment=$i] to-addresses=$new-address this line is in for loop, it means that you have two identical NAT rules? Why?
Also I think that there is absolutely no need to write this script, instead of srcnat you can use masquerade, it will solve dynamic IP problem.