LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (http://www.linuxquestions.org/questions/linux-networking-3/)
-   -   how are multiple default gateways handled? (http://www.linuxquestions.org/questions/linux-networking-3/how-are-multiple-default-gateways-handled-329203/)

eantoranz 06-01-2005 10:25 AM

how are multiple default gateways handled?
 
I will set up a multipath route in a box that has three Internet Connections, so hat the load is balanced. eth1 is 1536 kbps, eth2 is 1536 kbps and eth3 is 768 kbps

When the interfaces go on-line, they will use dhcp to configure themselves.

That will create three default gws in the routing table.

If I add another multipath route using the three devices as their nexthops, will it be treated as THE prefered default gw?

Say something like:
Code:

ip route add default nexthop dev eth1 weight 2 nexthop dev eth2 weight 2 nexthop dev eth3 weight 1

michaelsanford 06-01-2005 10:41 AM

Since routes are cached what is likely to happen is that contacting a certain domain will go out eth1, then another domain out eth2 and so on.

After the routing cache expires (not sure how long that takes...a few minutes I think) it can start all over again.

eantoranz 06-01-2005 12:15 PM

I've been thinking about it. I think the command I posted will not work... not even if it's taken as the default route.

That's because packets will be sent out throw a given device... but won't be sent to the gateway. In other words, I have to include the GWs addresses in the commmand (nexthop via x dev y). Do you agree?

michaelsanford 06-01-2005 01:11 PM

Here's how we do it:

Code:

eth0 = 192.168.1.200 (Sprint)
eth2 = 192.168.0.200 (Telus)

In /etc/iproute2/rt_tables, add:
1 Sprint
2 Telus

ip route add 192.168.1.0/24 dev eth0 src 192.168.1.200 table Sprint
ip route add default via 192.168.1.1 table Sprint
ip route add 192.168.0.0/24 dev eth2 src 192.168.0.200 table Telus
ip route add default via 192.168.0.1 table Telus

ip route show table Telus
ip route show table Sprint

ip rule add from 192.168.1.200 table Sprint
ip rule add from 192.168.0.200 table Telus

ip route add default scope global nexthop via 192.168.1.1 dev eth0 weight 1 \
nexthop via 192.168.0.1 dev eth2 weight 1

[root@wifi root]# ip route
192.168.1.0/24 dev eth0  scope link
192.168.0.0/24 dev eth2  proto kernel  scope link  src 192.168.0.200
127.0.0.0/8 dev lo  scope link
default
        nexthop via 192.168.1.1  dev eth0 weight 1
        nexthop via 192.168.0.1  dev eth2 weight 1
       
[root@wifi root]# route
Kernel IP routing table
Destination    Gateway        Genmask        Flags Metric Ref    Use Iface
192.168.1.0    *              255.255.255.0  U    0      0        0 eth0
192.168.0.0    *              255.255.255.0  U    0      0        0 eth2
127.0.0.0      *              255.0.0.0      U    0      0        0 lo
default        192.168.1.1    0.0.0.0        UG    0      0        0 eth0

[root@wifi root]# ip rule
0:      from all lookup local
32764:  from 192.168.0.200 lookup Telus
32765:  from 192.168.1.200 lookup Sprint
32766:  from all lookup main
32767:  from all lookup default

[root@wifi root]# traceroute -m 5 google.ca
traceroute: Warning: google.ca has multiple addresses; using 216.239.57.104
traceroute to google.ca (216.239.57.104), 5 hops max, 38 byte packets
 1  674895464.globetrotter.net (207.134.5.97)  1.642 ms  1.379 ms  1.363 ms
 2  207.134.34.201 (207.134.34.201)  18.712 ms  18.588 ms  16.905 ms
 3  142.169.173.131 (142.169.173.131)  19.910 ms  17.179 ms  17.939 ms
 4  mtrlpqfbgr00.bb.telus.com (154.11.7.5)  103.860 ms  122.291 ms  104.239 ms
    MPLS Label=202 CoS=3 TTL=1 S=0
 5  MTRLPQFBBR00.bb.telus.com (154.11.11.241)  105.419 ms  110.047 ms  102.544 ms
    MPLS Label=297 CoS=3 TTL=1 S=0

[root@wifi root]# traceroute -m 5 wificountry.ca
traceroute to wificountry.ca (206.45.119.128), 5 hops max, 38 byte packets
 1  6bdfug980..dedicated.sprintdsl.ca (149.99.14.185)  2.182 ms  1.780 ms  2.135 ms
 2  mtl149-99-189-69.dedicated.sprintdsl.ca (149.99.189.69)  14.238 ms  9.683 ms  10.541 ms
 3  g8-0-3-S1.bb1.mtl1.sprint-canada.net (207.107.254.1)  9.241 ms  12.278 ms g8-0-4-S1.bb1.mtl1.sprint-canada.net (207.107.254.65)  13.762 ms
 4  g7-0-S1.bb2.mtl1.sprint-canada.net (204.50.128.110)  13.472 ms  11.159 ms  8.969 ms
 5  as15290gw.mtl1.sprint-canada.net (209.5.21.18)  10.347 ms  13.975 ms  18.451 ms


eantoranz 06-01-2005 01:25 PM

I see, I see.

Three things:
1st: Good you got it working... I hope to say the same in a short time. :)
2nd: I tried to follow those instructions yesterday, but didn't get it working. I later realized it was because the kernel I was using (knoppix's, because we were just testing) didn't have multipath support (I later tried with mdk, which did have it... and was succesful at trying a single default route with two nexthops). What distribution are you using?
3rd: There's another level of difficulty for my problem. You got static routes.... and that's cool. But I depend on addresses provided by dhcp.... therefore I guess I'll just have to make scripts to handle setting the addresses of the nexthop's via and so on whenever there's a change in the addresses.

Let's see what I come up with.

eantoranz 06-01-2005 01:37 PM

I have a very simple question. Why are two tables needed? Can't it be done with a single one?

eantoranz 06-01-2005 01:39 PM

No, It can't each table has a different default gw.

eantoranz 06-01-2005 01:40 PM

But then why create separate tables... if the last command would do the whole thing?

I think you can simply say:
Code:

ip route add default scope global nexthop via 192.168.1.1 dev eth0 weight 1 \
nexthop via 192.168.0.1 dev eth2 weight 1

What is the catch? I bet there's one. :scratch:

michaelsanford 06-01-2005 02:03 PM

I just wrote an Answer on this in the Networking section, it should appear shortly (I assume it's gotta get approved by a mod like an HCL Review, right...if not I just lost it :P )

eantoranz 06-01-2005 02:09 PM

huh?:scratch:


All times are GMT -5. The time now is 08:54 AM.