Linux (Ubuntu 12.04) two gateways one nic

gatewaylinuxlinux-networkingnetworkingUbuntu

I have Ubuntu 12.04 Server edition

Two gateways, both on 192.168.0. network, let's make them 192.168.0.1 and 192.168.0.2

I've read you should be able to add second gateway into /etc/network/interfaces, that it will build out all the routing automatically, but I get "duplicate option" error.

So if I have one default gateway, let's say 0.1, and a connection comes through from the 0.2 gateway, my understanding is that it still tries to respond through 0.1 gateway.

Can we change this behavior?

Best Answer

You need a way to distinguish which gateway the packet came in on in order to route the response out the correct gateway. This is usually done by having multiple IP addresses on the host, and using source policy routing to select the gateway based on the source address of the response packets. I'm assuming that the gateways are independent Internet connections, and that incoming connections are being DNATed (or port forwarded) by the gateways. You need to bind additional IP addresses to the machine and configure the gateways to DNAT to different addresses, so that the machine can tell the difference.