> computerish

Wednesday, 22 August 2007

the multihomed house

I mentioned in a previous post that I had, for a time, both DSL and cable internet; but I didn't go into detail about how had my router hooked up to both lines, routing traffic over them concurrently. It's time to rectify that omission. Although this multihomed configuration did not last long, I'm still using pretty much the same tools/config to take advantage of the multiple IP addresses I've managed to snag from my ISP.

This is how I've setup my Linux 2.6-based router using 'ip route', 'ip rule' and iptables to get WAN-bound traffic coming from the local subnets to exit one of several WAN links depending on different criteria; mostly source IP.
You create multiple routing tables (one for each WAN interface) and then add rules to send traffic to the correct table based on source IP, or packet marks that you set with iptables which allow you even greater flexibility (eg. choose outbound interface by destination port).
To set it all up you use something like this:


(assuming you don't already have a default route in the 'main' table)
ip route 24.0.0.0/24 dev wan0 table 10
ip route default via 24.0.0.1 dev wan0 table 10
ip route 74.0.0.0/24 dev wan1 table 11
ip route default via 74.0.0.1 dev wan1 table 11

ip rule add from 10.0.0.0/24 table 10
ip rule add from 192.168.0.0/24 table 11
-or-
ip rule from all fwmark 10 table 10
ip rule from all fwmark 11 table 11

iptables -t nat -A POSTROUTING -o wan0 -j SNAT --to-source 24.0.0.55
iptables -t nat -A POSTROUTING -o wan1 -j SNAT --to-source 74.0.0.66
-and for the fwmark option-
iptables -t mangle -A PREROUTING -s 10.0.0.0/24 -j CONNMARK --set-mark 10
iptables -t mangle -A PREROUTING -s 192.168.0.0/24 -j CONNMARK --set-mark 11


This is a simplified example, as I've used as many as five WAN links and I have over a dozen local subnets to deal with.

Trackbacks

    No Trackbacks

Comments

Display comments as (Linear | Threaded)

    No comments


Add Comment


Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA 1CAPTCHA 2CAPTCHA 3CAPTCHA 4CAPTCHA 5