Splitting International and Local Bandwidth with IPcop

ASS_SAZiN`

Senior Member
Joined
Jul 14, 2005
Messages
520
Wow! This thread is growing nicely!!

Thanks to all whom have contributed thus far to the project, I'm sure we can make the lives of our fellow ADSL users a lot easier by using theses scripts, if we can add the auto update of routes it would be perfect.

I'm tweaking my script to do just that and trying to iron out a few issues (I'm just so busy with my normal work!!).

Keep up the good work!!
 

SlowHands

Senior Member
Joined
Apr 25, 2005
Messages
525
It's been mentioned already, but could someone put all these scripts in a nice small app or something so the rest of us less intelligent peeps may also use it :D
 

ASS_SAZiN`

Senior Member
Joined
Jul 14, 2005
Messages
520
When I get my script running 100% smooth, with Auto updating Routes, I will put it into one package, for use by all, but I have so little free time at the moment!

If any one else manages to get the auto update of routes working within their script please post it!! :D
 

SlowHands

Senior Member
Joined
Apr 25, 2005
Messages
525
Of course please include a short user manual or step by step guide as well please.
 

Bernie

Expert Member
Joined
May 2, 2006
Messages
1,993
When I get my script running 100% smooth, with Auto updating Routes, I will put it into one package, for use by all, but I have so little free time at the moment!

If any one else manages to get the auto update of routes working within their script please post it!! :D
I am busy testing the changes to my script. I am hoping to get it all done by tomorrow eve. My job is just a bit of a hinderance at the moment :p
 

hj2k_x

Honorary Master
Joined
Jan 22, 2006
Messages
30,808
A step-by-step guide for this once it works would be great :D

A real break-through in the SA DSL context
 

ArminM

Well-Known Member
Joined
Apr 12, 2005
Messages
149
I'm using this script..... (adapted)

Code:
DATE=`date`
LOGFL=/root/rt.set.log
echo "----------------------" >> $LOGFL
echo $DATE >> $LOGFL

LOCAL=ppp1
INTL=ppp0
PPCHKI=`ifconfig|grep $INTL|awk '{print $1}'`
PPCHKL=`ifconfig|grep $LOCAL|awk '{print $1}'`
if [ "$PPCHKI" == $INTL ]; then
   if [ "$PPCHKL" == $LOCAL ]; then
      echo "$LOCAL already exists. Exiting..." >> $LOGFL
      exit
   fi 
else
   if [ "$PPCHKL" == $LOCAL ]; then
      PID=`ps -ef|grep MyUserName|awk '{print $2}'`
      echo "NO $INTL, therfor killing $LOCAL PID $PID" >> $LOGFL
      kill -9 $PID
   fi
   echo "$INTL Not connected. Exiting..." >> $LOGFL
   exit
fi

echo "Creating connection..." >> $LOGFL
PPUSER=local.dsl.acc
PPASS=local.passw
/usr/sbin/pppd plugin rp-pppoe.so eth1 usepeerdns noipdefault nodefaultroute ipcp-accept-local ipcp-accept-remote passive noccp nopcomp novjccomp user $PPUSER password $PPASS lcp-echo-interval 20 lcp-echo-failure 3 lcp-max-configure 50 maxfail 5
sleep 15
echo "Getting routes..."
wget http://alm.za.net/ip/localroutes4.txt -O /tmp/localroutes
echo "Adding routes..."
source /tmp/localroutes 
#   route add -net 0.0.0.0 netmask 0.0.0.0 $INTL  
echo "Setting Intl. Route..."
route add default dev $INTL metric 0
# SAIX does not allow email to be sent from local only account, therfore
# have to explicitly add the IP of smtp.saix.net to INTL route
route add -host 196.25.240.94 $INTL
sleep 2
echo "Adjusting IPTABLES..."
iptables -t nat -A POSTROUTING -o ppp+ -j MASQUERADE
sleep 2
echo "--- END SCRIPT ---" >> $LOGFL

