Linux routing help needed

if i run ./local 196.209.102.x

where local is

case $1 in
196.*)
#route local
for i in `cat ../localroutes.dat`; do
echo ``route add -net `echo $i | sed s/\,/\ netmask\ /g` gw $1 `` ;
`route add -net `echo $i | sed s/\,/\ netmask\ /g` gw $1 ` ;
done

;;

165.*)
#international
route add default gw $1

;;
esac


it tell me

Usage: inet_route [-vF] del {-host|-net} Target[/prefix] [gw Gw] [metric M] [[dev] If]
inet_route [-vF] add {-host|-net} Target[/prefix] [gw Gw] [metric M]
[netmask N] [mss Mss] [window W] [irtt I]
[mod] [dyn] [reinstate] [[dev] If]
inet_route [-vF] add {-host|-net} Target[/prefix] [metric M] reject
inet_route [-FC] flush NOT supported
./local: line 1: gw: command not found


if i remove gw in "\ /g` gw $1 ``" it give me

Usage: inet_route [-vF] del {-host|-net} Target[/prefix] [gw Gw] [metric M] [[dev] If]
inet_route [-vF] add {-host|-net} Target[/prefix] [gw Gw] [metric M]
[netmask N] [mss Mss] [window W] [irtt I]
[mod] [dyn] [reinstate] [[dev] If]
inet_route [-vF] add {-host|-net} Target[/prefix] [metric M] reject
inet_route [-FC] flush NOT supported
./local: line 1: 196.209.102.x: command not found

thanx conrad
 
Try this:

Code:
case $1 in
196.*)
#route local
for i in `cat ../localroutes.dat`; do
echo ``route add -net `echo $i | sed s/\,/\ netmask\ /g` gw $1 `` ;
``route add -net `echo $i | sed s/\,/\ netmask\ /g` gw $1 `` ;
done

;;

165.*)
#international
route add default gw $1

;;
esac


edit: You could stick that in your /etc/ppp/ip-up script just by replacing $1 with $5, and putting in the full path to localroutes.dat. I'd take out the echo line though.
 
Last edited:
that worked

all i have to do is figure out how to run script when i pon

u beat me to it thanx
thanx a mil

Conrad
 
thanks for help all sorted know
created an script file local whitch i put in ppp/ip-up.d
my masquarading also working had to add ppp1 to shorewall masq file

one more q what is is ussage stats page not sure but looks like when i use sasa i cant see usage in is account if dialed in twice just an funny one

Thanx Conrad
 
Hi

I need some help please.

I got the routes from the command:
echo -e "terminal length 0\nshow ip bgp\nexit" | nc route-server.is.co.za 23 | grep ^* | awk '{print $2}' > routes.txt

Got the 2 ppp connections running together. Also I ran the ffg:

for i in `cat routes.txt`; do
``sudo route add -net `echo $i | sed s/\,/\ netmask\ /g` dev ppp0 `` ;
done

in the terminal and i got some routes set but most of them gave me this error:

SIOCADDRT: Invalid argument

Heres a sample of routes.txt:
129.227.213.0/24
129.227.214.0/24
129.227.215.0/24
137.158.0.0
137.214.0.0
137.215.0.0
139.53.0.0
139.92.51.0/24


My routes.txt dont seem to be in the right format, it should be
137.214.0.0,255.255.255.0
right?

But how do i get from my format to that format?

Thanks
 
Last edited:
this file i got in /etc/ppp/ip-up.d named local

#!/bin/sh
# Enable MSS clamping (autogenerated by pppoeconf)
echo $PPP_LOCAL >/etc/ppp/ggg.txt
case $PPP_LOCAL in
196.*)
#route local
for i in `cat /etc/ppp/localroutes.dat`; do
echo ``route add -net `echo $i | sed s/\,/\ netmask\ /g` gw $PPP_LOCAL `` ;
``route add -net `echo $i | sed s/\,/\ netmask\ /g` gw $PPP_LOCAL `` ;
done

;;

165.*)
#international
route add default gw $PPP_LOCAL

;;
esac



and here is my gethosts file

echo -e "terminal length 0\nshow ip bgp\nexit" | nc route-server.is.co.za 23 | grep ^* | awk '{print $2}' > routes.txt

