Here's how I did it
I've got an account with 2 ISPs both of whom use pppoe. This gives me two interfaces ppp0 and ppp1.
With iproute2, you can use
ip route add default nexthop dev ppp0 nexthop dev ppp1
This works. After a large download using bittorrent, if you check the amount of traffic through each interface, you'll find that the two values are pretty close. But since routes are cached, this doesn't always work satisfactorily with ftp and http downloads.For example, you might find that sometimes all the traffic is going through ppp0 while ppp1 is sitting idle and vice versa. It works with bittorrent because there are hundreds of peers ergo hundreds of different routes.
To do it per packet, you can use the
'nth' or
'random' mode of the 'statistic' match in iptables
This feature allows you to change the source address for every nth packet. I have two connections, so I send every other packet through ppp0 and rest goes throught ppp1. So,
Packets: 0,2,4,6,8.... go through ppp0
Packets: 1,3,5,7,9 ... go through ppp1
This ofcourse has to be used in addition to the iproute2 command mentioned above, here's how you do it
Assuming,
$IP1 is the IP address of ppp0 and $IP2 is that of ppp1
If you want to use the nth mode, which as the name suggests manipulates every nth packet
iptables -t nat -A POSTROUTING -m statistic --mode nth --every 2 --packet 0 -j SNAT --to-source $IP1
iptables -t nat -A POSTROUTING -m statistic --mode nth --every 2 --packet 1 -j SNAT --to-source $IP2
If you want to use the random mode, you have to provide the probability
iptables -t nat -A POSTROUTING -m statistic --mode random --probability 0.5 -j SNAT --to-source $IP1
iptables -t nat -A POSTROUTING -m statistic --mode random --probability 0.5 -j SNAT --to-source $IP2
Both modes work great. Use whichever suits your setup better.
If you don't have a static IP, you'll have to clear the nat table using
iptables -t nat -F and re-issue the above commands everytime you connect.
You have to modify the above commands to suit your setup. For eg,if you have an ADSL connection in addition to the above, you'll need to issue the commands
ip route add default equalize nexthop dev eth0 via $ADSLRouterIP nexthop dev ppp0 nexthop dev ppp1
iptables -t nat -A POSTROUTING -m statistic --mode nth --every 3 --packet 0 -j SNAT --to-source $ADSLRouterIP
iptables -t nat -A POSTROUTING -m statistic --mode nth --every 3 --packet 1 -j SNAT --to-source $IP1
iptables -t nat -A POSTROUTING -m statistic --mode nth --every 3 --packet 2 -j SNAT --to-source $IP2
I've written a script which extracts the IP addresses of my two interfaces ppp0 and ppp1 and sets the nat rules. I've attached it if someone wants to have a look
This method won't work with all ftp servers. You might get an error saying "Bad IP Connecting" because your ftp client will be sending commands via different IPs. If you want to play safe, restrict the statistic rule to http downloads by using "
-p tcp --dport 80"
NOTE: You need to re-compile iptables to get the 'statistic' match feature. For instructions on how to do it, see this thread
http://forums.fedoraforum.org/showthread.php?p=835694