I have a system with two interfaces. Both interfaces are connected to the internet. One of them is set as the default route; a side effect of this is that if a packet comes in on the non-default-route interface, the reply is sent back through the default route interface. Is there a way to use iptables (or something else) to track the connection and send the reply back through the interface it came from?
The above doesn't require any packet marking with ipfilter. It works because the outgoing (reply) packets will have the IP address that was originally used to connect to the 2nd interface as the source (from) address on the outgoing packet. |
|||||||||||||||||||||
|
|
The following commands create an alternate routing table via
The other half of the job is recognizing packets that must get the mark 1; then use
I'm not sure if that's enough, maybe another rule is needed on the incoming packets to tell the conntrack module to track them. |
|||||
|
|
I had issues with the locally generated packets with the solution suggested by Peter, I've found that the following corrects that:
Regards. |
|||||
|
|
I'm assuming you are running Linux and, further, that you are utilising a RedHat/CentOS-based distribution. Other Unix's and distributions will require similar steps - but the details will be different. Start by testing (note that this is very similar to @Peter's answer. I am assuming the following:
The commands are as follows:
The firewall is not involved in any way. Reply packets would always have been sent from the correct IP - but previously were being sent out via the wrong interface. Now these packets from the correct IP will be sent via the correct interface. Assuming the above worked, you can now make the rule and route changes permanent. This depends on what version of Unix you are using. As before, I'm assuming a RH/CentOS-based Linux distribution.
Test that the network change is permanent:
If that didn't work, on the later versions of RH/CentOS you also need to do go with one of two options:
Personally I prefer installing the rules package as it is the simpler more supported approach:
Another strong recommendation is to enable arp filtering as this prevents other related issues with dual network configurations. With RH/CentOS, add the following content to the /etc/sysctl.conf file:
|
|||
|
|
|
The syntax seems to have changed from
to
|
||||
|
|