not sure is stil working re-installed recovered this from my original drive
 
Ok thanks. i did that, got it running automatically.

But heres the problem, it doesnt create all the routes.
The routes.txt is in the format i gave above, and some of the ips are missing the "/24 or whatever number" after it. Those ips aren't being created routes.

Also it keeps creating the default root for all ppp connections. Have to manually delete it everytime.

Thanks
 
Last edited:
I have the same issue as linkinpark.

route commands should be specified either as:
route add -net 192.168.0.0/16 gw $5
or
route add -net 192.168.0.0 netmask 255.255.0.0 gw $5

but since some of the lines returned by the IS route server consist of a network address without a mask, the route command borks.

Is there a way to make the route server send us info formatted another way, or could someone write a script to properly convert them?

Thanks

Edit: I'm inclined to think those IPs can just be ignored as without a netmask they are essentially meaningless anyway.. If I just knew what they meant I might be able to work around them.
 
Last edited:
Edit: I'm inclined to think those IPs can just be ignored as without a netmask they are essentially meaningless anyway.. If I just knew what they meant I might be able to work around them.

Not true, the reason why they do not have a netmask is because they do not need special treatment. They utilise the default subnet mask for that class of network.

You can convert these standard entries (that do not have a corresponding CIDR) with the following command:

# cat routes.txt | grep -v "/" | awk '{FS=".";if ($1 >= 1 && $1 <= 126){print $0"/8"} else if ($1 >= 128 && $1 <= 191){print $0"/16"}else if ($1 >= 192 && $1 <= 223){print $0"/24"} }'

Note: The above command should be input on one line

-twiga
 
# cat routes.txt | grep -v "/" | awk '{FS=".";if ($1 >= 1 && $1 <= 126){print $0"/8"} else if ($1 >= 128 && $1 <= 191){print $0"/16"}else if ($1 >= 192 && $1 <= 223){print $0"/24"} }'
:eek:

That looks damn complicated. Machine code looks more readable than that. :p

But kewl, thanks twiga and eremos. Ill try that when i get home.

Using ubuntu edgy btw. Got everything working fine. Beryl just looks so sweet.
 
So the following command will take care of everything (except /32 routes):

# for i in `cat routes.txt | dos2unix`;do if [[ $i =~ "/" ]]; then route add -net $i gw $ADSL1; else route add -net `echo -n $i | awk '{FS=".";if ($1 >= 1 && $1 <= 126){printf $0"/8"} else if ($1 >= 128 && $1 <= 191){printf $0"/16"}else if ($1 >= 192 && $1 <= 223){printf $0"/24"} }'` gw $ADSL1 ; fi;done

It is assumed that ADSL1 has the contents of the gateway of your local ADSL connection.

The script will not handle the entries x.x.x.x/32 because for these routes you need to pass the command:

ip route add -host x.x.x.x/32 gw blah

I'm sure you will be able to handle those special cases yourself.

EDIT: (nevermind, here is the handling of /32 aswell):
# for i in `cat routes.txt | dos2unix`;do if [[ $i =~ "/32" ]];then route add -host $i gw $ADSL1; else if [[ $i =~ "/" ]]; then route add -net $i gw $ADSL1; else route add -net `echo -n $i | awk '{FS=".";if ($1 >= 1 && $1 <= 126){printf $0"/8"} else if ($1 >= 128 && $1 <= 191){printf $0"/16"}else if ($1 >= 192 && $1 <= 223){printf $0"/24"} }'` gw $ADSL1 ; fi;fi;done

You will need the dos2unix utils, which I used above to filter out stoopid CRLF characters.

- twiga
 
Last edited:
w00t

awesome twigga. you are my new hero.

I've put all of the info from this thread into a little script that can be run at dialup.

