注册 登录
自由的生活_软路由 返回首页

glb323的个人空间 https://bbs.routerclub.com/?60987 [收藏] [复制] [分享] [RSS]

日志

光纤上行多ADSL下行脚本分享

已有 1494 次阅读2013-3-12 16:09 |个人分类:负载均衡| 分享, 光纤

要做到光纤上行,多ADSL线路下行,有不少限制因素,下面的脚本经过多项目验证都是没有问题的,所以请不要对脚本的可用性怀疑。
下面的示例用的是北京联通的48线ADSL。有些没说到的内容大家自己想办法。

1.首先我们当然是要跟vlan交换机对接啦,那就先创建vlan吧,此处以联通示例,如果是多pcc,请自行解决。
  1. :for i from=901 to=948 do= {/int vlan add interface=WAN name=("vlan".$i) vlan-id=$i}
  2. /int vlan set [find name=vlan901] comment=VLAN-CU
  3. /
2.vlan搞定了,接下来就是建桥了,为什么要这么做,我想大家都应该明白吧
  1. :for i from=901 to=948 do= {/int bridge add name=("bridge".$i) admin-mac=("01:88:".$i) auto-mac=no}
  2. :for i from=901 to=948 do= {/int bridge port add bridge=("bridge".$i) interface=("vlan".$i)}
  3. /int bridge set [find name=bridge901] comment=BRIDGE-CU
  4. /int bridge port set [find interface=vlan901] comment=BRIDGE-CU
  5. /
3.下面呢,我们搞个profile给pppoe-client用,方便多pcc分离。
  1. /ppp profile add change-tcp-mss=default name=profile-CU only-one=default use-compression=no use-encryption=no use-mpls=no use-vj-compression=no dns-server=202.106.0.20,202.106.196.115
  2. /
4.现在我们该建拨号连接了。
  1. :for i from=901 to=948 do= {/int pppoe-client add name=("cu-pppoe-out".($i-900)) interface=("bridge".$i) profile=profile-CU}
  2. /interface pppoe-client set [find interface=bridge901] comment=PPPoE-CU
  3. /
5.建个联通nat的地址池吧
  1. /ip firewall address-list add address=172.17.0.0/24 disabled=no list=NAT-CU
  2. /
6.起nat了,这里的地址都是临时的,真正运行起来,会自动修改的哦
  1. :for i from=901 to=948 do= {/ip firewall nat add action=src-nat chain=srcnat disabled=no connection-mark=("cu".($i-900)) to-addresses=("2.2.2.".($i-900))}
  2. /ip firewall nat set [find connection-mark="cu1"] comment=NAT-CU
  3. /
7.做标记
  1. :for i from=901 to=948 do= {/ip firewall mangle add action=mark-connection chain=prerouting disabled=no dst-address-type=!local new-connection-mark=("cu".($i-900)) passthrough=yes per-connection-classifier=("both-addresses-and-ports:48/".($i-901)) src-address-list=NAT-CU}
  2. :for i from=901 to=948 do= {/ip firewall mangle add action=mark-routing chain=prerouting connection-mark=("cu".($i-900)) disabled=no new-routing-mark=fiber_route passthrough=yes src-address-list=NAT-CU}
  3. /ip firewall mangle set [find new-connection-mark=cu1] comment=CONNECTION-CU
  4. /ip firewall mangle set [find connection-mark="cu1"] comment=ROUTING-CU
  5. /
8.下面要做两个schedule,一个呢是去判断当前运行的出口数,做均衡;另外一个呢是看看每个线路是不是断线重拨了,如果重拨了,肯定是改了ip了。我们先做第一个。
  1. sys scheduler add name=scheduler-CU interval=00:01:00 on-event={
  2. :local status
  3. :local i "48"
  4. :local x "0"
  5. :local y "0"
  6. :local z "0"
  7. :set x [:len [/interface pppoe-client find running=yes profile=profile-CU]]
  8. :if ($x<$i) do={
  9. :for ii from=1 to=$i do={
  10. :set status [/interface get [find name=("cu-pppoe-out"."$ii")] running]
  11. :if ($status=true) do={
  12. /ip fir man set [find new-connection-mark=("cu"."$ii")] per-connection-classifier=("both-addresses-and-ports:"."$x"."/"."$y") disable=no;:set y ($y+1)} else={
  13. /ip fir man set [find new-connection-mark=("cu"."$ii")] disable=yes}}}
  14. :if ($x=$i) do={
  15. :set z [:len [/ip fir man find action="mark-connection" disabled=yes chain=prerouting]]
  16. :if ($z>0) do={
  17. :for ii from=1 to=$i do={
  18. /ip fi man set [find new-connection-mark=("cu"."$ii")] per-connection-classifier=("both-addresses-and-ports:"."$i"."/"."$y") disable=no;:set y ($y+1)}}}}
9.现在做第二个。
  1. sys scheduler add name=changeip-CU interval=00:01:00 on-event={
  2. :global ipa ""
  3. :global ipb ""
  4. :global pname ""
  5. /interface pppoe-client
  6. :for i from=1 to=48 do={
  7. :set pname ("cu-pppoe-out". $i)
  8. monitor $pname once do={
  9. :if ($status="connected" && $uptime<00:01:00) do={
  10. :set ipa [/ip address get [/ip address find interface=$pname dynamic=yes] address]
  11. :set ipa [:pick $ipa 0 [:find $ipa "/"]]
  12. :if ([:len [/ip fir nat find connection-mark=("cu".$i)]] > 0) do={
  13. :set ipb [/ip fir nat get [/ip fir nat find connection-mark=("cu".$i)] to-addresses]
  14. } else={/ip fir nat add action=src-nat chain=srcnat connection-mark=("cu".$i) to-addresses=$ipa comment=$pname;:set ipb $ipa}
  15. :if ($ipb != $ipa) do={
  16. /ip fir nat set [find connection-mark=("cu".$i)] to-addresses=$ipa disabled=no
  17. :log warning ("\D0\DE\B8\C4\5B" . $pname . "\5D\D3\B3\C9\E4\B5\BD" . $ipa)
  18. :beep length=3000ms frequency=1800
  19. }}}}}

路过

雷人

握手

鲜花

鸡蛋

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

QQ|Archiver|手机版|小黑屋|软路由 ( 渝ICP备15001194号-1|渝公网安备 50011602500124号 )

GMT+8, 2024-11-5 20:24 , Processed in 0.042108 second(s), 6 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

返回顶部