Linux routing help needed

I have the code in an executable script file called local in my /etc/ip-up.d/
directory. The advantage of that is that whatever scripts are in that folder, will be run everytime a ppp connection is made.

Could that be the problem?

Nope, that's the way it should be. The variables $IPLOCAL and $IPREMOTE are passed to the script by pppd. Are you getting your IP logged by the following line?

echo $IPLOCAL >/etc/ppp/iplocal.txt

Try adding this:
echo $IPREMOTE > /etc/ppp/ipremote.txt

And see if it logs the gateway IP.

I tried manually running the script file with no success.

No, that wouldn't work unless you hard coded the IPs
 
if i copy the code, remove spaces and tabs, hardcode the ips, take out the logging and paste it in terminal. It works! although to a certain extent, the -host for the ips with /32 gives some error (cant check now, at work)

I have the code in an executable script file called local in my /etc/ip-up.d/
directory. The advantage of that is that whatever scripts are in that folder, will be run everytime a ppp connection is made.

Could that be the problem?

I tried manually running the script file with no success.

What distro are you running? maybe post your local script. try using the script posted by eremos and pasting it into your /etc/ppp/ip-up script, it also gets called when ppp goes active. Are you sure your script gets called try outputing debug echo's to a file. Maybe the scripts permisions are not correct, IOW, can't execute.
 
What distro are you running? maybe post your local script. try using the script posted by eremos and pasting it into your /etc/ppp/ip-up script, it also gets called when ppp goes active. Are you sure your script gets called try outputing debug echo's to a file. Maybe the scripts permisions are not correct, IOW, can't execute.

It definitely executes. We've seen output in the logs.

Although, it might be useful to double check the modification times on the files after every try, or deleting them before retrying a connection

rewrite the script to put them in /tmp/log/
and to connect use: rm /tmp/log/* && pon
 
yep the local ip and gateway gets written to the file, i also delete the logs before i try, so its definitely doing the loop.

Using ubuntu edgy (6.10)
 
yep the local ip and gateway gets written to the file, i also delete the logs before i try, so its definitely doing the loop.

Using ubuntu edgy (6.10)

I'm also using ubuntu, mine is working fine, is there a specific reason you want to use. ip-up.d and local script? and not just ip-up? I did need to download dos2unix before it worked!

But thats all and I had to config because I don't use IS and SAIX but 2 IS accounts
 
Last edited:
I'll try it in the ip-up.d file when i get home. And i have the dos2unix tools.

I'm thinking about trying to run routesentry through wine, think that'll work??
 
I'll try it in the ip-up.d file when i get home. And i have the dos2unix tools.

I'm thinking about trying to run routesentry through wine, think that'll work??
No don't think so, how will you init the ppp connections RASPPPOE, it uses windows system commnads to bring up the connetcions and windows routing to do the routes.

This can't be that hard, for you, I will fix up my script and post it some time today.

You are sure both ppp connections are up and running? You used pppoeconfig to setup the connections?
 
ass_sazin: the script works to a certain extent. the if statements and awk part doesnt want to work.
 
the script works to a certain extent. the if statements and awk part doesnt want to work.

Are you using bash as your shell? Also you need bash v3 for the regex matches to work.

- twiga
 
Are you using bash as your shell? Also you need bash v3 for the regex matches to work.

- twiga

I would think so. I installed a fresh install of the latest ubuntu distro which was release last month
 
if the awk command is the only remaining issue, I take it the /32s and /everythingelses work?

put this in /tmp/testfile

41.1.1.1
145.1.1.1
193.1.1.1

and run this against it:
Code:
for i in `cat /tmp/testfile | dos2unix` ; do 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 $IPREMOTE ; done

then run this:
Code:
for i in `cat /tmp/testfile | dos2unix` ; do echo route add -net `echo -n $i | 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 $IPREMOTE ; done
 
the if [] and the awk work when run from the terminal, but not from the script file. Thats the problem ive been having all along (was only trying it out through the script file). The code works fine, i just dont know why it doesnt work in a script file.

I tried making the file executable, also changed permissions but still no luck, anyway that cant be it, because the script runs, just certain parts doesnt
 
the if [] and the awk work when run from the terminal, but not from the script file. Thats the problem ive been having all along (was only trying it out through the script file). The code works fine, i just dont know why it doesnt work in a script file.

I tried making the file executable, also changed permissions but still no luck, anyway that cant be it, because the script runs, just certain parts doesnt

How about this:

Code:
for i in `cat /etc/ppp/routefile.txt | dos2unix | grep -v "/"` ; do echo route add -net `echo -n $i | 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 $IPREMOTE ; done
 
:)

That worked in the script file!

Thanks!

It added the correct class to all ips without a "/", all 500 of them
but this means the if statements arent working :/
 
:)

That worked in the script file!

Thanks!

It added the correct class to all ips without a "/", all 500 of them
but this means the if statements arent working :/

Hehe, indeed. Try removing the grep -v "/" - (in YOUR script, not the one I just posted) I think it's before dos2unix in your script.

Edit: and repost your script as it is now.
Edit2: and an update on what the logs are saying now
 
Last edited:
here is the script that worked

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

but if uncomment the if statements, then its still the same (working for only ips without /)
 
Put this in an ip-up script (make sure yours is commented out or inactive) and connect

I'd like to see the contents of all 4 log files. If they're too long to post here, use http://pastebin.com/

Thanks

Code:
case $IPLOCAL in
196.*)
        echo local: $IPLOCAL >/tmp/iplocal.txt;
        echo remote: $IPREMOTE >>/tmp/iplocal.txt;
        echo /32 routes go here > /tmp/routes.log;
        echo other routes go here > /tmp/routes1.log;
        echo no / routes go here > /tmp/routes2.log;
#       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 echo route add -host $i gw $IPREMOTE >> /tmp/routes.log; route add -host $i gw $IPREMOTE >> /tmp/routes.log 2>&1;
                        else if [[ $i =~ "/" ]]; then echo route add -net $i gw $IPREMOTE >> /etc/ppp/routes1.log; route add -net $i gw $IPREMOTE >> /etc/ppp/routes1.log 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 >> /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 $IPREMOTE >> /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
 
Last edited:
nothing got created, tried changin the directory to /etc/ppp/ and still nothing got created. Not even the "/32 routes go here"
 
This time the files got created
iplocal.log:
Code:
local: 196.209.27.232
remote: 196.209.16.1

routes.log:
Code:
/32 routes go here

routes1.log:
Code:
other routes go here

routes2.log
Code:
no / routes go here

Thats everything in those files in /tmp/
 
Top
Sign up to the MyBroadband newsletter
X