Load Balancing
So, I got curious today as I do with most things and I decided to experiment with my laptop. It occurred to me that since it has two network cards (wired, and wifi), that I could potentially load balance the two and get an increased speed overall, so I gave a shot.
My first attempt was bonding the interfaces (via the linux kernel bonding module), but that turned out to fail pretty badly since not only was each interface a different IP, but on a completely different subnet.
After trying that, I focused on more routing table type things. I knew that the routing table had default entries, so I tried to just add two.. but that broke more than it fixed. Then I discovered there is a method to add multiple default gateways. Here’s what I came up with:
ip route add default equalize scope global nexthop via <GATEWAY> dev eth1 weight 2 nexthop via <GATEWAY> dev wlan0 weight 3
Just with that simple code (replacing the devices with your devices, and the gateways with your own gateways), it worked. What linux ended up doing is giving priority to wlan0 (as shown by the weight), and then once that bandwidth got used up, it switched over to eth1. This is perfect. I could be downloading something off a webpage on one, and still be online without any bandwidth bottlenecks on the other.
Aside: For those of you who don’t know how to figure out your gateways, simply to connect to the network and type “route” in a command line. You’ll see a list of different routes. Look for the one that says “default” on the left, and the proper device on the right. In that row you’ll see the listed gateway for that interface.
I doubt this is something I will use every day, but it is nifty, and could come in use eventually.. maybe.
Tags: Linux, Networking