Introduction

This procedure outlines a very simple round-robbin procedure via IProute. This article is aimed at a computer with multiple static links to internet sources. After the installatin is complete IProute will automatically switch from one external network to another for each connection made, allowing for fail-over, and increased down/upload speeds with torrent clients.

Setup

Ubuntu comes with iproute already installed, but it needs configuration to work with multiple networks. IProute pulls its default configuration from /etc/network/interfaces. Any "manual" changes to IProute that are not marked in the interfaces file will be reverted. IProute checks the current configuration periodically, and resets them to default if they are not marked. The routes will also be destroyed on a restart.

First take note of your current hardware configuration. Gather information such as the device names (eth1, wlan0, eth0, etc), gateways, IP addresses, etc. {{{ip addr ip route show table all ip rule}}}.

backup your current configuration.

sudo cp /etc/network/interfaces /etc/network/interfaces.backup

sudo gedit /etc/network/interfaces

Example and Explanation

For example, configuration instructions.

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
        address 192.168.1.2
        netmask 255.255.255.0
        post-up ip route add 192.168.1.0/24 dev eth0 src 192.168.1.2 table 1
        post-up ip route add default via 192.168.1.1 table 1
        post-up ip route append 192.168.1.0/24 dev eth0 src 192.168.1.2
        post-up ip rule add from 192.168.1.2 table 1
        post-down ip rule del from 192.168.1.2 table 1

auto eth1
iface eth1 inet static
        address 192.168.2.5
        netmask 255.255.255.0
        post-up ip route add 192.168.2.0/24 dev eth1 src 192.168.2.5 table 2
        post-up ip route add default via 192.168.2.1 table 2 protocol 4
        post-up ip route append 192.168.2.0/24 dev eth1 src 192.168.2.5
        post-up ip rule add from 192.168.2.5 table 2
        post-down ip rule del from 192.168.2.5 table 2

auto wlan0
iface wlan0 inet static
        wireless-essid homewireless
        address 19.168.3.4
        netmask 255.255.255.0
        post-up ip route add 192.168.3.0/24 dev wlan0 src 192.168.3.4 table 3
        post-up ip route add default via 192.168.3.1 table 3 protocol 4
        post-up ip route append 192.168.3.0/24 dev wlan0 src 192.168.3.4
        post-up ip rule add from 192.168.3.4 table 3
        post-down ip rule del from 192.168.3.4 table 3

This configuration assumes 3 seperate networks are present. 192.168.1.1, 192.168.2.1, and 192.168.3.1 are all gateways attached to seperate external networks. 192.168.1.2, 192.168.2.5, and 192.168.3.4 are the interface IP addresses. After you make these changes you will need to restart the computer, before using the new configuration.

Applying the IProute

sudo ip route add default scope global nexthop via 192.168.1.1 dev eth0 weight 1 nexthop via 192.168.2.1 dev eth1 weight 1 nexthop via 192.168.3.1 dev wlan0 weight 1

This command creates the default gateway IProute will give to the system. The system will first use 192.168.1.1, then 192.168.2.1 for the second connection, and so on.

This isn't a very efficient load balancing scheme, the system can't keep the interfaces "balanced," but if you have a few external networks you wish to get usage out of this is one method. This method works well with the torrent protocol, because the connections to all the peers are spread out over the interfaces, allowing for increased download and upload speeds.

IProuteRoundRobbin (last edited 2011-05-16 15:53:30 by jengelh)