Traduisez - Übersetzen - Traduzca - Traduza - Tradurre - Translate

Re: Adding gateways under Linux

John Paul Morrison (jmorriso@bogomips.com)
Sun, 8 Mar 1998 14:41:21 -0800 (PST)

>
> I have a linux box that needs to talk to 2 routers that are on different
> subnets that can only be accessed thru 2 different routers.
>
> [router1(1.2.3.4)]--------------[target router1(1.2.6.1)]
> /
> Linux Box
> 1.2.3.1
> \
> [router2(1.2.3.5)]--------------[target router2(1.2.7.1)]
>

This should be very straightforward.

First you should make sure that the local network is added properly, ie

ifconfig eth0 1.2.3.1 netmask 255.255.0.0
route add -net 1.2.0.0 netmask 255.255.0.0
(since you said it was "class B" - adjust the netmask to suit the locally
connected network)

Make sure each router is reachable, ie
ping 1.2.3.4
ping 1.2.3.5

(if you can't get this working, you have other problems, and
it wouldn't be from your routing table)

then you can do:

route add -net 1.2.6.0 gw 1.2.3.4 netmask 255.255.255.0
route add -net 1.2.7.0 gw 1.2.3.5 netmask 255.255.255.0

HOWEVER - I'm assuming your Linux box has only one ethernet card. From
the network numbers, it looks like one ethernet card, but the way
you've drawn it suggests two or more.

> I am trying to add 2 different routes to the routing table on the linux
> box by typing
> route add -net 1.2.6.0 gw 1.2.3.4 netmask 255.255.255.0
> route add -net 1.2.7.0 gw 1.2.3.5 netmask 255.255.255.0
> and getting errors that point to incorrect parameters. Ours is a class B
> address(1.2.0.0) and when I type
> route add -net 1.2.0.0 gw 1.2.3.4
> it seems to work fine but I can only add one gateway and I cant talk to
> the hosts on the subnets that can only be addressed through the 2nd
> router. Any ideas?

That route makes no sense. If your linux box is 1.2.3.1/255.255.0.0
then it's directly connected to 1.2.0.0/255.255.0.0
That's why your Linux box needs the route:

route add -net 1.2.0.0 netmask 255.255.0.0
or equivalently:
route add -net 1.2.0.0 gw 1.2.3.1 netmask 255.255.0.0

If this doesnt work, you should carefully check the output
of netstat -rn. And also make use of traceroute to see
what's happening.

BTW, if you're routers are properly configured, you should just
have to add the route 1.2.0.0/255.255.0.0 locally, and make
one of those two routers the default route, and the whole
thing should work. Your routing table would probably updated
by redirects telling you to use the other router.

> I am running Kernel V 2.0.30.
>
> Thanks
> Dilan
>
>

---------------------------------------------------------------------------
BogoMIPS Research Labs -- bogosity research & simulation -- VE7JPM --
jmorriso@bogomips.com ve7jpm@ve7jpm.ampr.org jmorriso@ve7ubc.ampr.org
---------------------------------------------------------------------------