HOWTO – Dual WAN Setup under GNU/Linux

Posted: October 18, 2009 in archlinux, Debian, Slackware

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

Comments
  1. […] but I used "weight" instead of metric. Same idea… I used a guide not entirely unlike this one. Can we pretend I only have 1 NIC if I just don't enable it? At least while I'm trying to get past […]

Leave a reply to [CentOS] Networking woes... "network is unreachable" Cancel reply