4

I am thinking of implementing a load balancing solution for personal use.

What I want to do, is to maximize data throughput over mobile phone Internet connections. Let me be clear:

I have data plan in my mobile phone and my family have their respective data plans in their phones, too. If I can connect up to 4 phones in one (desktop) PC (through USB preferably) then I will achieve (theoretically) a faster Internet connection than any one of the 4 phones can achieve (if I connect them to a PC).

That desktop computer will then act as a router for an intranet.

If the above has a sound basis (I could be wrong - don't know the technologies involved in great detail), I need a how to to implement that.

I have seen that the tool for the job is ipvs (right?) but no how to.

Distro-wise the job can be done in any distro, but I know that connecting an Android phone with Ubuntu works plug and play. So If I can do it in Ubuntu, it will probably be faster than compiling everything from strach.

Is there a relative how to? Is there a distro perhaps that does load balancing, and identifies USB internet connections on the fly?

1
  • 1
    I think without specialized transport layer/packet level modifications to the phone OS (maybe sort of like ipvs, but with a different goal -- my guess is ipvs won't quite do on the linux router either), the best you'll be able to do here is run 4 concurrent requests, none of which will be any faster than any one phone. So it won't improve the speed of, e.g., downloads or streaming media at all.
    – goldilocks
    Jun 24, 2014 at 14:51

3 Answers 3

2

To balance outgoing connections all you need is standard iptables and some policy routing. This does get a bit complex with 4 connections as you will need to reconfigure and rebalance the links as connections come and go.

The raw iptables setup is

  • Create a routing table for each connection

    ip rule add fwmark 10 table PHONE0 prio 33000
    ip rule add fwmark 11 table PHONE1 prio 33000
    ip rule add fwmark 12 table PHONE2 prio 33000
    ip rule add fwmark 13 table PHONE3 prio 33000
    
  • Add the default gateway for each connection to each table (the gateway IP will vary depending on each phones provider/setup)

    ip route add default via 192.168.1.2 table PHONE0 
    ip route add default via 192.168.9.1 table PHONE1 
    ip route add default via 192.168.13.2 table PHONE2 
    ip route add default via 192.168.7.9 table PHONE3 
    
  • Randomly mark any unmarked flows, which will route the flow via a specific connection. OUTPUT is used for local processes. Use PREROUTING if you are forwarding traffic for other clients)

    iptables -t mangle -A OUTPUT -j CONNMARK --restore-mark
    iptables -t mangle -A OUTPUT -m mark ! --mark 0 -j ACCEPT
    iptables -t mangle -A OUTPUT -j MARK --set-mark 10
    iptables -t mangle -A OUTPUT -m statistic --mode random --probability 0.25 -j MARK --set-mark 11
    iptables -t mangle -A OUTPUT -m statistic --mode random --probability 0.25 -j MARK --set-mark 12
    iptables -t mangle -A OUTPUT -m statistic --mode random --probability 0.25 -j MARK --set-mark 13
    iptables -t mangle -A OUTPUT -j CONNMARK --save-mark
    
  • NAT for each of the connections (the interface will need to be whatever you phone connection appears to the system as)

    iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
    iptables -t nat -A POSTROUTING -o ppp1 -j MASQUERADE
    iptables -t nat -A POSTROUTING -o ppp2 -j MASQUERADE
    iptables -t nat -A POSTROUTING -o ppp3 -j MASQUERADE
    

Note that a single TCP or UDP connection will see no speed up as it will still be going over a single link. You have to use multiple concurrent connections (at least 4) to make use of the extra bandwidth. Most browsers do this under the hood when requesting multiple objects. Some download managers allow you to use multiple connections for a single file.

As garethTheRed suggests, ispunity adds some of the "glue" on top of this iptables setup to loop through a list of connections, check that the gateway is responding, re balance if something is wrong etc. It's "sticky session" management looks to be additional setup per port on top of it's base "round robin" load balancing of connections. Another solution is Net-ISP-Balance, a Perl script and library that automates the iptables and routing table configuration, monitors the ISP status, alerts you to problems, and reconfigures the routing in case one or more ISPs become inacessible.

Also note that having requests come from multiple IP's can break some services that are based on consistent IP lookups and you may need to add additional rules for those services to tie them to a connection. You won't see any speedup on single connections, only when you are doing 4 things at once, which most browsers will try to do anyway.

ipvs is more for creating a virtual service addresses for things you host so the service can be failed over between multiple hosts.

4
  • so outgoing connections seem to be "set" with this setup. what about incoming connections. after all, I will mostly be downloading over the 4 connections, rather than uploading. how will I get to combine packets arriving from random ifs?
    – nass
    Jun 25, 2014 at 14:51
  • All data sent out a connection, will have that connections (phones) source IP set with the MASQUERADE and so will have to return via the same connection. There is no multiplexing at the packet level. Only TCP or UDP connection level (as deemed by ip_conntrack). You would have to download something in 4 segments, or download 4 things at once to make use of the full bandwidth.
    – Matt
    Jun 25, 2014 at 15:10
  • got a few clarification Qs could we chat here chat.stackexchange.com/rooms/15336/multiple-wan-connections
    – nass
    Jun 25, 2014 at 15:17
  • You have to grant me talk privileges in the room...
    – Matt
    Jun 25, 2014 at 15:22
2

It could be possible - ispunity is a project that load balances your internet connection. It's written in Ruby. They've got it running on a Raspberry Pi, so it should run on any reasonable distro.

The only difference between theirs and your scenario is that they used Ethernet whereas you're proposing to use 3G. I suppose much of your success (or failure) depends on how your 4 mobile phones present their Internet on USB.

As Rasberry Pi usually runs a variant of Debian, then maybe start with that or Ubuntu.

2
  • that's not bad at all. the usb net connections appear as ethernet ifaces. They should run seamlessly.
    – nass
    Jun 24, 2014 at 15:28
  • They should run seamlessly - famous last words! I hope you're right ;-) Jun 24, 2014 at 15:30
1

dispatch-proxy
Using dispatch-proxy one can combine many Wi-Fi networks/Ethernet/3G/4G connections and have access to them as one big, high-bandwidth, load balanced connection. Do note that to make use of higher-connection speed, user must use a threaded download manager which will open multiple connections to dispatch-proxy and it will effectively fetch them using multiple interfaces resulting in combined, faster download speeds.
instruction to install for mac, also works for linux.

ISP unity
ISPUnity is an opensource rubygem/software based multiple internet load balancer and failover.

For mobile internet I recommend dispatch-proxy as you don't configure any setting as in ISP unity. this link comment about a patched linux kernel for inbuilt load balancing you may have a look.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .