I set up this DNAT rule to allow traffic to my mail server that sits behind my OpenWRT router. The rule forwards WAN traffic to the server as expected but it is not respecting the source address whitelist and is allowing traffic from any source IP.
Scenario: Traffic coming from whitelisted WAN IP to mail server Expected behavior: Traffic is forwarded to mail server Actual behavior: Traffic is forwarded to mail server
Scenario: Traffic coming from NON-whitelisted WAN IP to mail server Expected behavior: Traffic is dropped Actual behavior: Traffic is forwarded to mail server
The source condition needs to be in the redirect rule. Redirect rules are considered first.
The firewall works by going through the list of rules until one of them matches all its conditions. The action is then taken, and the firewall decision is complete. No rules further down the list will be evaluated for that packet.
@ mk24 Thanks for pitching in. I had tested this theory during my initial troubleshooting and found that I could only whitelist a single source IP / subnet which made me drop this option and focus on getting the traffic rule to work because that ones allows the use of multiple source IPs.
Also, my testing shows that the rules are indeed applied after the redirect. This was demonstrated by changing the rule "drop" and it did indeed block the traffic in the whitelist which means the traffic rules are processed after the redirection.
Just because LuCI red flags something that you attempt to set, doesn't mean it is wrong.
If it really doesn't work even on the CLI to have multiple sources in one rule, write multiple redirect rules, one for each allowed source IP or subnet.
I had done numerous grep searches for the whitelist IPs to see which files may contain the configuration but got no results. Any idea where the whitelist parameters are configured?
I never considered using multiple redirect rules, that's ingenious, thanks for the tip! Will turn to that as a last resort.
This also worked, thank you. Because it doesn't require multiple rules, it is cleaner. The changes however don't show in the UI so one must remember to always look in /etc/config/firewall for config.
"Forwarded" redirect traffic is automatically "allowed" and does not need a "traffic rule" (for example, traffic to a mail server as was the case here) ( @mk24 )
"Input" redirect traffic does also require a traffic rule to allow it to reach the port/service on the router (for example to OpenVPN if the router itself is the server)
If the UI says you can't do something it doesn't mean it's not doable
IP Sets can be used in "redirect" and "traffic" rules ( @vgaetera)
For UDP traffic, the source address filtering must be applied to both the "redirect" and the "traffic" rules in order for it to work. For TCP traffic, only the "redirect" rule needs to have the filter (ipset)
(Note: I am not sure if this is inherent to the protocol or to OpenWRT design but it was tested and confirmed to be the case on my router)