This article presents a reasonably straightforward approach to using two independent internet connections on one system. While the examples are for multiple ethernet connections, some minor modifications could apply the methods to a mixed ethernet/wireless system.
Note: The timestamp on this article may seem unusual. This was written before Slack/Tux was purchased, and relocated to this site, where it was more fitting.
Update 2008-05-23: The concepts outlined here also work with virtual interfaces (aliases). This can be used to configure multiple IPs on a single interface. While this doesn’t have a lot of practical advantages for desktop users, there is significant value for servers. Thanks to Mickael Maddison for testing this.
Keep in mind that multiple virtual interfaces would still be a single physical connection though, so the maximum throughput would remain the same. This could also be used to allow a single ethernet card to span multiple subnets.
Requirements
- PC or router running GNU/Linux
- Multiple WAN Connections, either from the same ISP or different ones
- A dedicated ethernet adapter for each connection.
Update 2008-05-23: It should be noted that this example requires all involved interfaces to be configured already. It assumes IPs have been assigned without using DHCP, though minor changes could account for that. The interfaces must also be active (not stopped). Thanks for Mickael Maddison pointing out that I hadn’t mentioned that.
Example Setup
In this example, I have a 10MBit Cable connection via Shaw on eth1, and a 6MBit ADSL connection via TELUS on eth2.
- eth1 - IP 192.168.254.100 / Gateway 192.168.254.1
- eth2 - IP 192.168.1.100 / Gateway 192.168.1.254
Simple Configuration
First, we need to add two lines to /etc/iproute2/rt_tables
1 Shaw
2 TELUS
And then set up the routing for those tables.
# ip route add 192.168.254.0/24 dev eth1 src 192.168.254.100 table Shaw
# ip route add default via 192.168.254.1 table Shaw
# ip route add 192.168.1.0/24 dev eth2 src 192.168.1.100 table TELUS
# ip route add default via 192.168.1.254 table TELUS
# ip rule add from 192.168.254.100 table Shaw
# ip rule add from 192.168.1.100 table TELUS
Set up evenly weighted round-robin routing for the interfaces.
# ip route add default scope global nexthop via 192.168.254.1 dev eth1 weight 1 nexthop via 192.168.1.254 dev eth2 weight 1
Fixes and workarounds
In the event that you receive a RTNETLINK answers: File exists error, replace the previous entry with…
# ip route append default scope global nexthop via 192.168.254.1 dev eth1 weight 1 nexthop via 192.168.1.254 dev eth2 weight 1
Then remove the earlier route:
# ip route del
Alternatively, omiting both
# ip route add default via 192.168.254.1 table Shaw
# ip route add default via 192.168.1.254 table TELUS
should prevent this as well.
Slightly more complex configurations
In addition to the basic setup here, the interfaces can be weighted differently, to favour one over the other (useful if one is a larger pipe, as in my setup here).
# ip route append default scope global nexthop via 192.168.254.1 dev eth1 weight 5 nexthop via 192.168.1.254 dev eth2 weight 3
In the case of IP-bound services (example: a GigaNews account, which does not allow simultaneous connections from different IPs), a static route is simple to configure:
# ip route add 216.196.97.131 via 192.168.254.1
If one of your ISP blocks DNS queries from non-subscribers, then you will need to ensure that your primary DNS server is ISP-agnostic. OpenDNS is a great solution for this. Add the appropriate entries to /etc/resolv.conf
nameserver 208.67.222.222
nameserver 208.67.220.220
Sources





