OpenWrt > ADSL单线多拨,负载均衡(仅供参考)
前题
- 硬件:路由器,刷入OpenWrt
- 一些背景知识和动手能力
目标效果图
步骤
- 使用SSH 登陆路由器。I.e. ssh root@192.168.2.1
- 运行/usr/bin/duobo。日志类似:
sh: : unknown operand
Killed
Warning: Unable to locate ipset utility, disabling ipset support
* Flushing IPv4 filter table
* Flushing IPv4 nat table
* Flushing IPv4 mangle table
* Flushing IPv4 raw table
* Flushing conntrack table ...
* Populating IPv4 filter table
* Zone 'lan'
* Zone 'wan'
* Rule 'Allow-DHCP-Renew'
* Rule 'Allow-Ping'
* Rule ''
* Rule ''
* Rule ''
* Rule ''
* Forward 'lan' -> 'wan'
* Populating IPv4 nat table
* Zone 'lan'
* Zone 'wan'
* Populating IPv4 mangle table
* Zone 'lan'
* Zone 'wan'
* Populating IPv4 raw table
* Zone 'lan'
* Zone 'wan'
* Set tcp_ecn to off
* Set tcp_syncookies to on
* Set tcp_window_scaling to on
* Running script '/etc/firewall.user'
* Running script '/usr/share/miniupnpd/firewall.include'
* Running script '/usr/share/qos_gargoyle/firewall.include'
! Failed with exit code ___________________________________________________
开始第1次拔号...........
正在并发拔号中.............
等待3秒.............
[]拔[]拔成功, 小于设定的[]拔,将重新拔号... _________________________- 如果没有成功并发多播,根据提示信息调整duobo的内部参数设置,重新运行。分享一些技巧:
number=10 #number是重拔次数,本脚本启动后一共尝试的次数
n=7 #n是几拔,同时发出几拨,理论上设置越大成功概率越大!
ok=2 #ok是拔上几次后退出拔号, 要实现的预期目标
wait=5 #wait time 每次单线多拨失败后,重试的等待时间- 原则:失败多次以后,建议冷重启路由器,多个运行中的脚本会互相冲突,把问题复杂化。
- 多拨失败以后,耐心等上1分钟;很多次的多播成功都是脚本完成以后退出,然后60秒内获取了超过预期的多条链接。
- 把n调到7,这样会虚拟出很多wan接口,根据硬件性能,理论上设置越大成功概率越大!
- 将ok调低一点,比如2。我觉得别太贪心,如果能稳定多播2个ADSL的IP,那其实概率上更折中了稳定性和高负载下的带宽均衡。
- wait的时间我感觉5秒-8秒差不多,这个要看运行日志,做相应调整。
- 看懂程序的原理,根据实际情况调整脚本程序。比如:这个版本的程序是这么多播的,ifup $prefix$i
遗留问题
开始第3次拔号...........
正在并发拔号中.............
等待10秒.............
pppoe-wan Link encap:Point-to-Point Protocol
pppoe-wan3 Link encap:Point-to-Point Protocol
[]拔[]拔成功, 大于或等于设定的[]拨,退出拔号...
Error: an inet address is expected rather than "dev".
iptables v1.4.10: Couldn't load target `zone_wan_notrack':File not found Try `iptables -h' or 'iptables --help' for more information.
iptables v1.4.10: Couldn't load target `zone_wan_nat':File not found Try `iptables -h' or 'iptables --help' for more information.
iptables: No chain/target/match by that name.
iptables v1.4.10: Couldn't load target `zone_wan':File not found Try `iptables -h' or 'iptables --help' for more information.
iptables: No chain/target/match by that name.
iptables: No chain/target/match by that name.
iptables: No chain/target/match by that name.
iptables: No chain/target/match by that name.
iptables: No chain/target/match by that name.
iptables: No chain/target/match by that name.
iptables: No chain/target/match by that name.
Error: an inet address is expected rather than "dev".
iptables v1.4.10: Couldn't load target `zone_wan_notrack':File not found Try `iptables -h' or 'iptables --help' for more information.
iptables v1.4.10: Couldn't load target `zone_wan_nat':File not found Try `iptables -h' or 'iptables --help' for more information.
iptables: No chain/target/match by that name.
iptables v1.4.10: Couldn't load target `zone_wan':File not found Try `iptables -h' or 'iptables --help' for more information.
iptables: No chain/target/match by that name.
iptables: No chain/target/match by that name.
iptables: No chain/target/match by that name.
iptables: No chain/target/match by that name.
iptables: No chain/target/match by that name.
iptables: No chain/target/match by that name.
iptables: No chain/target/match by that name.
Error: an IP address is expected rather than "dev"
192.168.2.0/ dev br-lan proto kernel scope link src 192.168.2.1
221.218.232.1 dev pppoe-wan3 proto kernel scope link src 123.112.248.148
221.218.232.1 dev pppoe-wan proto kernel scope link src 221.218.236.51
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.2.0 0.0.0.0 255.255.255.0 U br-lan
221.218.232.1 0.0.0.0 255.255.255.255 UH pppoe-wan3
221.218.232.1 0.0.0.0 255.255.255.255 UH pppoe-wan
View Error Code
显然这个0.3版本的脚本不完全适用于我的路由器,有时间我需要查查原因。
估计都是关于iptables
有没有大侠探讨一下?
修正了下面版本中的一个错误
line 19:if [ $j -ge $ok ] ;
多拨代码(V0.3)
#!/bin/sh
#modified by muziling v0.
#并发多拨脚本 #number是重拔次数
#n是几拔
#ok是拔上几次后退出拔号
#wait time number=
n=
ok=
wait=
# avoid same with feixiang's N-WAN naming and must start with "wan"
prefix=wan
vthprefix=vth j=$(ifconfig | grep pppoe-wan | wc -l)
if [ "$j" >= "$ok" ] ;
then
echo 已经是[$j]拔了,退出拔号...
exit
fi if [ -f /etc/config/nwannumset ] ;
then
uci set nwannumset.@macvlan_numset[].macvlan_num=
uci commit nwannumset
fi
for i in $( seq $(($n-)))
do
ifname=$prefix$i
ifvth=$vthprefix$i
#ifwan=$(uci get network.wan.ifname)
pppoe_name=$(uci get network.wan.username)
pppoe_pw=$(uci get network.wan.password) if [ $(ip link | grep " ${ifvth}@eth0.2:" | wc -l) == "" ] ;
then
macfac=$(ifconfig | grep eth0. | tr -s " " | cut -d " " -f5 | cut -b -)
mac="$macfac:"$(md5sum /proc/sys/kernel/random/uuid | sed 's/\(..\)/&:/g' | cut -b - | tr [a-f] [A-F])
ip link add link eth0. $ifvth type macvlan
ifconfig $ifvth hw ether $mac
fi # add /etc/config/network
uci delete network.$ifname
uci set network.$ifname=interface
uci set network.$ifname.ifname=$ifvth
#uci set network.$ifname._orig_ifname=eth0.
#uci set network.$ifname._orig_bridge=false
uci set network.$ifname.proto=pppoe
uci set network.$ifname.username=$pppoe_name
uci set network.$ifname.password=$pppoe_pw
uci set network.$ifname.auto=
uci set network.$ifname.defaultroute=
uci set network.$ifname.peerdns=
uci set network.$ifname.pppd_options="plugin rp-pppoe.so syncppp $n" # add /etc/config/dhcp
uci delete dhcp.$ifvth
uci set dhcp.$ifvth=dhcp
uci set dhcp.$ifvth.interface=$ifname
uci set dhcp.$ifvth.ignore= if [ -f /etc/config/nwan ] ;
then
uci delete nwan.$ifname
uci set nwan.$ifname=interface
uci set nwan.$ifname.name=telecom
uci set nwan.$ifname.route=balance
uci set nwan.$ifname.weight=
uci set nwan.$ifname.uptime=0day,0hour,0min
uci commit nwan
fi
done
uci set network.wan.defaultroute=
uci set network.wan.peerdns=
uci set network.wan.pppd_options="plugin rp-pppoe.so syncppp $n"
uci commit network
uci commit dhcp fw_wan_list=$(uci show network |grep =interface |grep -v lan|grep -v loopback |cut -d"." -f2 | awk -F "=" '{printf $1" "}')
uci set firewall.@zone[].network="$fw_wan_list"
uci commit firewall
/etc/init.d/firewall restart for q in $( seq $number )
do
echo
echo ___________________________________________________
echo 开始第$q次拔号...........
killall -q -SIG pppd
if [ "$q" == "" ] ;
then
for i in $( seq $(($n-)))
do
ifup $prefix$i
done
fi echo 正在并发拔号中.............
echo 等待$wait秒.............
sleep $wait j=$(ps | grep pppd | wc -l)
! [ "$j" -ge "$n" ] && ifup ${prefix} ifconfig|grep pppoe
j=$(ifconfig | grep pppoe-wan | wc -l) ! [ "$j" -ge "$ok" ] && echo [$n]拔[$j]拔成功, 小于设定的[$ok]拔,将重新拔号...
[ "$j" -ge "$ok" ] && echo [$n]拔[$j]拔成功, 大于或等于设定的[$ok]拨,退出拔号... if [ "$j" -ge "$ok" ] ;
then
for i in $( seq $(($n-)))
do
if [ "$i" == "" ] ;
then
interface=wan
else
interface=$prefix$i
fi
if [ $(ifconfig | grep "pppoe-$interface " | wc -l) == "" ] ;
then
ifdown $interface
fi
done
break
fi
done
# kill ddns sleep and re-check wan ip change
killall sleep j=$(ifconfig | grep pppoe-wan | wc -l)
! [ "$j" -ge ] && reboot #ppoename=$(ifconfig |grep 'ppoe-' |awk '{print substr($1,7)}'|tr '\n' ' ')
ppoename=$(ifconfig |grep 'ppoe-' |awk '{print $1}'|tr '\n' ' ')
i=
vias=""
for wan_ifname in $ppoename
do
vias="$vias nexthop via $wan_ip dev $wan_ifname weight 1 "
let "rt=100+$i"
i=$(($i+))
ip route flush table $rt
ip route add default via $wan_ip dev $wan_ifname table $rt
ip route add table $rt to $(ip route | grep br-lan) if [ $(iptables -t nat -vxnL POSTROUTING | grep -c " $wan_ifname ") == "" ] ;
then
iptables -t raw -A PREROUTING -i $wan_ifname -j zone_wan_notrack
iptables -t nat -A PREROUTING -i $wan_ifname -j zone_wan_prerouting
iptables -t nat -A POSTROUTING -o $wan_ifname -j zone_wan_nat
iptables -t filter -A forward -i $wan_ifname -j zone_wan_forward
iptables -t filter -A input -i $wan_ifname -j zone_wan
iptables -t filter -A zone_wan_ACCEPT -o $wan_ifname -j ACCEPT
iptables -t filter -A zone_wan_ACCEPT -i $wan_ifname -j ACCEPT
iptables -t filter -A zone_wan_DROP -o $wan_ifname -j DROP
iptables -t filter -A zone_wan_DROP -i $wan_ifname -j DROP
iptables -t filter -A zone_wan_REJECT -o $wan_ifname -j reject
iptables -t filter -A zone_wan_REJECT -i $wan_ifname -j reject
fi
iptables -A PREROUTING -t mangle -i $wan_ifname -j MARK --set-mark $rt
iptables -t mangle -A zone_wan_MSSFIX -o $wan_ifname -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
ip rule add fwmark $rt table $rt prio $rt
done
ip route del default
ip route add default scope global $vias
ip route flush cache
ip route list
route -n
root@OpenWrt:~#
(duobo)
修订版(V0.3.1)
#!/bin/sh
#modified by muziling v0.
#并发多拨脚本
#modified by carl v0.3.1 (修正一处bug,改善友好提示信息) #number是重拔次数,本脚本启动后一共尝试的次数
#n是几拔,同时发出几拨,理论上设置越大成功概率越大!
#ok是拔上几次后退出拔号, 要实现的预期目标
#wait time 每次单线多拨失败后,重试的等待时间 number=
n=
ok=
wait=
# avoid same with feixiang's N-WAN naming and must start with "wan"
prefix=wan
vthprefix=vth j=$(ifconfig | grep pppoe-wan | wc -l)
if [ $j -ge $ok ] ;
then
echo 已经是[$j]拔了,退出拔号程序。
exit
fi if [ -f /etc/config/nwannumset ] ;
then
uci set nwannumset.@macvlan_numset[].macvlan_num=
uci commit nwannumset
fi for i in $( seq $(($n-)))
do
ifname=$prefix$i
ifvth=$vthprefix$i
#ifwan=$(uci get network.wan.ifname)
pppoe_name=$(uci get network.wan.username)
pppoe_pw=$(uci get network.wan.password) if [ $(ip link | grep " ${ifvth}@eth0.2:" | wc -l) == "" ] ;
then
macfac=$(ifconfig | grep eth0. | tr -s " " | cut -d " " -f5 | cut -b -)
mac="$macfac:"$(md5sum /proc/sys/kernel/random/uuid | sed 's/\(..\)/&:/g' | cut -b - | tr [a-f] [A-F])
ip link add link eth0. $ifvth type macvlan
ifconfig $ifvth hw ether $mac
echo 更换MAC完毕$ifvth.
fi # add /etc/config/network
uci delete network.$ifname
uci set network.$ifname=interface
uci set network.$ifname.ifname=$ifvth
#uci set network.$ifname._orig_ifname=eth0.
#uci set network.$ifname._orig_bridge=false
uci set network.$ifname.proto=pppoe
uci set network.$ifname.username=$pppoe_name
uci set network.$ifname.password=$pppoe_pw
uci set network.$ifname.auto=
uci set network.$ifname.defaultroute=
uci set network.$ifname.peerdns=
uci set network.$ifname.pppd_options="plugin rp-pppoe.so syncppp $n" # add /etc/config/dhcp
uci delete dhcp.$ifvth
uci set dhcp.$ifvth=dhcp
uci set dhcp.$ifvth.interface=$ifname
uci set dhcp.$ifvth.ignore= if [ -f /etc/config/nwan ] ;
then
uci delete nwan.$ifname
uci set nwan.$ifname=interface
uci set nwan.$ifname.name=unicom
uci set nwan.$ifname.route=balance
uci set nwan.$ifname.weight=
uci set nwan.$ifname.uptime=0day,0hour,0min
uci commit nwan
fi
done uci set network.wan.defaultroute=
uci set network.wan.peerdns=
uci set network.wan.pppd_options="plugin rp-pppoe.so syncppp $n"
uci commit network
uci commit dhcp fw_wan_list=$(uci show network |grep =interface |grep -v lan|grep -v loopback |cut -d"." -f2 | awk -F "=" '{printf $1" "}')
uci set firewall.@zone[].network="$fw_wan_list"
uci commit firewall
/etc/init.d/firewall restart for q in $( seq $number )
do
echo
echo ___________________________________________________
echo 开始第$q次拔号...........
killall -q -SIG pppd
if [ "$q" == "" ] ;
then
for i in $( seq $(($n-)))
do
ifup $prefix$i
done
fi echo 正在并发拔号中.............
echo 等待$wait秒.............
sleep $wait j=$(ps | grep pppd | wc -l)
! [ "$j" -ge "$n" ] && ifup ${prefix} ifconfig | grep pppoe
j=$(ifconfig | grep pppoe-wan | wc -l) ! [ "$j" -ge "$ok" ] && echo [$n]拔[$j]拔成功, 小于设定的[$ok]拔,将重新拔号...
[ "$j" -ge "$ok" ] && echo [$n]拔[$j]拔成功, 大于或等于设定的[$ok]拨,退出拔号... if [ "$j" -ge "$ok" ] ;
then
for i in $( seq $(($n-)))
do
if [ "$i" == "" ] ;
then
interface=wan
else
interface=$prefix$i
fi
if [ $(ifconfig | grep "pppoe-$interface " | wc -l) == "" ] ;
then
ifdown $interface
fi
done
break
fi
done # done/tried all tring times $number # kill ddns sleep and re-check wan ip change
killall sleep # reboot the machine if failed tried times
#sleep $wait
j=$(ifconfig | grep pppoe-wan | wc -l)
! [ "$j" -gt ] && reboot echo ___________________________________________________
echo 开始N-WAN负载均衡功能...
#ppoename=$(ifconfig |grep 'ppoe-' |awk '{print substr($1,7)}'|tr '\n' ' ')
ppoename=$(ifconfig|grep 'ppoe-' |awk '{print $1}'|tr '\n' ' ')
i=
vias=""
for wan_ifname in $ppoename
do
vias="$vias nexthop via $wan_ip dev $wan_ifname weight 1 "
let "rt=100+$i"
i=$(($i+))
ip route flush table $rt
#REMOVE ERROR
ip route add default via $wan_ip dev $wan_ifname table $rt
ip route add table $rt to $(ip route | grep br-lan) if [ $(iptables -t nat -vxnL POSTROUTING | grep -c " $wan_ifname ") == "" ] ;
then
#REMOVE ERROR
iptables -t raw -A PREROUTING -i $wan_ifname -j zone_wan_notrack
iptables -t nat -A PREROUTING -i $wan_ifname -j zone_wan_prerouting
#REMOVE ERROR
iptables -t nat -A POSTROUTING -o $wan_ifname -j zone_wan_nat
iptables -t filter -A forward -i $wan_ifname -j zone_wan_forward
#REMOVE ERROR
iptables -t filter -A input -i $wan_ifname -j zone_wan
iptables -t filter -A zone_wan_ACCEPT -o $wan_ifname -j ACCEPT
iptables -t filter -A zone_wan_ACCEPT -i $wan_ifname -j ACCEPT
iptables -t filter -A zone_wan_DROP -o $wan_ifname -j DROP
iptables -t filter -A zone_wan_DROP -i $wan_ifname -j DROP
iptables -t filter -A zone_wan_REJECT -o $wan_ifname -j reject
iptables -t filter -A zone_wan_REJECT -i $wan_ifname -j reject
fi iptables -A PREROUTING -t mangle -i $wan_ifname -j MARK --set-mark $rt
iptables -t mangle -A zone_wan_MSSFIX -o $wan_ifname -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
ip rule add fwmark $rt table $rt prio $rt
done ip route del default echo ___________________________________________________
echo 下面执行ip route add default scope global $vias
ip route add default scope global $vias ip route flush cache echo ___________________________________________________
echo 下面输出ip route list
ip route list echo ___________________________________________________
echo 下面输出route -n
route -n
参考文献
OpenWrt For AR71xx系列 ar2 Tr 脱机 N-WAN r48549
自己动手 4530R 脱机 Samba U-BOOT 多拨(11-04更新部分问题说明,请看2楼)
[0916更新]WR703N WR720N 及其他各类 OpenWRT类路由实现一号多拨带宽叠加教程
OpenWrt > ADSL单线多拨,负载均衡(仅供参考)的更多相关文章
- Unity上一页下一页切换功能实现源码(仅供参考)
在做项目时我们有时需要实现切换上一页下一页图片,切换上一首下一首歌曲等等类似的功能.这里写了个简单的实现源码(仅供参考),要是有更好的方法欢迎提出来,共同进步~ 以切换上一页下一页图片为例: usin ...
- Ubuntu 12.04 分区方案(仅供参考)
Ubuntu 12.04 分区方案(仅供参考) 总空间大小:50G 目录 建议大小 实际大小 格式 描述 / 10G~20G 10G ext4 根目录 swap <2048M 1G swap ...
- VSS的运用小内容(针对于vs2008版本)(小的问题都是,仅供参考--只针对于菜鸟级的)
自己开始接触vss 的时候有些小的习惯没有很好的养成,下面的有关VSS内容都是简单的迁入迁出的问题,(仅供参考) 1.文件的迁入迁出:(.txt..xlsx..doc) a:文件的覆盖问题: 对于文件 ...
- mysql 千万级数据查询效率实践,分析 mysql查询优化实践--本文只做了一部分,仅供参考
数据量, 1300万的表加上112万的表 注意: 本文只做了部分优化,并不全面,仅供参考, 欢迎指点. 请移步tim查看,因为写的时候在tim写的,粘贴过来截图有问题,就直接上链接了. https ...
- jdk1.8+SpringAOP注解报java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut select错误的不知原因的解决办法[仅供参考]
先说办法:如果Aspectweaver-1.*.*jar这三个包版本比较低, 比如1.5.0这一层次的,可以找版本高一点的包替换低版本的包,问题可以得到解决 jar包的下载地址:https://mvn ...
- normalizr实践使用(个人总结,仅供参考)
# normalizr实践使用 原数据 (自编数据,本数据仅供参考) var aaaObj ={ "id" : "0000000000000000000000000000 ...
- 第二步 (仅供参考) sencha touch 使用cmd打包apk
最新版本的cmd可以直接将sencha touch项目打包成本地应用,不过还有很多不足,本文仅供参考 通过sencha app build native命令可以直接将项目打包成本地应用,不过在命令运行 ...
- 2019第十届蓝桥杯C++B组题解(赛后重写的,不确保答案正确性,仅供参考)
先说一下这次的感受吧,我们考场比较乱,开始比赛了,还有的电脑有故障,(向这些人发出同情),第一次认真参加比赛,真正比赛的时候感觉没有那么正式,很乱,各种小问题,(例如博主就没找到题目在哪里,找到后又不 ...
- 分享分享JavaScript100例-仅供参考
最近一直在做项目,分享下以前收集的Javascript100例,仅供参考. http://files.cnblogs.com/52net/JavaScript100例.zip
随机推荐
- UWP&WP8.1 重新绘制图片 WriteableBitmap用法 图片转byte[]数组,byte[]数组转图片
---恢复内容开始--- WriteableBitmap 是UWP和WP8.1绘制图片的,重组图片的最重要方法.方法较为简单,方法多样性. 通过查看文档,WriteableBitmap的继承性是 ...
- Tyrion中文文档(含示例源码)
Tyrion是一个基于Python实现的支持多个WEB框架的Form表单验证组件,其完美的支持Tornado.Django.Flask.Bottle Web框架.Tyrion主要有两大重要动能: 表单 ...
- ssh无密码通信设置
■单向登陆配置:1.在本地机器中的~/.ssh/目录下执行下命令#ssh-keygen -t dsa然后全部回车,采用默认值.生成了一对密钥,id_dsa和id_dsa.pub,存放在用户目录的~/. ...
- 【原创】JMeter学习(三十七)Jmeter录制手机app脚本
环境准备: 1.手机 2.wifi 3.Jmeter 具体步骤: 1.启动Jmeter: 2.“测试计划”中添加“线程组”: 3.“工作台”中添加“HTTP代理服务器”: 4.配置代理服务器:Gl ...
- RDIFramework.NET -.NET快速信息化系统开发整合框架 【开发实例 EasyUI】之产品管理(WebForm版)
RDIFramework.NET—.NET快速开发整合框架 [开发实例]之产品管理(WebForm版) 接上篇:RDIFramework.NET (.NET快速信息化系统开发整合框架) [开发实例]之 ...
- 开始学习c语言
学习c语言的第一篇博客,心里的感觉说不出来,不知道能不能坚持下去,我是一名工作了差不多2年的phper,其实我本来是想学习数据结构和算法的,但是尼玛这年头那些书的例子都不是php,动不动就是c,jav ...
- PostgreSQL 磁盘使用大小监控
表大小信息 postgres=# SELECT *, pg_size_pretty(total_bytes) AS totalpostgres-# , pg_size_pretty(index_byt ...
- linux-------------计划任务crond:如何创建linux里面的计划任务
1.centos下安装crond [root@localhost /]# yum -y install vixie-cron [root@localhost /]# yum -y install cr ...
- Windows Phone 十八、加速计
加速度传感器 手机的加速度传感器工作时是通过 x.y.z 三个轴的偏移来计算的 在代码基本的 API 主要集中在 Accelerometer 类型中 主要是使用该类型的对象捕获 ReadingChan ...
- SSH整合报错:org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped[......]
非常诡异的报错,信息如下:org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped [select count(* ...