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!

  • I am pretty sure this is possible, even if by using policy based routing. But please wait for a few more answers since there may be an easier way to ensure this. Also check this out and see if it helps: unix.stackexchange.com/questions/171482/… – Pedro May 29 at 10:07
  • As Pedro told this will involve policy based routing. In some rare cases it involves also marking packets and iptables, but this should be avoided if possible. You should make a small ascii picture describing your layout between the two devices and the ubuntu's 3 interfaces if possible. Preferably stating even the IP addresses involved, restrictions ("device can't be reconfigured") etc. The problems are often in the small details here. – A.B May 29 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.