I'm trying to find a solution to only nat/masquerade traffic that goes to 0.0.0.0 via a specific gateway (ie: 192.168.0.1) and let traffic going to all the other IPs in 192.168.1.0/24 without masquerading.
I've tried to add in the firewall rule/advanced Settings/Restrict masquerading to destination = 192.168.0.1/32
but this rule, even if it is in wan_postrouting, only masquerade traffic to 192.168.0.1 and not traffic routed to 192.168.0.1.
Any idea to do this whithout leaving openwrt web interface (I may create a specific rule and by-pass the default one, but will it appear on the web interface ?)
Goto Advance of your WAN zone with masquerading enable. Note the '!' before the destination subnet - it means traffic going to that subnet will not masquerade.
Net map: my mistake, this is how my network looks like:
Wifi networks (multiple SSID) --> openWRT AP --> DMZ_LAN --> GW1
I have a couple of SSID, some needs minimum traffic modification, and always masquerade to GW1 (192.168.0.1)
Others can have their traffic going (ideally not masqueraded) to a second GW2 that can be up or down.
I have a apinger running and modifying the routing table on the fly. (This GW2 has more filtering things, but can be off from time to time).
you're idea is great and lean to deny masquerading on the DMZ_Lan (!192.168.0.0/24), I'll take it as last ressort option, but I would like to activate masquerading only on traffic routed to GW1 (192.168.0.1)
I tried to find tutorials about masquerading depending on gateway, I only found stuff with interfaces. I can't rely on vlan, and I don't think we can create local loop to do it.
GW1 is a cable operator basic box, my openwrt is connect via wifi
option network 'wwan'
the subnet between the two is 192.168.0/24
I've tried to create a second IP for the openWRT box and use it to route traffic, but the masquerading rules are based on real interfaces, so it just sees both the two IP as the same interface and makes no difference of rules with or without masquerading
I'm going to check if I can play with mark to mark the "need to be masqueraded traffic" versus the non masqueraded one.
You should probably disable masquerading on the downstream router entirely.
Just add static routes to the downstream router's subnet on each upstream router/gateway.