[CentOS] CentOS 4.x - Multiple gateways

Fri May 26 12:39:15 UTC 2006
Charles Lacroix <clacroix at cegep-ste-foy.qc.ca>

On Friday 26 May 2006 08:30, Joshua Gimer wrote:
> Hi,
>
> I've done some work on this a few month ago at my other job, and basically
> the solution lies in iproute2 commands.
>
> First you need to create a rule and assign that traffic to a different
> table than the main table. Then you can easily add a default route to that
> new table.
>
> so it would look like this
>
> ip rule add from 192.168.1.0/24 table X
>
> check /etc/iproute2/rt_tables if you want to make aliases like eth1 eth2
> eth3
> it will get easier if you automate this thing :)
>
> After that you set a default route to this new table.
>
> ip route add default via 1.2.3.4 table X
>
>
> Once you have this done and working it's a matter of getting your
> dhclient of pppoe to do this for you as soon as ip changes.
>
> for pppoe create a /etc/ppp/ip-up.local script.
> for dhclient stuff you need to look in /sbin/dhclient-script script to find
> out how it will execute what's in /etc/dhclient-enter-hooks
> or /etc/dhclient-exit-hooks
>
> It's quite useful and for me it did turn out to work nicely. I just had to
> create some sort of master script that would take decisions on what's going
> on with my gateways :) It was pretty fun to work on that. I hope this helps
> you out.
>
> Later,
> Charles
>
> On 5/26/06, Feizhou <feizhou at graffiti.net> wrote:
> > Tom Brown wrote:
> > > Hi
> > >
> > > On a multihomed box how can i set different gateways for each NIC?
> > > Setting them in the ifcfg-ethx does not seem to make any difference to
> > > the routing?
> > >
> > > thanks
> > > _______________________________________________
> > > CentOS mailing list
> > > CentOS at centos.org
> > > http://lists.centos.org/mailman/listinfo/centos
> >
> > Try creating routing tables per NIC, populating those tables and
> > creating ip rules to lookup the respective table. This means you need to
> > identify which NIC the packets belong to. You can try adding rules to
> > the mangle PREROUTING chain of netfilter to mark the packets based on
> > their source ip. Then the ip rules can instruct the kernel to lookup the
> > proper routing table depending on the firewall mark.
> >
> > man ip, man iptables, http://linux-ip.net/html/routing-tables.html and
> > http://linux-ip.net/html/tools-ip-route.html
> >
> > _______________________________________________
> > CentOS mailing list
> > CentOS at centos.org
> > http://lists.centos.org/mailman/listinfo/centos

Just a tiny weebit of iproute2 will do the job, if you have static ip's it's 
just a matter of adding 4 lines to rc.local just like i explained on my other 
post.

ip rule ..
ip route ..
 
;)