Loadbalance traffic over multiple ADSL lines
- 2015-07 ADSL line quality recommendations.
SNR should be at least 6dB, but preferably higher than 9 or 10dB.
Attenuation/resistance should be below 55dB, but preferably lower than 45dB.
- 2015-04 Add routing table and ppp notes., Add cron-script to keep adsl lines up.
- 2013-06 feature removed in kernel 3.6 for route caching.
- This causes per packet load-balancing over equal cost routes, breaking ADSL links, as outside ip changes in middle of tcp session.
- Main setup script, used in firehol.conf bash config file.
- What it does is mark statefull sesion with exit interface and then use same interface for all other packets.
- This works in conjunction with routing based on fw-mark.
##(c) Pieter E Smit 2013 - GPL3.
##(c) 2015 Add notes on creation of routing tables.
#Note1: create tables e.g. ppp1, ppp2 in /etc/iproute2/rt_tables
#Note2: define pppX interface number with "unit X" option in ppp config.
##Routing
ipt=iptables
prio=1
#Set connmark depending on dsl interface used.
for i in {1..5}; do
int="ppp$i"
mark="$i"
$ipt -t mangle -I POSTROUTING 1 -o $int -m state --state NEW -j CONNMARK --set-mark $mark
$ipt -t mangle -I PREROUTING 1 -i $int -m state --state NEW -j CONNMARK --set-mark $mark
$ipt -t mangle -I INPUT 1 -i $int -m state --state NEW -j CONNMARK --set-mark $mark
#Update route
#Also done in ppp ip-up script as we cant add route if int does not exist.
ip route replace default dev $int table $int 2> /dev/null
##THIS is LOCAL lan route## Update to local subnet.
ip route replace 192.168.0.0/16 dev eth0 table $int
#set routing rule to pick routing table depending on fwmark, table name=$int see /etc/iproute2/rt_tables
ip rule del fwmark $mark table $int 2> /dev/null
ip rule add fwmark $mark table $int prio $prio
#
done
$ipt -t mangle -I PREROUTING 1 -j CONNMARK --restore-mark
#Debug command
# iptables -L -nv -t mangle- ppp/if-up and if-down script to add and remove routes as adsl go up and down.
#(c)Pieter E Smit 2013 GPL3 #adds all ppp interfaces to default route. command="ip route replace default scope global" for i in `ifconfig | grep ppp | cut -d " " -f 1` ; do command="$command nexthop dev $i weight 1" ; #Add default route to each ppp interface's own routing table. /etc/iproute2/rt_table ip route replace default dev $i table $i done $command
- line added to cron to test and enable adsl if down. Currently set to test every hour.
# crontab -e 10 */1 * * * if /sbin/ifconfig ppp1 > /dev/null; then true ; else /sbin/ifup --force ppp1 ; fi 20 */1 * * * if /sbin/ifconfig ppp2 > /dev/null; then true ; else /sbin/ifup --force ppp2 ; fi 30 */1 * * * if /sbin/ifconfig ppp3 > /dev/null; then true ; else /sbin/ifup --force ppp3 ; fi 40 */1 * * * if /sbin/ifconfig ppp4 > /dev/null; then true ; else /sbin/ifup --force ppp4 ; fi 50 */1 * * * if /sbin/ifconfig ppp5 > /dev/null; then true ; else /sbin/ifup --force ppp5 ; fi
...