it fetches the routes and executes them.....you can run it through a grep if you are worried about executing arbitrary commands.

I run this in my fcron every 5 mins.

1. scp script to ipcop box
1.5 edit script to include correct username/password
2. set script executable
3. edit fcron using fcrontab -e
4. include executing the script every 5 mins
5. check the log too see it's running
 
Last edited:

Bernie

Expert Member
Joined
May 2, 2006
Messages
1,993
I followed a slightly different way of using the downloaded routes.

The first thing I did is create a separate script for the download part (yeah I know supposed to be 1 script but this suites me better :) )

My download script is as follows - called get_routes:
Code:
#!/bin/bash
#Thanks to ArminM from http://mybroadband.co.za/vb/showthread.php?t=64649&page=4
# for making this download possible.

WORKDIR=$1
LOGFILE=$WORKDIR/get_routes.log
DATE=`date`
echo $DATE >> $LOGFILE

cd $WORKDIR
#Backup existing route file
mv -f $WORKDIR/localroutes4.txt $WORKDIR/localroutes4.txt.bak

#Retrieve the file
#If file already exists, do not download (-nc option), as it means 
# creating the backup file did not work
# Using --proxy=off option to make sure the latest version of file is
# downloaded and not the one off  the proxy server.
# I decided to keep appending to the wget logfile. (-a option)

wget --proxy=off http://alm.za.net/ip/localroutes4.txt -nc -a $LOGFILE

# Make sure download file exists after wget completed
# If file does not exist Restore the backup
if [ ! -f $WORKDIR/localroutes4.txt ]; then
   echo "Download failed, restoring backup" >> $LOGFILE
   mv -f $WORKDIR/localroutes4.txt.bak $WORKDIR/localroutes4.txt
else
#  Make sure all route commands are complete.
#  This can't guarantee that the whole file has been downloaded
#  but it does make sure that what has been downloaded is complete
   BCHK=`cat $WORKDIR/localroutes4.txt|grep 'route'|wc -l`
   ECHK=`cat $WORKDIR/localroutes4.txt|grep '$LOCAL'|wc -l`
   if [ $BCHK -ne $ECHK -o $BCHK -eq 0 -o $ECHK -eq 0 ]; then
      echo "Route commands incomplete, restoring backup BCHK=$BCHK ECHK=$ECHK" >> $LOGFILE
      mv -f $WORKDIR/localroutes4.txt.bak localroutes4.txt
   else
#     In theory we now have a useful file, so I now create
#     a "saved" version of the file for use in my rt.set script
#     incase the localroutes4.txt file does not exist for any reason
      cp $WORKDIR/localroutes4.txt $WORKDIR/localroutes.save
   fi
fi
The reason I used a separate script is because at first I thought of putting it in the cron to run once a day to get the download file, regardless of what my rt.set script was doing. The rt.set script could then just use the download file that was there. On second thoughts, I thought I may aswell just call the get_route script from the rt.set script whenever a new connection was being set up. In the end that is what I did, but I have the option of putting the get_routes script in the cron if I want.

My changed rt.set script is as follows:

Code:
#!/bin/bash

WORKDIR='/var/log'
DATE=`date`
LOGFL=$WORKDIR/rt.set.log
echo "----------------------" >> $LOGFL
echo $DATE >> $LOGFL

LOCAL=ppp1
INTL=ppp0
PPUSER=MyISPLocalUserName
PPASS=MyISPLocalPassword
PPCHKI=`ifconfig|grep $INTL|awk '{print $1}'`
PPCHKL=`ifconfig|grep $LOCAL|awk '{print $1}'`
if [ "$PPCHKI" == $INTL ]; then
   if [ "$PPCHKL" == $LOCAL ]; then
      echo "$LOCAL already exists. Exiting..." >> $LOGFL
      exit
   fi 
