找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 26639|回复: 36

[负载平衡] 光纤上行多ADSL下行脚本分享

  [复制链接]
发表于 2013-3-12 11:21:22 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

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

×
本帖最后由 glb323 于 2013-3-12 11:19 编辑

要做到光纤上行,多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. /interface pppoe-client
  2. :for i from=901 to=948 do= {/int pppoe-client add name=("cu-pppoe-out".($i-900)) interface=("bridge".$i) profile=profile-CU}
  3. /interface pppoe-client set [find interface=bridge901] comment=PPPoE-CU
  4. /
复制代码
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. }}}}}
复制代码

评分

参与人数 1铜板 +24 收起 理由
9939781 + 24 淡定

查看全部评分

routeros
发表于 2013-3-12 12:01:59 | 显示全部楼层
支持,不过强制SRC-NAT在某些地区还是被运营商限制的。
routeros
回复

使用道具 举报

发表于 2013-3-12 12:03:10 | 显示全部楼层
好工整的脚本!!!!沙发,支持楼主!
routeros
回复

使用道具 举报

 楼主| 发表于 2013-3-12 12:13:51 | 显示全部楼层
routeros
回复

使用道具 举报

发表于 2013-3-12 12:34:28 | 显示全部楼层
趁楼主没有卖钱前,赶紧看完!
routeros
回复

使用道具 举报

发表于 2013-3-12 13:25:46 | 显示全部楼层
留位有备用
routeros
回复

使用道具 举报

发表于 2013-3-12 15:52:45 | 显示全部楼层
顶楼上的,留着备用!
routeros
回复

使用道具 举报

发表于 2013-3-12 18:16:44 | 显示全部楼层
顶楼上的,留着备用!
routeros
回复

使用道具 举报

发表于 2013-3-12 19:28:06 | 显示全部楼层
glb323 发表于 2013-3-12 12:13
所以我有前提条件,能不能用,自己测试。

glb323的技术贴值得收藏,呵呵
我订了e3-2670一套了,回头指点指点怎么测试转发能力
所有配件预计周末就到期啦,哈哈
routeros
回复

使用道具 举报

 楼主| 发表于 2013-3-12 19:39:25 | 显示全部楼层
sealin 发表于 2013-3-12 19:28
glb323的技术贴值得收藏,呵呵
我订了e3-2670一套了,回头指点指点怎么测试转发能力
所有配件预计周末就 ...

测试我也不会啊。那天忘了问你,你需要10个接口?
routeros
回复

使用道具 举报

发表于 2013-3-12 20:44:34 | 显示全部楼层
glb323 发表于 2013-3-12 19:39
测试我也不会啊。那天忘了问你,你需要10个接口?

现在是3入3出,考虑未来扩容,暂时上了两块i350t4,加上主板带的2口i350
一共10口,原来的两块82576可以继续使用,这就是14口啦,呵呵
routeros
回复

使用道具 举报

 楼主| 发表于 2013-3-13 00:43:54 来自手机 | 显示全部楼层
sealin 发表于 2013-3-12 20:44
现在是3入3出,考虑未来扩容,暂时上了两块i350t4,加上主板带的2口i350
一共10口,原来的两块82576可以 ...

你的规模也不小啊
routeros
回复

使用道具 举报

发表于 2013-3-13 03:03:05 | 显示全部楼层
学习了,也可以 走vpn,
routeros
回复

使用道具 举报

发表于 2013-3-13 07:39:30 | 显示全部楼层
这个不错和你好好
routeros
回复

使用道具 举报

发表于 2013-3-13 08:30:42 | 显示全部楼层
收藏起來...........有空研究看看!~
routeros
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-28 16:24 , Processed in 0.070695 second(s), 5 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2023 Discuz! Team.

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