Code:
if [[ $IPLOCAL =~ ^196 ]]; then
        route add route-server.is.co.za gw $IPREMOTE;
        echo -e "terminal length 0\nshow ip bgp\nexit" | nc route-server.is.co.za 23 | grep ^* | awk '{print $2}' > /tmp/routefile.txt;
        echo it has begun > /tmp/log.routes
        for i in `cat /tmp/routefile.txt | dos2unix` ;
                do if [[ $i =~ "/32" ]]; then echo route add -host $i gw $IPREMOTE >> /tmp/log.routes; route add -host $i gw $IPREMOTE >> /tmp/log.routes 2>&1;
                else if [[ $i =~ "/" ]]; then echo route add -net  $i gw $IPREMOTE >> /tmp/log.routes; route add -net  $i gw $IPREMOTE >> /tmp/log.routes 2>&1;
                        else echo route add -net `echo -n $i | awk '{FS="." ; if ($1 >= 1 && $1 <= 126){printf $0"/8"} else if ($1 >= 128 && $1 <= 191){printf $0"/16"}else if ($1 >= 192 && $1 <= 223){printf $0"/24"} }'` gw $IPREMOTE >> /tmp/log.routes; route add -net `echo -\n $i | awk '{FS="." ; if ($1 >= 1 && $1 <= 126){printf $0"/8"} else if ($1 >= 128 && $1 <= 191){printf $0"/16"}else if ($1 >= 192 && $1 <= 223){printf $0"/24"} }'` gw $IPREMOTE >> /tmp/log.routes 2>&1;
                        fi;
                fi;
        done;
fi

It contains debugging code that will log everything to /tmp/log.routes, but if you're happy that you don't need the debugging code, use the following instead:

Code:
IPLOCAL=$4
IPREMOTE=$5
if [[ $IPLOCAL =~ ^196 ]]; then
        route add route-server.is.co.za gw $IPREMOTE;
        echo -e "terminal length 0\nshow ip bgp\nexit" | nc route-server.is.co.za 23 | grep ^* | awk '{print $2}' > /tmp/routefile.txt;
        for i in `cat /tmp/routefile.txt | dos2unix` ;
                do if [[ $i =~ "/32" ]]; then route add -host $i gw $IPREMOTE;
                else if [[ $i =~ "/" ]]; then route add -net  $i gw $IPREMOTE;
                        else route add -net `echo -n $i | awk '{FS="." ; if ($1 >= 1 && $1 <= 126){printf $0"/8"} else if ($1 >= 128 && $1 <= 191){printf $0"/16"}else if ($1 >= 192 && $1 <= 223){printf $0"/24"} }'` gw $IPREMOTE
                        fi;
                fi;
        done;
fi

It doesn't do anything with your alternate connection, but adapting it into a case statement as outlined before should sort that out.

Thank you so much to everyone who contributed to this thread. This should streamline things for me very nicely.

update 1: bug in first chunk of code. nothing fatal, would just have hindered logging.
update 2: integrated the changes twiga suggested below.
update 3: changed ppp local IP to be soft-coded in case of distro-dependence
 
Last edited:
Yeah, that looks way neater!


The only thing is this:

Code:
else echo route add -net `echo -\n $i ...

should prolly change to

Code:
else echo route add -net `echo -n $i ...

The -n instructs echo not to output a trailing newline (\n)

Also this line:

Code:
 rm /tmp/log.routes

Is not necessary 'cause this line:

Code:
 echo it has begun > /tmp/log.routes

Overwrites the file anyways.


- twiga
 
Last edited:
I was wondering about the -\n myself, wonder how that snuck in. and I put in the rm before I decided to start with "it has begun", just never removed it. :)

man, it is tough maintaining two sets of very similar but subtly different sets of code!
 
but heres the problem, the route that gets generated from is.co.za, doesnt contain /32

its already the proper ###.###.###.###/## format except the ones that need /32 are in ###.###.###.###

so im working on a script that modifies the lines without the / to add /32, once thats done it should work fine.
 
Cisco by default drops CIDR notation on a full classless route. I highly doubt everyone would push a bunch of /32's via BGP... It's lousy, and hardly optimised

Where no subnet (or class) is specified, it is presumed to be a full class route. Class A, B, and C has their own defaults for these addresses...

Class A - 0.0.0.0 TO 127.0.0.0 (Cisco drops /8 here)
Class B - 128.0.0.0 To 191.0.0.0 (Cisco drops /16 here)
Class C - 192.0.0.0 to 223.0.0.0 (Cisco drops /24 here)

If octet1 is between 0 and 127, add a /8, if octet1 is between 128 to 191, add /16, etc etc etc etc.

Networking 101.... Hardly rocket science...
 
Top
Sign up to the MyBroadband newsletter
X