else
   if [ "$PPCHKL" == $LOCAL ]; then
      PID=`ps -ef|grep $PPUSER|awk '{print $2}'`
      echo "NO $INTL, therfor killing $LOCAL PID $PID" >> $LOGFL
      kill -9 $PID
   fi
   echo "$INTL Not connected. Exiting..." >> $LOGFL
   exit
fi

echo "Creating connection..." >> $LOGFL
/usr/sbin/pppd plugin rp-pppoe.so eth1 usepeerdns noipdefault nodefaultroute ipcp-accept-local ipcp-accept-remote passive noccp nopcomp novjccomp user $PPUSER password $PPASS lcp-echo-interval 20 lcp-echo-failure 3 lcp-max-configure 50 maxfail 5
sleep 10

echo "Setting up routes..."
# Call the get_routes script
/usr/local/bin/get_routes $WORKDIR

# If the normal download file of local routes is not available for any reason,
# then use a saved file with routes.
# 
if [ ! -f $WORKDIR/localroutes4.txt ]; then
   ROUTEFILE=$WORKDIR/localroutes.save
else
   ROUTEFILE=$WORKDIR/localroutes4.txt
fi
for IP in `cat $ROUTEFILE|awk '{print $4}'`
do
     route add -net $IP $LOCAL
done

echo "Setting Intl. Route..."
route add default dev $INTL metric 0

# SAIX does not allow email to be sent from local only account, therfore
# have to explicitly add the IP of smtp.saix.net to INTL route
route add -host 196.25.240.94 $INTL

echo "Adjusting IPTABLES..."
iptables -t nat -A POSTROUTING -o ppp+ -j MASQUERADE

echo "--- END SCRIPT ---" >> $LOGFL
Call me paranoid, but I did not want to execute any commands from a file downloaded from the internet, it may have an "rm -r *" command somewhere :p

So I strip out the IP address and subnet mask and loop through the download file and set the routes myself.

I have now put both scripts in /usr/local/bin and use /var/log for logging. You can use any directory for logging by changing the $WORKDIR variable in the rt.set script.

I also put a couple of rudimentary checks in the scripts, to make sure the script will still run incase there is any problem downloading the file.

Anyway, I hope the above helps.

I am going to try and make a little install script that will take all of the above and install automatically, by passing a couple of options to the install script. If I get that working, I will post that aswell.

Happy Internetting!!!
 
Last edited:

Bernie

Expert Member
Joined
May 2, 2006
Messages
1,993
....
I am going to try and make a little install script that will take all of the above and install automatically, by passing a couple of options to the install script. If I get that working, I will post that aswell.
For those that are interested, I created a little install package to install these scripts.

I have put the install file on www.4shared.com. Here is the URL:

http://www.4shared.com/dir/1869544/c1bbda86/sharing.html

The file is called rt-0.0.01.gz.tar

