Fedora Linux Support Community & Resources Center

Sections ›› Home | Forums | Guidelines | Forum Help | Fedora FAQ | Fedora News 

Go Back   FedoraForum.org > Fedora Support > Guides & Solutions (No Questions)

Guides & Solutions (No Questions) Post your guides here. You can also add your comments to a guide, but don't start a thread to ask a question. Use another forum for that.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 2007-07-26, 03:59 AM CDT
mndar's Avatar
mndar Offline
Registered User
 
Join Date: Feb 2005
Posts: 1,046
Look Ma! I just balanced my connections

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

Last edited by mndar; 2007-07-31 at 07:48 PM CDT. Reason: Works better without 'equalize' in 'ip route...'
Reply With Quote
  #2  
Old 2007-07-26, 04:10 AM CDT
mndar's Avatar
mndar Offline
Registered User
 
Join Date: Feb 2005
Posts: 1,046
Here's the script I use
Code:
#!/bin/bash
#You need to provide two arguments.The gateway IP of your first ISP and the gateway IP of your second ISP

#establish connections
ifup ppp0
ifup ppp1

#provide two arguments.
GW1=$1
GW2=$2

#iproute2 to set the default route
ip route add default equalize nexthop dev ppp0 nexthop dev ppp1
iptables -t nat -F

#Get your current IPs
IP1=`ip route show|grep $GW1|sed -n 1p|tr -d [:alpha:]|tr -d [=\ =]|sed s/$GW1\0//`
IP2=`ip route show|grep $GW2|sed -n 2p|tr -d [:alpha:]|tr -d [=\ =]|sed s/$GW2\1//`

#Another way of doing the same thing
#IP1=`ifconfig |grep $GW1|sed -n 1p|tr -d [:alpha:],:,\-|sed s/$GW1//|sed s/255.255.255.255//|tr -d [=\ =]`
#IP2=`ifconfig |grep $GW2|sed -n 2p|tr -d [:alpha:],:,\-|sed s/$GW2//|sed s/255.255.255.255//|tr -d [=\ =]`

#form the commands
COMMAND1="iptables -t nat -A POSTROUTING  -m statistic --mode nth --every 2 --packet 0 -j SNAT --to-source $IP1"
COMMAND2="iptables -t nat -A POSTROUTING  -m statistic --mode nth --every 2 --packet 1 -j SNAT --to-source $IP2"

#execute them
$COMMAND1
$COMMAND2
Reply With Quote
  #3  
Old 2007-07-27, 10:07 AM CDT
mndar's Avatar
mndar Offline
Registered User
 
Join Date: Feb 2005
Posts: 1,046
Here's the link that I had referred to http://www.linux-noob.com/forums/ind...topic=2182&hl= .
You might find it useful
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
2 connections, 1 NIC nspmangalore Networking 2 2007-08-23 08:03 AM CDT
2 connections, 1 NIC nspmangalore General Support 1 2007-08-22 03:03 AM CDT
TCP Connections Albert A. Modderkolk gmane.linux.redhat.fedora.general 3 2005-08-23 07:50 AM CDT
RE: Load balanced, failover internet connections Mike McGrath gmane.linux.redhat.fedora.general 0 2005-07-25 02:57 PM CDT
Load balanced, failover internet connections Aaron O'Hara gmane.linux.redhat.fedora.general 7 2005-07-25 02:55 PM CDT

Automatic Translations (Powered by Powered by Google):
Afrikaans Albanian Arabic Belarusian Bulgarian Catalan Chinese Croatian Czech Danish Dutch English Estonian Filipino Finnish French Galician German Greek Hebrew Hindi Hungarian Icelandic Indonesian Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Taiwanese Thai Turkish Ukrainian Vietnamese Yiddish

All times are GMT -7. The time now is 11:22 AM CST.

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo



All trademarks, and forum posts in this site are property of their respective owner(s).

FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact | Founding Members
Designed By Ewdison Then | Powered by vBulletin ©2000-2009, Jelsoft Enterprises Ltd.
FedoraForum is Powered by Open Source Projects and Products
vB Enterprise Translator (vBET 2.3.8) coded by NLP-er