Linux routing help needed

Thats not the case with the file that we get from is.
Heres a sample:
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

Theres also /23, /17 etc etc
and it all seems random
 
So LP what exactly is your problem?

With that script the default subnet for that class will be automatically added. (The awk script takes care of it)

I highly doubt everyone would push a bunch of /32's via BGP... It's lousy, and hardly optimised
IS doesn't seem to mind:

160.123.6.72/32
160.123.100.150/32
160.123.100.173/32

- twiga
 
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)

Surely you mean:

A: 0.0.0.0 TO 127.255.255.255
B: 128.0.0.0 TO 191.255.255.255
C: 192.0.0.0 TO 223.255.255.255

?

- twiga
 
The awk script adds a /## even if its already there.

Some of the routes have the /## so thats fine to add, but some dont so i have to use -host instead of -net.

The problem is that the if statement "else if [[ $i =~ "/" ]];" only is true when the route ends with / and not with /##
How do u change it so it allows /## ?? :confused:

Something to the effect like:
if line ends with /## then use -net in route command
else use -host in route command

Sigh........ If this was c++, it would be soo easy :rolleyes:


This classes thing, im not sure the routes file is the same
theres a 32.234.234.0/23
and 165.253.43.0/17
Im confused :confused:
 
The awk script adds a /## even if its already there.

not so. grep -v means it only returns the lines that don't contain the string specified (so everything without a /). awk then adds a /8, /16 or /24 to the end of the line depending on whether it's a class a, b or c network.

Some of the routes have the /## so thats fine to add, but some dont so i have to use -host instead of -net.

the first if line takes care of that

The problem is that the if statement "else if [[ $i =~ "/" ]];" only is true when the route ends with / and not with /##
How do u change it so it allows /## ?? :confused:

nope, =~ means if "/" is anywhere in the line

Something to the effect like:
if line ends with /## then use -net in route command
else use -host in route command

The first line in the if statement takes care of /32 entries, using -host on them
the second line takes care of everything that has a /
the 3rd line takes care of everything that needs a / appended (using the awk command to determine class)

Sigh........ If this was c++, it would be soo easy :rolleyes:

This classes thing, im not sure the routes file is the same
theres a 32.234.234.0/23
and 165.253.43.0/17
Im confused :confused:

Anything that's not in a straightforward class (a, b, c) has a subnet, because there's no other way to describe them

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.

They're not /32. They are just straightforward class A, B or C

There's a table of subnet classes here: http://en.wikipedia.org/wiki/Subnetwork#Subnetworking_concept
 
Last edited:
The awk script adds a /## even if its already there.
No it doesn't....


The problem is that the if statement "else if [[ $i =~ "/" ]];" only is true when the route ends with / and not with /##

The above statement matches ANYTHING that has a "/",

Something to the effect like:
if line ends with /## then use -net in route command
else use -host in route command

Which is excacly what the script is doing. Let me explain this logically.

If the route has a /32 mask then add the route using the command
route add -host
else
if the route has a /xx (a slash anything mask) simply add the route using
route add -net
else
if the route has NO mask, ie no /
then add the default mask for that class of network with the awk script and execute route add -net

Did you actually test the script??


- twiga
 
Anything that's not in a straightforward class (a, b, c) has a subnet, because there's no other way to describe them

This does not mean that everything that starts with 0-126 is in class A, it's only class A unless specified otherwise
 
I did test it, thats how i know what it did. I put the first if statement to output to a log file and the second to another log file and the third to a third log file. Only the second log file had anything. Ill put up the script exactly how it is in the script file.

Anyway, its likely that i missed something, i was working on it last night while i was half asleep. Thanks for the help dudes.
 
ok my code is:

Code:
case $PPP_LOCAL in
196.*)
        echo $PPP_LOCAL >/etc/ppp/iplocal.txt