Code:
1. Copy the file to a temp directory on your IPcop box. You will need 
to use WinSCP or similar program. (http://winscp.net/eng/index.php) 

2. Change to this temp directory and extract the tar ball. Enter the following 
command "tar zxvf rt-0.0.01.tar.gz"

3. This will extract the files into directory called rt-0.0.01. 

4. Change to directory rt-0.0.01. Please read the README file for more 
information. Run the install script. enter "./install" 

5. Follow the prompts until the install completes.

[B]*********** DISCLAIMER ************** 
This script is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE. It comes with NO warranty or 
guarantee, so use it at your own risk. This package adds firewall rules, 
modifies the kernel routing table. Do NOT use this script if firewall 
security is a major issue. 
*********** DISCLAIMER ************** [/B]
If anybody does try this out, please let me if it works or does not work, what bugs there are etc. etc.

Please read the README file before running the install.

B.
 

kilkraze

Active Member
Joined
Mar 8, 2007
Messages
67
Hey Bernie

I tried your install package on as IPCop with only a green and red interface and it worked great. Thank you very much. I have been looking for a solution like this for a long time. When 'n installed it on a IPcop with blue and orange interfaces however, it didn't work. The reason for this, I figured, was because the install package assume that red is on eth1. I tried to switch my red to eth1 but still no luck. Another thing I am curious about is whether this will work together with a VPN.

Thanks again for a great solution!
 

Bernie

Expert Member
Joined
May 2, 2006
Messages
1,993
Hey Bernie

I tried your install package on as IPCop with only a green and red interface and it worked great. Thank you very much. I have been looking for a solution like this for a long time. When 'n installed it on a IPcop with blue and orange interfaces however, it didn't work. The reason for this, I figured, was because the install package assume that red is on eth1. I tried to switch my red to eth1 but still no luck. Another thing I am curious about is whether this will work together with a VPN.

Thanks again for a great solution!
Hi kilkraze

Thanks for the feedback.

You make a good point, and something I neglected to mention. I only tested on a RED-GREEN setup as that is what I have and my RED is on eth1.

If you change the interface in the rt.set script to your RED interface that may work.
Code:
echo "Creating connection..." >> $LOGFL
/usr/sbin/pppd plugin rp-pppoe.so eth1 usepeerdns....
change eth1 in this line in the script to what ever your RED interface is on.

Please let me know if that works, if it does, I will change the install to try and derive the RED interface instead of assuming eth1.

As for VPN. I guess there are two ways you can look at this:

1. Connecting to an external VPN through IPcop.
2. IPcop hosting the VPN to give access to the resources behind IPcop.

The first senario I use everyday, since the VPN I connect to is in SA it allways uses the local bandwidth, no problem there.

For the second senario, I cant really comment. I have never set this up. Having said that, I cant see why this would be a problem, but I would need to test.

If there are any other types of VPN setups I am not aware of them.
 

mysticMystic

Member
Joined
Jan 2, 2007
Messages
29
Hi thanks it works great.

But from the logs I can see that downloading of the localroutes file is failing. Doesn't say why though.

Is there a local site I can go to to show my ipaddress so I can confirm what ip is being used locally?

I have now thought of another nice :) feature that can be added.

