Re: Routing help....

Tony Nugent <[email protected]>
Newsgroups gmane.linux.redhat.release.enigma
Organization Linux Works
Message-ID <[email protected]>
On Thu Apr 17 2003 at 09:05, Tony Nugent wrote:

> On Thu Apr 17 2003 at 01:45, "System" wrote:
> 
> > Thankx a lot. Will try this out. Do I have to add any route using
> > /sbin/route command?

Just to add to what I said previously...

Static routes can be added to /etc/sysconfig/static-routes, iirc the
supplied network config tools add them to that file.  (It has been a
long while since I've used these tools - I tend to do many of these
things by hand with an editor).

This file is used by /etc/sysconfig/network-scripts/ifup-routes, and
the syntax for specifying the routes in the static-routes file
requires that it be can be used with /sbin/route (see below).

This is unfortunate, as /sbin/route cannot handle the configuration
of more complex routing situations such as multiple default or
static routes (also see below).

To overcome this, for a long time I have been using a slightly
hacked ifup-routes so that static-routes uses a syntax that can be
used with the /sbin/ip command instead.  I have found that the
resulting route syntax is much nicer, and it has certainly been very
useful in solving problems when trying to preserve through reboots
the configuration of more complex routing situations that
/sbin/route simply cannot handle:

=====8<---- cut from /etc/sysconfig/network-scripts/ifup-routes ---
DEVICE=$1
#note the trailing space in the grep gets rid of aliases
grep "^$DEVICE " /etc/sysconfig/static-routes | while read device args; do
#	/sbin/route add -$args $device
	/sbin/ip route replace $args
done
grep "^any " /etc/sysconfig/static-routes | while read ignore args ; do
#        /sbin/route add -$args
        /sbin/ip route replace $args
done
	/sbin/ip route replace $args
=====8<------------------------------------------------------------

What gets put into /etc/sysconfig/static-routes are the arguments
necessary for "ip route replace" to setup whatever routes are
required when any particular interface comes up.

For example, I have a network with all my boxes hanging off the same
hub, but on this box I have a crossover cable that directly connects
it to one of the others (also with two NICs, one active on the hub).

I have given both eth0 and eth1 exactly same IP address, and there
exists a single host route on that interface to the other box.
Doing this is perfectly "legal", but the netmask on eth1 is /32...

$ /sbin/ip -o a | grep inet
1: lo    inet 127.0.0.1/8 brd 127.255.255.255 scope host lo
2: eth0    inet 192.168.2.9/25 brd 192.168.2.127 scope global eth0
3: eth1    inet 192.168.2.9/32 scope global eth1

So in static-routes:

# add single-host route to .2.9 on eth1
eth1 192.168.2.9/32 dev eth1 src 192.168.2.7

There are actually two routes from .2.7 to .2.9, so I could get
really fancy and start doing things like forcing the utilisation of
_both_ physical links but at a weighted ratio of 10:1 ...

# add single-host routes to .2.9 on eth1 and eth0
eth0 192.168.2.9/32 dev eth0 src 192.168.2.7
eth1 192.168.2.9/32 dev eth1 src 192.168.2.7
# these will fail if both interfaces are not up (which is ok)
eth0 192.168.2.9/32 nexthop dev eth0 weight 1 nexthop dev eth1 weight 10
eth1 192.168.2.9/32 nexthop dev eth0 weight 1 nexthop dev eth1 weight 10

Of course, the .2.9 box would need to have a similar reciprical
configuration for this to work properly.

The end result looks like this:

$ /sbin/ip -o route $* | sed -e 's,\\[ 	], ,g'
                                      \\(space+tab here)
192.168.2.9  nexthop dev eth0 weight 1 nexthop dev eth1 weight 10
192.168.2.0/24 dev eth0  scope link  src 192.168.2.7 
127.0.0.0/8 dev lo  scope link 
default via 192.168.2.12 dev eth0  src 192.168.2.7 

That's cool, no?  All done with pure routing.

> > Tina...

Can you now see why /sbin/ip is such a powerful networking tool? :)

Cheers
Tony
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.