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.
ipvs
, but with a different goal -- my guess isipvs
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.