I have a Linux box (running slackware with 2.4.26 kernel - iptables v1.2.10) with one LAN interface which is connected to two DSL routers (using two differnet ISPs).
Linux box ethernet interface on 10.0.1.1 (255.255.0.0)
RouterA on 10.0.1.254 (255.255.0.0), uses one ISP
RouterB on 10.0.1.252 (255.255.0.0), uses another ISP
Both of the DSL routers port forward 80/tcp and 22/tcp to 10.0.1.1.
10.0.1.1 normally has its default gateway set to RouterA (10.0.1.254), but when testing is required via RouterB (10.0.1.252) I need to manually change the routing table to use it as the default gateway - what I would idealy like is for the box itself to re-route traffic via the correct gateway/router itself, depending on where the request originated from.
The idea being if I then ssh to RouterA the data travels via RouterA (so the first ISP), but if I were to then ssh to RouterB the data travels via the second ISP.
Hopefully I've made some sense : ) I'm trying to think of the bests ways to accomplish this. I know iptables has some fancy options for re-writing data on-the-fly (particularly noticed the --gw flag and SNAT/DNAT), or thought that adding another NIC and have eth0 data use a default gateway of RouterA and eth1 use a default gateway of RouterB, but not sure how I would go about trying to set that up either :/
Does anyone have any suggestions or examples on how I could best achieve this?
All the best,
You are right that with DNAT/SNAT it is quite possible to route the data from a particular IP to a particular Gateway.
Also it can be done through IP Route utility freely distributed with linux.
what you do is create tables of gateway. basically routing tables and specify there that if source is this ip or destined traffic is of particular type it should follow a particular table.
hope i am not too confusing.