I have an Ubuntu 18.04 acting as router with 3 interfaces. Two of them end up in the same device (they are used as dual path since depending on the situation one of the paths can be down or viceversa). The other interface is the local network where there is other device (lets call it device2) that comunicates with the previous one (device1).
Assuming that device1 is who starts communication always, I want to route packets coming from device2 (the answer to those sent by device1) through the same interface as incoming packets from device1.
I have thought about using iptables and mangle, but I don't know how to do it dinamically depending on the actual situation of the networks connected to each incoming interfaces.
Thanks in advance!