Configure Two Gateways with Different IPs – Linux, iptables

gatewayiptableslinuxrouting

I want to route packets coming in on eth0 back over eth0 and the ones coming in to eth1 back over eth1. I don't care which gateway is used for outgoing connections.

If i just enter two gateways in /etc/network/interfaces then the kernel routes packets out on both interfaces.

I remember it has something to do with routing tables but I don't know how to do it/where can I read more about it.

Best Answer

What you want to achieve is multi-homing, not bonding or load-balancing.

To do this you'll need to implement what is known as "policy" or "source based" routing.

Which you can do in Linux by using the iproute2 package.

There is a good article that explains how to, here.