Apparently the problem is that by default, you can only have one default gateway on a system. The case described would lead to asynchronous routing.
The iproute2 program, which is included in all current Linux distributions and already installed even, as a rule, can be used for the solution of this problem. Normally, a Linux system only has one routing table, in which only one default gateway can make entries. With iproute2, you have the ability to setup an additional routing table, for one thing, and allow this table to be used by the system based on rules, for another.
We will assume that we have two interfaces: eth0 and eth1. The two networks that should be used are 192.168.0.0/24 and 10.10.0.0/24, whereby the first IP address in each respective network should be the gateway. The initial configuration would appear as follows. /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
iface lo inet loopback
# The primary network interface
iface eth0 inet static
# The secondary network interface
iface eth1 inet static
Adding a Second Routing Table
To add a new routing table, the file, /etc/iproute2/rt_tables must be edited. We will call the routing table “rt2” and set its preference to 1. The named file should then appear as follows.
# reserved values
Configuring the New Routing Table
From this point, four commands are needed to achieve our goal. First, the new routing table needs to be populated, which is done using the following command.
ip route add 10.10.0.0/24 dev eth1 src 10.10.0.10 table rt2
ip route add default via 10.10.0.1 dev eth1 table rt2
The first command says that the network, 10.10.0.0/24, can be reached through the eth1 interface. The second command sets the default gateway.
So that the system knows when to use our new routing table, two rules must be configured.
ip rule add from 10.10.0.10/32 table rt2
ip rule add to 10.10.0.10/32 table rt2
These rules say that both traffic from the IP address, 10.10.0.10, as well as traffic directed to or through this IP address, should use the rt2 routing table.