#        route add route-server.is.co.za gw $PPP_LOCAL;
        echo /32 routes go here > /etc/ppp/routes.log
        echo other routes go here > /etc/ppp/routes1.log
        echo no / routes go here > /etc/ppp/routes2.log
        for i in `cat /etc/ppp/routefile.txt | dos2unix` ;
                do if [[ $i =~ "/32" ]]; then echo route add -host $i gw $PPP_LOCAL >> /etc/ppp/routes.log; route add -host $i gw $PPP_LOCAL >> /etc/ppp/routes.log 2>&1;
                else if [[ $i =~ "/" ]]; then echo route add -net $i gw $PPP_LOCAL >> /etc/ppp/routes1.log; route add -net $i gw $PPP_LOCAL >> /etc/ppp/routes1.log 2>&1;
                        else echo route add -net `echo -n $i | grep -v "/" | awk '{FS="." ; if ($1 >= 1 && $1 <= 127){printf $0"/8"} else if ($1 >= 128 && $1 <= 191){printf $0"/16"}else if ($1 >= 192 && $1 <= 223){printf $0"/24"} }'`gw $PPP_LOCAL >> /etc/ppp/routes2.log; 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 $PPP_LOCAL >> /etc/ppp/routes2.log 2>&1;
                     fi;
                fi;
        done;
;;
41.*)
	echo $PPP_LOCAL >/etc/ppp/ipint.txt
;;
165.*)
	echo $PPP_LOCAL >/etc/ppp/ipint.txt
;;
esac

the routes and routes1 only contain the line i set. Routes2 contains the following a few hundred time:

Code:
route add -net gw 196.209.24.34
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

As you can see, the awk statement isnt doing anything but taking out the ip :confused:
 
Code:
else echo route add -net `echo -n $i | grep -v "/" | awk '{FS="." ; if ($1 >= 1 && $1 <= 127){printf $0"/8"} else if ($1 >= 128 && $1 <= 191){printf $0"/16"}else if ($1 >= 192 && $1 <= 223){printf $0"/24"} }'[u]`g[/u]w $PPP_LOCAL >> /etc/ppp/routes2.log; 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"} }'[u]`g[/u]w $PPP_LOCAL >> /etc/ppp/routes2.log 2>&1;

underlined characters should be seperated with a space
 
Would you care to run this command:

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

just to make sure we're working with the same source file
 
Great progress guys!

My problem now is that both my connections are IS based! So the 196.? 195.? would not map my routes corectly!

Any Ideas on how I can make script that would "fix" this?
 
Great progress guys!

My problem now is that both my connections are IS based! So the 196.? 195.? would not map my routes corectly!

Any Ideas on how I can make script that would "fix" this?

Edit the linkname options for the relevant connections in /etc/ppp/peers/

then put in your /etc/ppp/ip-up files the following:

echo $LINKNAME > /tmp/log.ppp

and tell us if /tmp/log.ppp contains what you'd expect
 
thats the same command i used to create my routes file and i do have dos2unix installed.

Add the 2 spaces and tried again, now the place where my ip supposed to is blank. Looks like PPP_GATEWAY is blank, but PPP_LOCAL contains my ip.

Also the awk command is really really slow. It takes ages to finish writing to the log file.
 
Thanx for quick reply!

Nothing the file is blank.

I put in echo $LINKNAME > /tmp/log.ppp into ip-up

and added linkname "local" (not sure of the syntax there was no linkname field) and same for international obviously changing to "int"
 
Add the 2 spaces and tried again, now the place where my ip supposed to is blank. Looks like PPP_GATEWAY is blank, but PPP_LOCAL contains my ip.

do you have the PPP_GATEWAY=$5 line?

Can you confirm that after running the script you don't have anything added to the routing table?
 
Thanx for quick reply!

Nothing the file is blank.

I put in echo $LINKNAME > /tmp/log.ppp into ip-up

and added linkname "local" (not sure of the syntax there was no linkname field) and same for international obviously changing to "int"

try linkname local without the ""

it should just work, lol :rolleyes:
 
yep. typed in route at the terminal and also check the network tools>>netstat>routing table info screen

btw the script that im running above is a file called local which is executable and in the /etc/ppp/ip-up.d/ directory
 
Top
Sign up to the MyBroadband newsletter
X