找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 13030|回复: 0

OpenWrt配置单线多播的例子

[复制链接]
发表于 2014-10-17 16:39:55 | 显示全部楼层 |阅读模式
先说明一下!此教程只适用于OpenWrt的Snapshot版和 Attitude Adjustment12.09版!其他版本请自行测试!此教程可能会涉及到一些破坏路由器配置文件的行为!请谨慎操作!一. 配置准备环境
1.以上提到的两个版本的OpenWrt
2.pppo.sh并发拨号脚本
3.配置路由器:TP-LINK 842nd v2
4.用到的插件:libc ip iptables iptables-mod-conntrack-extra iptables-mod-ipopt kmod-macvlan
二. 配置部分
1.安装辅助插件
opkg update
opkg install libc ip iptables iptables-mod-conntrack-extra iptables-mod-ipopt
opkg insatll kmod-macvlan

2.network文件的配置
[Bash shell] 纯文本查看 复制代码
vi /etc/config/network

config interface 'loopback'
    option ifname 'lo'
    option proto 'static'
    option ipaddr '127.0.0.1'
    option netmask '255.0.0.0'

config interface 'lan'
    option ifname 'eth0'
    option type 'bridge'
    option proto 'static'
    option ipaddr '192.168.1.1'
    option netmask '255.255.255.0'

config interface 'wan'
    option ifname 'eth1'
    option _orig_ifname 'eth1'
    option _orig_bridge 'false'
    option proto 'pppoe'
    option username 'xxxxxxxxxx'
    option password '123456'

config interface 'wan1'  #这步起都是模拟出来的WAN口
    option ifname 'vth1'
    option _orig_ifname 'eth1' #WAN口网卡
    option _orig_bridge 'false'
    option proto 'pppoe'
    option username 'xxxxxxxxx'
    option password '123456'

config interface 'wan2'
    option ifname 'vth2'
    option _orig_ifname 'eth1'
    option _orig_bridge 'false'
    option proto 'pppoe'
    option username 'xxxxxxxx'
    option password '123456'

config interface 'wan3'
    option ifname 'vth3'
    option _orig_ifname 'eth1'
    option _orig_bridge 'false'
    option proto 'pppoe'
    option username 'xxxxxxxx'
    option password '123456'

config switch
    option name 'eth0'
    option reset '1'
    option enable_vlan '1'

config switch_vlan
    option device 'eth0'
    option vlan '1'
    option ports '0 1 2 3 4'

此配置文件依据自己的情况进行配置
三. 重启执行并发拨号脚本
[AppleScript] 纯文本查看 复制代码
#!/bin/sh

#number是重拔次数
#n是几拔
#ok是拔上几次后退出拔号
#wait time

number=10000
n=4
ok=2 #这个可以任意修改!我这里只修改2拨后停止!
wait=20


   for i in $( seq 1 $(($n-1)))
   do
        interface=wan$i
        ifname=vth$i
        
        if [ $(ip link | grep " ${ifname}@eth1:" | wc -l) == "0" ] ;
        then
            macfac=$(ifconfig | grep eth1 | tr -s " " | cut -d " " -f5 | cut -b 1-8)
            mac="$macfac:"$(md5sum /proc/sys/kernel/random/uuid | sed 's/\(..\)/&:/g' | cut -b 1-8 | tr [a-f] [A-F])
            ip link add link eth1 $ifname type macvlan
            ifconfig $ifname hw ether $mac
            ifconfig $ifname up
            sleep 2
        else
            if [ $(ip link | grep " ${ifname}@eth1:" | grep "state UP " | wc -l) == "0" ] ;
            then
                ifup $interface
            
            fi 
        fi
   done    
   
   for q in $( seq 1 $number )
   do        
        echo
        echo ___________________________________________________
        echo 开始第$q次拔号...........
        killall -q -SIG pppd
        j=0
        sleep 2       
        echo 正开始并发拔号中.............

        # one line
        #取得wan口的账号和密码,用来多拨
        user=`uci get network.wan.username`
        pass=`uci get network.wan.password`

        for i in $( seq 0 $(($n-1)))
        do
          if [ "$i" == "0"  ] ;
          then
               interface=wan
                                                                ifname=eth1
          else
               interface=wan$i
                                                                ifname=vth$i
          fi

           # mul line
           #ifname=`uci get network.$interface.ifname`
           #user=`uci get network.$interface.username`
           #pass=`uci get network.$interface.password`
           #echo pppoe帐号:[$user]                pppoe密码:[$pass]        pppoe接口:[$ifname]

           /usr/sbin/pppd plugin rp-pppoe.so mtu 1492 mru 1492 nic-$ifname nopersist usepeerdns nodefaultroute user $user password $pass ipparam $interface ifname pppoe-$interface nodetach &
        done

        echo 正在并发拔号中.............
        echo 等待$wait秒.............
        sleep $wait
        
        j=$(ifconfig | grep pppoe-wan | wc -l)
        echo [$n]拔[$j]拔成功.....

        ! [ "$j" -ge "$ok" ] && echo 成功[$j]拔, 小于设定的[$ok]拔将重新拔号... 
        [ "$j" -ge "$ok" ] && echo 成功[$j]拔, 大于或等于设定的[$ok]退出拔号...   
        #[ "$j" -ge "$ok" ] && exit
        if [ "$j" -ge "$ok" ] ;
        then
           vias="" 
           for i in $( seq 0 $(($n-1)))
           do
              if [ "$i" == "0"  ] ;
              then
                  interface=wan
                  dev=eth1
              else
                  interface=wan$i
                  dev=vth$i
              fi
              if [ $(ifconfig | grep "pppoe-$interface " | wc -l) == "0" ] ;
              then
                     [ "$i" != "0" ] && ifdown $interface
              else
                                     wan_ifname="pppoe-${interface}"
                                     wan_ip=$(ip route list | grep 'src' | grep "${wan_ifname} " |  tr -s ' ' | cut -d ' ' -f9)
                                     vias="$vias nexthop via $wan_ip dev $wan_ifname weight 1 "
                        
                                     let "rt=100+$i"
                                     #./cprt main $rt
                                     ip route flush table $rt
                                     ip route add default via $wan_ip dev $wan_ifname table $rt
                                     #ip route add  table $rt default via $wan_gw dev $wan_ifname src $wan_ip
                                     #ip route add default 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 ") == "0" ] ;
                                                            then
                                                                iptables -t raw -A PREROUTING -i $wan_ifname -j zone_wan_notrack
                                                                #iptables -t mangle -A zone_wan_MSSFIX -o $wan_ifname -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-
                                                                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 
    

              fi
              
            done
                     
          ip route del default           
          ip route add default scope global $vias 
                                  ip route flush cache
          ip route list
          route -n

          exit
       fi 
        
    done

   
 
    
    


保存该脚本!并把该脚本扔到/root文件夹下并赋予755运行权限;后在每个配置好的wan口在防火墙勾选wan;最后执行 /root/pppoe.sh
补充:
1.由于路由器soc的瓶颈!所以脚本尽量不要设置那么多次数并发拨号!可能会造成路由器死掉!
2.脚本拨号的间隔可以根据自己的情况改变!
3.如果使用该脚本得停用mwan等插件!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|第一站论坛 ( 蜀ICP备06004864号-6 )

GMT+8, 2025-4-5 00:57 , Processed in 0.068558 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表