Tue Apr 09, 2024 6:55 pm
For port forwarding, you need a generic allow port forwarding rule in the forward chain.
add chain=forward action=accept comment="port forwarding" connection-nat-state=dstnat
Then you need a specific DST NAT rule, detailing the port, the server etc......
For a dynamic public IP the standard format is:
add chain=dstnat action=dst-nat in-interface=WANX dst-port=abcd protocol=tcp or udp to-address=IPofServer
For a static fixed public IP the standard format is:
add chain=dstnat action=dst-nat dst-address=StaticPublicIP dst-port=abcd protocol=tcp or udp to-address=IPofServer
Note1: To ports is only required for port translation (where the port hitting the router first is different from the port expected by the Server.
Note2: To provide a bit better security than an open port one can delineate specific Source address or Source address list to limit the access. By providing a source field, the addiitional benefit is that the port does not appear on scans, and instead of port visible and closed, it is simply not visible.
An additional problem occurs for the hairpin nat case. Here you want to direct users ON THE SAME SUBNET as the Server, to the server via the WANIP, aka typically an easier to remember dyndns URL. In both cases ( public, dynamic WANIP), the easiest method to deal with this may simply be move the users or Server to a different subnet ( vlans are cheap ). If unable to do so, then you need at a minimum a hairpin source nat rule.
add chain=srcnat action=masquerade src-address=subnet0fServer dst-address=subnetofServer
The static fixed WANIP needs no further changes to make this scenario work. However, the dynamic WANIP of in-interface=WAN ( or the default firewall rule handling dstnat from the WAN) is no longer viable. Hence why the forward FW above is provided - works in all cases. To mimic the static config, we simply create a firewall address list for the WAN, using the same dyndns URL provided to users, ( or use the IP cloud my netname as another option )
add address=mynetname.net list=MYWAN
Then simply modify the dst-nat rule accordingly.
add chain=dstnat action=dst-nat dst-address-list=MYWAN dst-port=abcd protocol=tcp or udp to-address=IPofServer