The need is to have the NAT rule allowing access to DMZ server.
Current implementation uses as selector: in-interface-list=WAN
Code: Select all
chain=dstnat action=dst-nat to-addresses=192.168.1.1 to-ports=10443 protocol=tcp [b]in-interface-list=WAN[/b] dst-port=443 log=no
log-prefix=""
After reading it seems like there's no easy way outside of going for scripting:
# https://wiki.mikrotik.com/wiki/Manual:S ... ve_changed
Code: Select all
:global currentIP;
:local newIP [/ip address get [find interface="ether1"] address];
:if ($newIP != $currentIP) do={
:put "ip address $currentIP changed to $newIP";
:set currentIP $newIP;
}
With that said, am not sure what's the best way to amend existing NAT rule.
Looking at syntax, the only selector for rule to be amended is rule#, which might change over the time as NAT rules would be updated and all of the sudden script could be modifying wrong rule
Code: Select all
/ip firewall nat edit number=....
Looking at it for the second time, probably better will be to use Address List, which would be updated by script instead of the rule - though same worry comes - how to select the right one, as the Number is not the best selector.
Regardless of the worry of amending the rule, feeling is that the action should be added straight after
Code: Select all
:set currentIP $newIP;