Hi to all,
A week ago today I received a GSM usb-modem for my laptop which I use during the day at work.
With a colleague (also Slackware-fan) I discussed the possibility to use the usb-modem at home in combination with my adsl-modem and combine the two bandwidths.
My setup is the following:
1) Local network with:
- Desktop running Slackware 12.1-current
- Laptop running Slackware 12.1-current
- Some other desktops varying from Slackware 4.0 to 12.1
- Huawei MT880 adsl modem/router with a 1Mbps downstream / 320kbps upstream line
2) ZTE622 GSM usb modem reaching about 1.7Mbps downstream / 350kbps upstream where I live that I configured both on my laptop and primary desktop. (*)
(*) The modem is not fully supported by the 2.6.24 kernels, but there is a patch to option.c to make it work 100% at full speed.
After some research I found several solutions using iptables, but my desktop is not a router so I wasn't able to use the 'PREROUTING' chain to mangle packets as most sites suggest.
Messing around a bit with 'ip route' and 'ip rule' I managed to write a script that creates two new routing tables and defines the rules to alternate between the two ISPs.
It is not the most elegant solution, as routes are cached so once you have a connection to one destination, it will continue to use the same route (and thus the same ISP).
So, for FTP / HTTP downloads of large files there is no improvement other than using the other ISP for other traffic while you're downloading.
But if you use bittorrent (or KTorrent, etc.) you will have several connections at the same time and will notice a substantial gain in download speed.
Most information I found on this site:
Linux Advanced Routing & Traffic Control
For those interested, this is my script:
Code:
#!/bin/bash
#
# bal_local Load-balance internet connection over two local links
#
# Version: 1.0.0 - Fri, Sep 26, 2008
#
# Author: Niels Horn <niels.horn@gmail.com>
#
# Set devices:
DEV1=${1-eth0} # default eth0
DEV2=${2-ppp0} # default ppp0
# Get IP addresses of our devices:
ip1=`ifconfig $DEV1 | grep inet | awk '{ print $2 }' | awk -F: '{ print $2 }'`
ip2=`ifconfig $DEV2 | grep inet | awk '{ print $2 }' | awk -F: '{ print $2 }'`
# Get default gateway for our devices:
gw1=`route -n | grep $DEV1 | grep '^0.0.0.0' | awk '{ print $2 }'`
gw2=`route -n | grep $DEV2 | grep '^0.0.0.0' | awk '{ print $2 }'`
echo "$DEV1: IP=$ip1 GW=$gw1"
echo "$DEV2: IP=$ip2 GW=$gw2"
### Definition of routes ###
# Check if tables exists, if not -> create them:
if [ -z "`cat /etc/iproute2/rt_tables | grep '^251'`" ] ; then
echo "251 rt_dev1" >> /etc/iproute2/rt_tables
fi
if [ -z "`cat /etc/iproute2/rt_tables | grep '^252'`" ] ; then
echo "252 rt_dev2" >> /etc/iproute2/rt_tables
fi
# Define routing tables:
ip route add default via $gw1 table rt_dev1
ip route add default via $gw2 table rt_dev2
# Create rules:
ip rule add from $ip1 table rt_dev1
ip rule add from $ip2 table rt_dev2
# If we already have a 'nexthop' route, delete it:
if [ ! -z "`ip route show table main | grep 'nexthop'`" ] ; then
ip route del default scope global
fi
# Balance links based on routes:
ip route add default scope global nexthop via $gw1 dev $DEV1 weight 1 nexthop via $gw2 dev $DEV2 weight 1
# Flush cache table:
ip route flush cache
# All done...
To use the script, copy it to /usr/local/bin, make it executable with 'chmod +x' and call it with:
Code:
bal_local <dev1> <dev2>
filling in <dev1> and <dev2> with your network-devices.
If you call the script without any parameters, it tries to balance eth0 and ppp0 (because this works in my case

)
As a test I started downloading one of the Slackware 12.1 CDs and reached a total download speed of over 250KB/sec with BitTorrent, using about 50 connections simultaneously.
I know there are things that can / should be improved in the script, but, hey, it works for now!
Happy Slacking,
Niels