Multiple Default Routes, Source Based Routing
Assume you have a second ethernet interface with IP 10.55.99.100 with a /26 netmask (255.255.255.192) Because the IP ends in .100, this is part of the net segment with base address of 10.55.99.64. Let's say this 2nd interface is on eth1 and that your other interface is eth0.
The problem is that traffic coming to 10.55.99.100 on eth1 comes in via that interface, but if the traffic is outside of the network's visibility, it will use the default route on eth0 for the return. What you want is the idea of a default route for all traffic coming in on eth1... so that all traffic coming in on eth1, goes out eth1.
With iproute2, which is on most all Linux systems now, you have control to insert route rules into the default routing of the system. If you do "ip rule show" you will see the rules known on your system. Probably looks like:
0: from all lookup local 32766: from all lookup main 32767: from all lookup default
The first number establishes the priority for the rule. So, the local rules come first, then main, then default. The interesting information for a typical setup for eth0 (or whatever your normal network interface is) uses the "main" rule.
The command "ip route show table main" will show you things like the default route for your network. In fact, you sort of want to use this command instead of "netstat -rn" nowadays. You could simply say "ip route show", since that defaults to the "main" rule. The command "ip route show table all" will show all route tables.
Note: "ip route list" can be substituted for "ip route show"
To create a new rule table, edit the file /etc/iproute2/rt_tables and add a new table with priority. For example:
# # reserved values # 255 local 254 main 253 default 0 unspec # # local # #1 inr.ruhep 1 if2
That says we will have a rule with higher priority than the existing rules called if2.
Now, using the "ip" command we our "if2" rules:
ip rule add from 10.55.99.100/32 table if2 ip rule add to 10.55.99.100/32 table if2
And we can create the routing:
ip route add 10.55.99.64/26 dev eth1 src 10.55.99.100 table if2 ip route add default via 10.55.99.65 dev eth1 table if2
The "ip rule add" needs to happen before establishing the routes.