To do this you need to use the iproute2 programs.
Set up a table for each different gateway in /etc/iproute2/rt_tables
example rt_tables:
Code:
#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#
#1 inr.ruhep
10 gw1
11 gw2
Then you need to add a default route to each table:
ip route add default via 192.168.1.1 table gw1
ip route add default via 192.168.1.2 table gw2
Then you need to do routing rules like:
ip rule add from 192.168.1.11 table gw1
ip rule add from 192.168.1.12 table gw1
ip rule add from 192.168.1.13 table gw2
You should make sure to have an overall default route added via normal route command or interface setup. It's needed because the default route added to a table only apply to packets routed through that table.