load_balance.pl Load balance a host or network across two or more Internet connections.
# get status report % sudo load_balance.pl -s # start link monitoring and load balance across all up ISPs % sudo load_balance.pl # load balance across "CABLE" and "DSL" only % sudo load_balance.pl CABLE DSL # print out the routing and firewall commands that would # ordinarily be executed % load_balance.pl -d
This script can be run on a Linux-based home router or standalone computer to load balance your network connection among two or more Internet Service Providers (ISPs). When aggregated across multiple simultaneous connections, you will achieve the sum of the bandwidth of all ISP connections. In addition, the script will continuously ping each outgoing interface and adjust routing in the event that one or more ISPs become unavailable. This provides failover.
The script can be called with no arguments, in which case it will mark all known ISPs as being up and launch the "lsm" link monitor to test each one periodically for connectivity. It can also be called with one or more symbolic names for ISP connections, as defined in load_balance.conf. These will be forced "up" and other ISP connections will be forced "down".
Other command-line options allow you to view the status of your ISP connections, kill a running lsm, and more.
Generally this script must be run as root, since it alters the routing table and firewall rules.
For full installation and configuration instructions, please see http://lstein.github.io/Net-ISP-Balance/.
Each command-line option can be abbreviated or used in long-form.
--debug, -d Turn on debugging. In this mode, no firewall or routing commands will be executed, but instead will be printed to standard output for inspection. --verbose, -v Verbose output. Echo all route and iptables commands to STDERR before executing them. --status,-s Print current status of each monitored ISP interface to STDOUT. --kill,-k Kill any running lsm process. --help,-h Print this message.
This section describes common usage patterns. Note that load_balance.pl must always be run as root.
% sudo load_balance.pl
% sudo load_balance.pl CABLE
% sudo load_balance.pl up CABLE
% sudo load_balance.pl down CABLE
% sudo load_balance.pl -s
% sudo load_balance.pl -k
% sudo load_balance.pl -d
This section gives locations of important files.
/etc/network/balance.conf # Main configuration file /etc/network/balance/firewall/ # Additional firewall rules /etc/network/balance/routes/ # Additional routing rules
/etc/sysconfig/network-scripts/balance.conf # Main configuration file /etc/sysconfig/network-scripts/balance/firewall/ # Additional firewall rules /etc/sysconfig/network-scripts/balance/routes/ # Additional routing rules
balance.conf is the main configuration file. It defines the interfaces connected to the ISPs and to the LAN (if running on a router). Here is a typical example:
#service device role ping-ip CABLE eth0 isp 184.108.40.206 DSL eth1 isp 220.127.116.11 LAN eth2 lan # name=value pairs define lsm configuration variables email@example.com max_packet_loss=10 min_packet_loss=5
There are two parts of the configuration file. The first part, which is required, is a four-column table that defines interfaces to be monitored.
The first column is a service name that is used to bring up or down the needed routes and firewall rules.
The second column is the name of the network interface device that connects to that service.
The third column is either "isp" or "lan". There may be any number of these. The script will load balance traffic across all ISPs, and will act as a firewall between the LAN (if any) and the Internet. You do not need to have a "lan" entry if this is a standalone host.
The fourth and last column is the IP address of a host that can be periodically pinged to test the integrity of each ISP connection. If too many pings failed, the service will be brought down and all traffic routed through the remaining ISP(s). The service will continue to be monitored and will be brought up when it is once again working. Choose a host that is not likely to go offline for reasons unrelated to your network connectivity, such as google.com, or the ISP's web site.
The second (optional) part of the configuration file is a series of name=value pairs that allow you to customize the behavior of lsm, such as where to send email messages when a link's status changes. Please see http://lsm.foobar.fi/ for the comprehensive list.
Lincoln Stein, firstname.lastname@example.org
Copyright (c) 2014 Lincoln D. Stein
This package and its accompanying libraries is free software; you can redistribute it and/or modify it under the terms of the GPL (either version 1, or at your option, any later version) or the Artistic License 2.0.