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
mNo edit summary
(syntaxhighlight)
 
 
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>
</pre>
 
<syntaxhighlight lang=bash>
<pre>
#!/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>
<pre>
#!/bin/bash
# ip-down.d/remove-routes
 
ip route flush table ${PPP_IFACE}
</syntaxhighlight>
</pre>
 
<syntaxhighlight lang=bash>
<pre>
#!/bin/bash
# ipv6-down.d/remove-routes
 
ip -6 route flush table ${PPP_IFACE}
</syntaxhighlight>
</pre>
 
 
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) serves two purposes:
# 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>
 
simply load balances by alternating packets on each line.
 
 
[[Category:3rd Party Routers|Linux]]
editor
698

edits