找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 25083|回复: 63

[基础] (教程)双ADSL相同网关加负载

[复制链接]
发表于 2007-5-5 20:26:39 | 显示全部楼层 |阅读模式

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

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

×
这两天跟一个朋友研究的,做的不对的还请指出

1.设置PPPOELIENT 这个不用说了吧^_^ (注意:加的时候把 "Add Default Route"前面的勾勾掉,没勾掉的话去IP-ROUTE里把它删掉)

2.改PPPOE-OUT1和PPPOE-OUT2的名字:如改PPPOE-OUT1为WAN1 改PPPOE-OUT2为WAN2

改名字的脚本如下:

/int set [/int find name=pppoe-out1] name "你想要的名字1"
/int set [/int find name=pppoe-out2] name "你想要的名字2"

3.在IP-ADDRESS里加IP地址


假如你的PPPOE-OUT1获得的IP为IP1(去掉子网掩码),pppoe-out2获得的IP为IP2(去掉子网掩码)

/ip add add address=ip1 interface=pppoe-out1 disabled=no
/ip add add address=ip2 interface=pppoe-out2 disabled=no

自动加IP地址的脚本如下:

:local ip1 [/ip add get [/ip add find broa=0.0.0.0 interface="你想要的名字1"] address]
:local ip2 [/ip add get [/ip add find broa=0.0.0.0 interface="你想要的名字2"] address]
:set ip1 [:pick $ip1 0 ([:len $ip1]-3)]
:set ip2 [:pick $ip2 0 ([:len $ip2]-3)]
/ip add add address=($ip1 . "/32") interface="你想要的名字1" comment= "你想要的名字1" disabled=no
/ip add add address=($ip2 . "/32") interface="你想要的名字2" comment= "你想要的名字2" disabled=no

4.标记连接和路由、IP伪装、路由表添加

