The default gateway is only one; it is the default. You can have several interfaces each with a different gateway, but only one by default (your system cannot choose).
Imagine the following:
eth0 - IP: 192.168.0.10/24 Gateway: 192.168.0.1 eth1 - IP: 192.168.1.10/24
You must have at least 3 routes (usually automatic):
To go to some IP on 192.168.0.0, go thru eth0. To go to some IP on 192.168.1.0, to thru eth1. To go to anywhere else, go thru 192.168.0.1.
So, you see, you do not need more than one default gateway. What you may need is a gateway for a specific route. Imagine that you have a network 192.168.2.0 , access to which is possible only through the gateway in 192.168.1.1 . In the above configuration, your machine will try to use the default gateway 192.168.0.1 . You can use something like:
route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.1
This way you will have 2 gateways, but only 1 is used by default. This second one is used only for the 192.168.2.0 network.
source share