Iptables: Respond to gateway(b) while default is gateway(a)

Scenario: I have a gateway(A) to internet at, all my devices use this gateway, its a dhcp&dns server too.
Now I added another gateway(B), on wich have access to internet too.
On my computer I can change network profiles to use the first one or the second one with no problem, I just manually override gateway address taken from dhcp.
Sometimes I do port forwarding from the gateway(A) to some internal device and everything works well.
Now I need to do some port forwarding from the gateway(B) to some other device and I can do it, but because the devices have gateway(A) as default this responses goes to (A) and not to (B) as I want, if I change the default gateway on device to (B) the response is sent to (B) and can be reached from internet.

I found on the net something like I need but I cant figure out how to implement in OpenWrt:

This is my entry on firewall:

config redirect
	option target 'DNAT'
	option src 'wan'
	option dest 'lan'
	option proto 'tcp'
	option src_dport '88'
	option dest_ip ''
	option dest_port '80'
	option name 'Demo1'

Can somebody help me with a rule for firewall or explain me if this is possible with iptables on OpenWrt?


1 Like

Enable masquerading for the LAN firewall zone on the gateway B.

Thank you vgaetera, now it works as I want. Im getting a little old to understand this kind of things, heheee, still love to play with networking, OpenWrt and Linux.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.