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
There isn't going to be a difference to your routing. Whatever gateway comes first in your routing table is going to be used first. You can add the one that you want to use as the primary gateway in ifcfg-ethx of your first interface. Then you should see two entries in your routing table (along with the usual entries and information): Destination Gateway Genmask Interface 0.0.0.0 (The address of your first gateway) 0.0.0.0 eth0 0.0.0.0 (The address of your second gateway) 0.0.0.0 eth1 On 5/25/06, Tom Brown <tom at ng23.net> 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 >-- Thx Joshua Gimer -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.centos.org/pipermail/centos/attachments/20060525/9f254a27/attachment-0002.html>
On Thursday 25 May 2006 08:35, Joshua Gimer wrote:> There isn't going to be a difference to your routing. Whatever gateway > comes first in your routing table is going to be used first. You can add > the one that you want to use as the primary gateway in ifcfg-ethx of your > first interface. Then you should see two entries in your routing table > (along with the usual entries and information): > > Destination > Gateway Genmask > Interface > 0.0.0.0 (The address of your first gateway) > 0.0.0.0 eth0 > 0.0.0.0 (The address of your second gateway) > 0.0.0.0 > eth1 > > On 5/25/06, Tom Brown <tom at ng23.net> 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/centosHi, 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
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thu, May 25, 2006 at 11:51:14AM +0100, Tom Brown wrote:> 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?What are you trying to accomplish ? Load balancing ? Redundancy ? - -- Rodrigo Barbosa <rodrigob at suespammers.org> "Quid quid Latine dictum sit, altum viditur" "Be excellent to each other ..." - Bill & Ted (Wyld Stallyns) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFEdch5pdyWzQ5b5ckRAs2FAJwL9hb6r7/KAyh9P9P/W3BwPK6zggCfRvMU O/Zi20vrjX6CbGxA6i53jUQ=wUCx -----END PGP SIGNATURE-----
Vincent Knecht
2006-May-25 16:20 UTC
[CentOS] CentOS 4.x - Multiple gateways -- static routes
Le Jeudi 25 Mai 2006 12:51, Tom Brown a ?crit?:> 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? > > thanksHello, I think setting /etc/sysconfig/network-scripts/route-ethX files will help, see http://blog.subverted.net/?p=571
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/centosTry 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