(这里用的是ros官方的方法:伪装和路由的添加都是源自ROS官方的做法。具体解释请上官方查阅:http://wiki.mikrotik.com/wiki/Im ... r_Multiple_Gateways)

      标记连接和路由
/ ip firewall mangle
add chain=prerouting in-interface="内网网卡" connection-state=new nth=1,1,0 \
    action=mark-connection new-connection-mark=odd passthrough=yes comment="" \
    disabled=no
add chain=prerouting in-interface="内网网卡" connection-mark=odd action=mark-routing \
    new-routing-mark=odd passthrough=no comment="" disabled=no

add chain=prerouting in-interface="内网网卡" connection-state=new nth=1,1,1 \
    action=mark-connection new-connection-mark=even passthrough=yes comment="" \
    disabled=no
add chain=prerouting in-interface="内网网卡" connection-mark=even action=mark-routing \
    new-routing-mark=even passthrough=no comment="" disabled=no

       IP伪装
:local ip1 [/ip add get [/ip add find broa=0.0.0.0 interface="你想要的名字1"] address]
:local ip2 [/ip add get [/ip add find broa=0.0.0.0 interface="你想要的名字2"] address]
:set ip1 [:pick $ip1 0 ([:len $ip1]-3)]
:set ip2 [:pick $ip2 0 ([:len $ip2]-3)]
/ ip firewall nat
add chain=srcnat connection-mark=odd action=src-nat to-addresses=$ip1 \
    to-ports=0-65535 comment="" disabled=no
add chain=srcnat connection-mark=even action=src-nat to-addresses=$ip2 \
    to-ports=0-65535 comment="" disabled=no
      
      路由表添加
:local ip1 [/ip add get [/ip add find broa=0.0.0.0 interface="你想要的名字1"] network]
:local ip2 [/ip add get [/ip add find broa=0.0.0.0 interface="你想要的名字2"] network]
/ ip route
add dst-address=0.0.0.0/0 gateway=$ip1 scope=255 target-scope=10 routing-mark=odd \
    comment="" disabled=no
add dst-address=0.0.0.0/0 gateway=$ip2 scope=255 target-scope=10 routing-mark=even \
    comment="" disabled=no
add dst-address=0.0.0.0/0 gateway=$ip2 scope=255 target-scope=10 comment="你想要的名字2" \
    disabled=no   (这条也加标注的原因是为了后面的自动改网关脚本)

5.到这里内网的机器已经可以上网了。下面的就是控制IP改动的脚本

改IP-ADDRESS的脚本

:local ip1 [/ip add get [/ip add find broa=0.0.0.0 interface="你想要的名字1"] address]
:local ip2 [/ip add get [/ip add find broa=0.0.0.0 interface="你想要的名字2"] address]
:local ip3 [/ip add get [/ip add find comment= "你想要的名字1"] network]
:local ip4 [/ip add get [/ip add find comment="你想要的名字2"] network]
:set ip1 [:pick $ip1 0 ([:len $ip1]-3)]
:set ip2 [:pick $ip2 0 ([:len $ip2]-3)]
:if $ip1 != $ip3 do={/ip add set [/ip add find comment="你想要的名字1"] address ($ip1 . "/32") broa $ip1 network $ip1}
:if $ip2 != $ip4 do={/ip add set [/ip add find comment="你想要的名字2"] address ($ip2 . "/32") broa $ip1 network $ip1}

改IP伪装和路由表
:local ip1 [/ip add get [/ip add find broa=0.0.0.0 interface="你想要的名字1"] address]
:local ip2 [/ip add get [/ip add find broa=0.0.0.0 interface="你想要的名字2"] address]
:local ip3 [/ip fir nat get [/ip fir nat find connection-mark=odd] to-addresses]
:local ip4 [/ip fir nat get [/ip fir nat find connection-mark=even] to-addresses]
:local ip5 [/ip route get [/ip route find routing-mark=odd] gateway]
:local ip6 [/ip route get [/ip route find routing-mark=even] gateway]
:set ip1 [:pick $ip1 0 ([:len $ip1]-3)]
:set ip2 [:pick $ip2 0 ([:len $ip2]-3)]
:if $ip1 != $ip3 do={/ip fir nat set [/ip fir nat find connection-mark=odd] to-addresses $ip1}
:if $ip1 != $ip5 do={/ip route set [/ip route find routing-mark=odd] gateway $ip1}
:if $ip2 != $ip4 do={/ip fir nat set [/ip fir nat find connection-mark=even] to-addresses $ip2}
:if $ip2 != $ip6 do={/ip route set [/ip route find routing-mark=even] gateway $ip2}

添加任务

把上面的两个脚本添加到SYSTEM-SCRIPT里。命名为"change IP"和"change route"

/ system scheduler
add name="change ip" on-event="" start-date=jan/01/1970 \
    start-time=00:00:00 interval=2s comment="" disabled=no
add name="change route" on-event="" start-date=jan/01/1970 \
    start-time=00:00:00 interval=2s comment="" disabled=no
ROS双ADSL相同网关加负载.rar (1.52 KB, 下载次数: 843)
routeros
发表于 2007-5-5 20:40:25 | 显示全部楼层
我顶.....................
routeros
回复

使用道具 举报

发表于 2007-5-5 20:45:33 | 显示全部楼层
顶啊~~~~
routeros
回复

使用道具 举报

发表于 2007-5-5 20:45:51 | 显示全部楼层
照顾一下新手...有视频教程就好了..... ....再顶
routeros
回复

使用道具 举报

发表于 2007-5-5 20:58:14 | 显示全部楼层
虽然我不用这种负载,不过还是要强烈的顶~~~~ :lol :lol
routeros
回复

使用道具 举报

发表于 2007-5-5 21:12:19 | 显示全部楼层
要不要这么复杂啊~~~!
routeros
回复

使用道具 举报

 楼主| 发表于 2007-5-5 22:01:10 | 显示全部楼层
呵呵,如果用WINBOX的话用不了这么复杂.
只是加几个脚本就想完成的话有点复杂
routeros
回复

使用道具 举报

发表于 2007-5-5 23:01:12 | 显示全部楼层
这些对新手有帮助,算是总结以前我们大家发的贴吧。
但脚本应该精简,不过写得冗余些对新手也是个帮助。

NTH的负载均衡不推荐!
routeros
回复

使用道具 举报

发表于 2007-5-5 23:25:28 | 显示全部楼层

支持楼主
routeros
回复

使用道具 举报

发表于 2007-5-6 01:41:38 | 显示全部楼层
解析一下脚本的意思就好了........神啊...教教我吧,.......
routeros
回复

使用道具 举报

发表于 2007-5-6 11:11:39 | 显示全部楼层
dfxdfghdfg
routeros
回复

使用道具 举报

发表于 2007-5-6 12:17:51 | 显示全部楼层
支持共享精神,顶顶

我再顶,好样的,楼主
routeros
回复

使用道具 举报

发表于 2007-5-6 15:21:09 | 显示全部楼层
有没有谁试过啊?
routeros
回复

使用道具 举报

发表于 2007-5-6 15:23:06 | 显示全部楼层
:set ip1 [:pick $ip1 0 ([:len $ip1]-3)]

这样去掩码是否有问题??如果是:172.0.0.0/8呢
是不是应该用查找"/"这个来取呢??
routeros
回复

使用道具 举报

发表于 2007-5-6 16:41:09 | 显示全部楼层
这么麻烦啊。。。。
routeros
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-10 03:51 , Processed in 0.073937 second(s), 6 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2023 Discuz! Team.

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