LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (http://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Per Interface Gateway Routing (http://www.linuxquestions.org/questions/linux-networking-3/per-interface-gateway-routing-684186/)

Jelloir 11-17-2008 08:23 PM

Per Interface Gateway Routing
 
I have the following network configuration on Debian Etch:

Code:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
        address        192.168.84.20
        netmask        255.255.255.0
        gateway        192.168.84.254

auto eth1
iface eth1 inet static
        address        192.168.84.22
        netmask        255.255.255.0

I also have 2 Gateways on the network that go to the internet on 192.168.84.254 and 192.168.84.253.

I need to be able to force all data received/transmitted from eth1 (192.168.84.22) to go via 192.168.84.253 based on some port forwarding rules in the .253 router.

I tried adding "gateway 192.168.84.253" under eth1 but traffic still tries to go out via the default gateway .254. I also tried some "ip route" options but they do not work either.

I assumed that this woud be fairly simple to achieve but Googling has not provided me with a definitive answer.

estabroo 11-17-2008 09:21 PM

you need to set up some rt_tables and use iproute2

Take a look at http://lartc.org

Essentially you'll end up setting a default route for each table and then add a rule saying anything from 192.168.84.22 goes out the table that has 192.168.84.253 as its gateway

for example:
add tables to /etc/iproute2/rt_tables
20 out20
22 out22

add default routes
ip route add default via 192.168.84.254 table out20
ip route add default via 192.168.84.253 table out22

then add some rules
ip rule add from 192.168.84.20 table out20
ip rule add from 192.168.84.22 table out22

Now anything that originates form 192.168.84.22 will use 192.168.84.253 as its gateway

Jelloir 11-18-2008 12:12 AM

I copied exactly what you posted and it's working perfectly. Thanks!

Thanks for the link also. I came across it whilst searching but was getting a bit confused. You have cleared it up though.

Much appreciated.


All times are GMT -5. The time now is 06:46 AM.