I want to add a third ppoe connection. One for an unshaped account for games. I thought it to work similar to the local one, but have a seperate unshapedRoutes file that I can add specific server ips to for gaming. How to add ips to it is a problem :(. Manually in a file is cumbersome.

I am going to try and do it, but alas my knowledge of scripting and anything non Microsoft is lacking. So it might just take me some time but Ill post back when I've figured it out.

If somebody else thinks the idea is worthwhile, please take a crack at it. I dont know if I've got enough braincells to get this working. :D
 

Gnome

Executive Member
Joined
Sep 19, 2005
Messages
5,770
Nice work to everyone who worked on the script!!!

I especially like the idea of having something that can be easily install, very nice! Only one problem though, the 4shared link doesn't work: In firefox it keeps reloading the same page when I click download and in IE6 it gives me a error about my network settings being a problem.
 

Bernie

Expert Member
Joined
May 2, 2006
Messages
1,993
Nice work to everyone who worked on the script!!!

I especially like the idea of having something that can be easily install, very nice! Only one problem though, the 4shared link doesn't work: In firefox it keeps reloading the same page when I click download and in IE6 it gives me a error about my network settings being a problem.
Hi Gnome

PM me an email address, I'll send you the file. 4 Shared does seem to be a bit up and down, couldn't even log in a couple a days back. Do you know of any other file sharing sites, I will put a copy there aswell.
 

Bernie

Expert Member
Joined
May 2, 2006
Messages
1,993
Hi thanks it works great.

But from the logs I can see that downloading of the localroutes file is failing. Doesn't say why though.
Hi mysticMystic

Thank you for the feedback.

Yeah, I noticed the failing download of the routes aswell. I think it may have something to do with the fact that when it tries to download, there is no ppp1 connection, I just assumed that it would use ppp0, but for some reason it doesnt/cant. I will probably just end up putting the get_routes script in the cron by itself to download once a day until I find the problem. I will post the solution if/when I find it.

Is there a local site I can go to to show my ipaddress so I can confirm what ip is being used locally?
If you using IPcop, in the web GUI, just go to the "CONNECTIONS" menu option under the "STATUS" menu, it will show all websites you connected to and which IP address its coming from. Try this website: http://www.capeinfo.com/RC/reply.asp to check your local IP.

I want to add a third ppoe connection. One for an unshaped account for games. I thought it to work similar to the local one, but have a seperate unshapedRoutes file that I can add specific server ips to for gaming. How to add ips to it is a problem :(. Manually in a file is cumbersome.
I actually tried this out.
I created a ppp2 connection using my webafrica unshaped account. Added a single static route for this interface.
Code:
route add -net 196.31.65.0/24 ppp2
Webafrica is on this subnet. (Can test with anything actually). I then opened up Webafrica's home page. Here are some snippets from my connection status.

Code:
International link:
tcp (6)  	431999  	ESTABLISHED  	  41.242.110.165  :32807  	  66.102.9.104  :80  	  66.102.9.104  :80  	  41.242.110.165  :32807

IS Local only link to news server:
tcp (6)  	431994  	ESTABLISHED  	  192.168.1.11  :1715  	  196.26.208.123  :119  	  196.26.208.123  :119  	  196.209.19.151  :1715

Webafrica Unshaped:
tcp (6)  	431996  	ESTABLISHED  	  165.146.8.192  :32803  	  196.31.65.20  :80  	  196.31.65.20  :80  	  165.146.8.192  :32803
You will see the international connection is using 41.242.110.165, the local only IS is using 196.209.19.151, and the unshaped is using 165.146.8.192.

So after all this waffel, ja, its definately possible to set this up. If you not sure about the scripting, PM me (or post) the list of IP addresses you want for the unshaped account and can whip you up a script.

B.
 

ADSL Newbie

Well-Known Member
Joined
Feb 23, 2007
Messages
120
IPCop and Route Sentry...

Hey guy's, if you had to explain to a retard the difference between IPCop and Route Sentry, how would you do it??

And by the way : Let's say I'm using Route Sentry, and I'm downloading files from greenlab, but want to play Guild Wars on an International server at the same time, in what way is my cap affected??? (Meaning is it possible to use two accounts at the same time from the same PC, or does the local content come off my local cap whilst the INTL content come from my INTL cap)

Thanx guys...:D
 

Bernie

Expert Member
Joined
May 2, 2006
Messages
1,993
Hey guy's, if you had to explain to a retard the difference between IPCop and Route Sentry, how would you do it??

And by the way : Let's say I'm using Route Sentry, and I'm downloading files from greenlab, but want to play Guild Wars on an International server at the same time, in what way is my cap affected??? (Meaning is it possible to use two accounts at the same time from the same PC, or does the local content come off my local cap whilst the INTL content come from my INTL cap)

Thanx guys...:D
Not the most PC question out there :p but anyway, look at post no 3 in this thread. I have not used routesentry before, but from what I can gather the concept is the same. The only difference is where the splitting takes place within the network.

Regardless of how you set it up, once its set up, your international cap will get used by playing Guild Wars or any international surfing, and whatever you use for the local bandwidth, green lab whatever, will only use the local connection's bandwidth.

B.
 

ColinR

Expert Member
Joined
Aug 24, 2006
Messages
3,752
Going to setup a second box with ClarkConnect sometime to try and get good QoS and to implement the "splitting up" script with NC, will post the script if I get it working.
Ever get it going?

I gave it a go and had to reinstall my ClarkConnect box! I could always put IPCop between my ClarkConnect box and the ADSL - Bernie has done such a great job, now even an install script!
 
Top