Jump to content

This is the support site for Andrews & Arnold Ltd, a UK Internet provider. Information on these pages is generally for our customers but may be useful to others, enjoy!

Router - Linux upload bonding using policy routing: Difference between revisions

syntaxhighlight
(Created page with "I'm using PPP on the Linux box - in my case via a Solos ADSL card, but this will also work using PPPoE. First, for convenience, name your extra routing tables by editing <tt>...")
 
(syntaxhighlight)
 
(7 intermediate revisions by 2 users not shown)
<indicator name="Front">[[File:Menu-bonding.svg|link=:Category:Bonding|30px|Back up to the Bonding Page]]</indicator>
 
I'm using PPP on the Linux box - in my case via a Solos ADSL card, but this will also work using PPPoE.
 
 
Add a script in <tt>/etc/ppp/ip-up.d</tt> and in <tt>/etc/ppp/ipv6-up.d</tt> to put the routes in the per-interface tables:
<syntaxhighlight lang=bash>
<pre>
#!/bin/bash
# ip-up.d/set-routes
 
ip route replace default dev ${PPP_IFACE} table ${PPP_IFACE}
</syntaxhighlight>
 
<syntaxhighlight lang=bash>
#!/bin/bash
# ipv6-up.d/set-routes
 
ip -6 route replace default dev ${PPP_IFACE} table ${PPP_IFACE}
</syntaxhighlight>
</pre>
 
Add a script in <tt>/etc/ppp/ip-down.d</tt> and in <tt>/etc/ppp/ipv6-down.d</tt> to remove the per-interface routes when the PPP link goes down:
<syntaxhighlight lang=bash>
#!/bin/bash
# ip-down.d/remove-routes
 
ip route flush table ${PPP_IFACE}
</syntaxhighlight>
 
<syntaxhighlight lang=bash>
#!/bin/bash
# ipv6-down.d/remove-routes
 
ip -6 route flush table ${PPP_IFACE}
</syntaxhighlight>
 
Run the following script on boot:
 
<syntaxhighlight lang=bash>
<pre>
#!/bin/bash
 
ip rule add from all table ppp1 prio 50001
ip -6 rule add from all table ppp1 prio 50001
</syntaxhighlight>
</pre>
 
This uses iproute2's ip command to set up policy routing rules; the first set give you a firewall mark per line. (rules at prio 40000 and 40001). The last block (rules at 50000 and 50001) ensureserves thattwo even if you fail to set firewall marks for upstream line choice, your packets will still get out - it will just be non-optimal.purposes:
# It ensures that packets that are marked for routing via a dead line are passed onto the other line
# It provides a fallback if you forget to add firewall marks in PREROUTING for some packets.
 
Finally, apply firewall marks in PREROUTING to choose your load balancing policy. For example, to simply load balances by alternating packets on each line:
 
<syntaxhighlight lang=bash>
<pre>
for IPT in iptables ip6tables
do
$IPT -A PREROUTING ! -i ppp+ -m statistic --mode nth --every 2 --packet 1 -j MARK --set-mark 2
done
</syntaxhighlight>
</pre>
 
[[Category:3rd Party Routers|Linux]]
simply load balances by alternating packets on each line.
[[Category:Bonding Configuration|Linux]]
editor
698

edits