找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 19531|回复: 32

[其它] 3线ADSL负载均衡详细配置

[复制链接]
发表于 2008-8-12 02:22:16 | 显示全部楼层 |阅读模式

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

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

×
3线ADSL负载均衡详细配置
/ interface pppoe-client
add name="pppoe-out1" max-mtu=1480 max-mru=1480 interface=ether1 \
    user="adsl1帐号" password="adsl1密码" profile=adsl1gateway \
    service-name="" ac-name="" add-default-route=yes dial-on-demand=no \
    use-peer-dns=no allow=pap,chap,mschap1,mschap2 disabled=no
add name="pppoe-out2" max-mtu=1480 max-mru=1480 interface=ether2 \
    user="adsl2帐号" password="adsl2密码" profile=adsl2gateway \
    service-name="" ac-name="" add-default-route=no dial-on-demand=no \
    use-peer-dns=no allow=pap,chap,mschap1,mschap2 disabled=no
add name="pppoe-out3" max-mtu=1480 max-mru=1480 interface=ether3 \
    user="adsl3帐号" password="adsl3密码" profile=default service-name="" \
    ac-name="" add-default-route=no dial-on-demand=no use-peer-dns=no \
    allow=pap,chap,mschap1,mschap2 disabled=no

/ ip address
add address=11.1.1.228/32 network=11.1.1.228 broadcast=11.1.1.228 \
    interface=pppoe-out1 comment="1" disabled=no
add address=11.1.1.235/32 network=11.1.1.235 broadcast=11.1.1.235 \
    interface=pppoe-out2 comment="2" disabled=no
add address=116.116.116.116/32 network=116.116.116.116 \
    broadcast=116.116.116.116 interface=pppoe-out3 comment="3" disabled=no

/ ip route
add dst-address=0.0.0.0/0 gateway=11.1.1.228 scope=255 target-scope=10 \
    routing-mark=1 comment="1" disabled=no
add dst-address=0.0.0.0/0 gateway=11.1.1.235 scope=255 target-scope=10 \
    routing-mark=2 comment="2" disabled=no  
add dst-address=0.0.0.0/0 gateway=116.116.116.116 scope=255 target-scope=10 \
    routing-mark=3 comment="3" disabled=no

/ ip firewall nat
add chain=srcnat action=masquerade comment="" disabled=yes
add chain=srcnat connection-mark=1 action=src-nat to-addresses=11.1.1.228 \
    to-ports=0-65535 comment="1" disabled=no
add chain=srcnat connection-mark=2 action=src-nat to-addresses=11.1.1.235 \
    to-ports=0-65535 comment="2" disabled=no
add chain=srcnat connection-mark=3 action=src-nat to-addresses=116.116.116.116 \
    to-ports=0-65535 comment="3" disabled=no

/ ip firewall mangle
add chain=prerouting dst-address-list=noNTH_IP action=mark-routing \
    new-routing-mark=2 passthrough=yes comment="noNTH_IP" disabled=no
add chain=prerouting protocol=tcp dst-port=443 action=mark-routing \
    new-routing-mark=1 passthrough=yes comment="dst.port_443mark1" disabled=no
add chain=prerouting src-address=11.1.0.1-11.1.8.255 connection-state=new \
    nth=2,3,0 dst-address-list=!noNTH_IP action=mark-connection \
    new-connection-mark=1 passthrough=yes comment="" disabled=no
add chain=prerouting src-address=11.1.0.1-11.1.8.255 connection-mark=1 \
    dst-address-list=!noNTH_IP action=mark-routing new-routing-mark=1 \
    passthrough=no comment="" disabled=no
add chain=prerouting src-address=11.1.0.1-11.1.8.255 connection-state=new \
    nth=2,3,1 dst-address-list=!noNTH_IP action=mark-connection \
    new-connection-mark=2 passthrough=yes comment="" disabled=no
add chain=prerouting src-address=11.1.0.1-11.1.8.255 connection-mark=2 \
    dst-address-list=!noNTH_IP action=mark-routing new-routing-mark=2 \
    passthrough=no comment="" disabled=no
add chain=prerouting src-address=11.1.0.1-11.1.8.255 connection-state=new \
    nth=2,3,2 dst-address-list=!noNTH_IP action=mark-connection \
    new-connection-mark=3 passthrough=yes comment="" disabled=no
add chain=prerouting src-address=11.1.0.1-11.1.8.255 connection-mark=3 \
    dst-address-list=!noNTH_IP action=mark-routing new-routing-mark=3 \
    passthrough=no comment="" disabled=no
add chain=forward protocol=tcp tcp-flags=syn action=change-mss new-mss=1432 \
    comment="" disabled=no
add chain=prerouting action=accept comment="" disabled=no

/ ip firewall address-list
add list=noNTH_IP address=202.118.118.0/24 comment="" disabled=no
add list=noNTH_IP address=222.121.112.51-222.121.112.60 comment="" disabled=no

/system script
add name="balance" source={
:local assign-address
:local new-address
:local status
:local x
:set x 3
:for i from=1 to=$x do={
    :set status [/interface get [/interface find  name=("pppoe-out" . $i)] running]
    :if ($status=true) do={
     :set new-address [/ip address get [/ip address find dynamic=yes interface=("pppoe-out" . $i)] address]
     :set new-address [:pick $new-address 0 ([:len $new-address] -3)]
     :set assign-address [/ip address get [/ip address find dynamic=no interface=("pppoe-out" . $i)] address]
     :set assign-address [:pick $assign-address 0 ([:len $assign-address] -3)]
        :if ($assign-address != $new-address) do={ /ip address set [/ip address find comment=$i] address=$new-address network=$new-address broadcast=$new-address
        /ip route set [/ip route find comment=$i] gateway=$new-address
        /ip firewall nat set [/ip firewall nat find comment=$i] to-addresses=$new-address
        /ip route set [/ip route find comment=$i] gateway=$new-address
       }
   }
}
}

/ system scheduler
add name="获取adsl地址" on-event=balance start-date=jan/01/1970 \
    start-time=00:00:00 interval=10s comment="" disabled=no

全部复制到terminal控制台内,之后修改成自己的ADSL帐号、密码;“noNTH_IP”是不需要均衡IP的清单,在/ ip firewall address-list 内修改“noNTH_IP”的实际IP,没有IP可以禁用这个地址清单。src-address=11.1.0.1-11.1.8.255,是内网所用的IP,不论是固定IP还是PPPOE,建立地址池时,选用这段IP或更改成你的IP。觉得好就 顶顶顶起来
routeros
发表于 2008-8-12 03:05:33 | 显示全部楼层
另类连线法的具体操作:

  下面我们就来详细的介绍下另类接线法的具体操作,首先我们选取一台家用宽带路由器,一般家用宽带路由器都有四个LAN以太接口以及一个WAN广域网接入接口。

(1)另类连线法的初始工作:

  我们先来连接各个设备保证另类接线法网络拓扑的建立。

  第一步:开通三条ADSL线路接入服务,猫一般都自带路由功能,设置使其任何时间都始终拔号上网.不带的自己想办法.

  第二步:将一条ADSL电话线连接ADSL猫,并且从该ADSL猫上引出一条网线(它已拔号并成为网关)连接家用宽带路由器的某一个以太接口,我们姑且设定为LAN4。(注意所有都不要开DHCP)

  第三步:将另外一条ADSL电话线连接ADSL猫,并且从该ADSL猫上引出一条网线连接家用宽带路由器的某一个以太接口,我们姑且设定为LAN3。

  第四步:将连接家用宽带路由器WAN接口的那个网线的另外一端插到宽带路由器的某一个以太接口我们姑且设定为LAN2。

  第五步:将家用宽带路由器剩下的以太接口LAN1连接企业下属交换机。

   第六步:将另外一条ADSL电话线连接ADSL猫,并且从该ADSL猫上引出一条网线连接下属交换机的某一个以太接口,这样就完成了另类连接法的初始工作。

  至此我们就完成了连线工作,在实际使用过程中我们的外网接入服务就已经成为两条ADSL线路绑定方式了,提供的外网接入服务将是两条ADSL线路对应带宽的总和。当然在设置方面我们需要指定WAN接口的外网接入类型为非PPPOE拨号而是LAN接入方式。

好了,进家用路由设置WAN为0.0.0.0/24

(2)另类连线法提供多WAN口接入服务的原理:

  本文介绍的这个另类连线法提供多WAN口接入服务的原理是这样,首先我们来看宽带路由器四个LAN接口,LAN1提供下连设备的接入,当下连设备有联网请求时会向LAN1接口发送请求数据包,根据宽带路由器的工作原理,当有外网访问需求时会直接把数据包发送到WAN接口,而当前我们WAN接口通过一条网线连接到了LAN2接口,这样该数据包就被成功的发送到了LAN2接口。

  数据包到达LAN2接口后会将四个LAN接口看做一个广播区域,类似我们平时使用的交换机,然后各个接口都会收到这个外网访问请求,从而触发到LAN3口与LAN4接口上的拨号,进一步促成ADSL猫拨号连接网络,从而顺利完成数据包的路由功能。

  说白了我们可以把整个拨号过程看做是数据请求发送到一个四个以太接口的交换机上而非宽带路由器,这样数据包会以广播的方式发送给交换机各个以太接口,完成拨号工作和网络接入服务。
routeros
回复

使用道具 举报

发表于 2008-8-12 03:08:50 | 显示全部楼层
不过上面的方法让我担心引起广播风暴
routeros
回复

使用道具 举报

发表于 2008-8-12 04:16:05 | 显示全部楼层
ddddddddddddddd  ...................hao......................
routeros
回复

使用道具 举报

发表于 2008-8-12 04:18:53 | 显示全部楼层
我正在做4线,有教材吗??QQ415098161
routeros
回复

使用道具 举报

 楼主| 发表于 2008-8-12 05:28:16 | 显示全部楼层
理解Nth有3个参数Every,Counter,Packet就很容易设置多线的负载均衡(NTH)
Every频数,每几个数循环一次,这些数是从0开始计算的。
如:Every=1。01010101的循环
Counter是一个计数器,ROS共有16个计数器(0-15)
Packet就是计数器里的第几个数。

NTH二线参数 nth=1,1,0  1,1,1
NTH三线参数 nth=2,3,0  2,3,1  2,3,2三线以上类推
routeros
回复

使用道具 举报

发表于 2008-8-13 11:36:28 | 显示全部楼层
三线负载均衡做的不错,学习了,谢谢,辛苦你了  另类连线法我个人觉得可行性不够,你这样子猫恐怕一天死9次哦
routeros
回复

使用道具 举报

发表于 2008-8-14 00:06:53 | 显示全部楼层
hao dfasdfasdfsadfasdf
routeros
回复

使用道具 举报

发表于 2008-8-30 16:04:24 | 显示全部楼层
学习三线
routeros
回复

使用道具 举报

发表于 2008-8-30 18:11:10 | 显示全部楼层
routeros
回复

使用道具 举报

发表于 2008-9-12 14:44:24 | 显示全部楼层
好帖...不过按照楼主所说的方法做了以后有点问题,我是双电信固定公网IP,做两线NTH均衡后只有一条线路有流量,不过游戏和QQ掉线的问题的确是解决了,能加楼主的QQ请教一下吗?或者跟帖也行,我的QQ是3320699,谢了
routeros
回复

使用道具 举报

发表于 2008-9-12 19:02:50 | 显示全部楼层
我也用"NTH三线参数 nth=2,3,0  2,3,1  2,3,2"的方法试了,可是为什么标记里会有很多“none”(未标记)的连接呢?
3nth.PNG

[ 本帖最后由 upcwh 于 2008-9-12 19:05 编辑 ]
routeros
回复

使用道具 举报

发表于 2008-9-26 00:14:51 | 显示全部楼层

使用vMWare作测试环境..客户端不能上网.

/ interface pppoe-client
add name="pppoe-out1" max-mtu=1480 max-mru=1480 interface=ether2 \
    user="a" password="a" profile=default service-name="" \
    ac-name="" add-default-route=yes dial-on-demand=no \
    use-peer-dns=no allow=pap,chap,mschap1,mschap2 disabled=no
add name="pppoe-out2" max-mtu=1480 max-mru=1480 interface=ether3 \
    user="b" password="b" profile=default service-name="" \
    ac-name="" add-default-route=no dial-on-demand=no \
    use-peer-dns=no allow=pap,chap,mschap1,mschap2 disabled=no

add name="pppoe-out3" max-mtu=1480 max-mru=1480 interface=ether4 \
    user="c" password="c" profile=default service-name="" \
    ac-name="" add-default-route=no dial-on-demand=no use-peer-dns=no \
    allow=pap,chap,mschap1,mschap2 disabled=no

/ ip address
add address=11.1.1.228/32 network=11.1.1.228 broadcast=11.1.1.228 \
    interface=pppoe-out1 comment="1" disabled=no
add address=11.1.1.235/32 network=11.1.1.235 broadcast=11.1.1.235 \
    interface=pppoe-out2 comment="2" disabled=no
add address=116.116.116.116/32 network=116.116.116.116 \
    broadcast=116.116.116.116 interface=pppoe-out3 comment="3" disabled=no

/ ip route
add dst-address=0.0.0.0/0 gateway=11.1.1.228 scope=255 target-scope=10 \
    routing-mark=1 comment="1" disabled=no
add dst-address=0.0.0.0/0 gateway=11.1.1.235 scope=255 target-scope=10 \
    routing-mark=2 comment="2" disabled=no  
add dst-address=0.0.0.0/0 gateway=116.116.116.116 scope=255 target-scope=10 \
    routing-mark=3 comment="3" disabled=no

/ ip firewall nat
add chain=srcnat action=masquerade comment="" disabled=yes
add chain=srcnat connection-mark=1 action=src-nat to-addresses=11.1.1.228 \
    to-ports=0-65535 comment="1" disabled=no
add chain=srcnat connection-mark=2 action=src-nat to-addresses=11.1.1.235 \
    to-ports=0-65535 comment="2" disabled=no
add chain=srcnat connection-mark=3 action=src-nat to-addresses=116.116.116.116 \
    to-ports=0-65535 comment="3" disabled=no

/ ip firewall mangle
add chain=prerouting dst-address-list=noNTH_IP action=mark-routing \
    new-routing-mark=2 passthrough=yes comment="noNTH_IP" disabled=no
add chain=prerouting protocol=tcp dst-port=443 action=mark-routing \
    new-routing-mark=1 passthrough=yes comment="dst.port_443mark1" disabled=no
add chain=prerouting src-address=11.1.0.1-11.1.8.255 connection-state=new \
    nth=2,3,0 dst-address-list=!noNTH_IP action=mark-connection \
    new-connection-mark=1 passthrough=yes comment="" disabled=no
add chain=prerouting src-address=11.1.0.1-11.1.8.255 connection-mark=1 \
    dst-address-list=!noNTH_IP action=mark-routing new-routing-mark=1 \
    passthrough=no comment="" disabled=no
add chain=prerouting src-address=11.1.0.1-11.1.8.255 connection-state=new \
    nth=2,3,1 dst-address-list=!noNTH_IP action=mark-connection \
    new-connection-mark=2 passthrough=yes comment="" disabled=no
add chain=prerouting src-address=11.1.0.1-11.1.8.255 connection-mark=2 \
    dst-address-list=!noNTH_IP action=mark-routing new-routing-mark=2 \
    passthrough=no comment="" disabled=no
add chain=prerouting src-address=11.1.0.1-11.1.8.255 connection-state=new \
    nth=2,3,2 dst-address-list=!noNTH_IP action=mark-connection \
    new-connection-mark=3 passthrough=yes comment="" disabled=no
add chain=prerouting src-address=11.1.0.1-11.1.8.255 connection-mark=3 \
    dst-address-list=!noNTH_IP action=mark-routing new-routing-mark=3 \
    passthrough=no comment="" disabled=no
add chain=forward protocol=tcp tcp-flags=syn action=change-mss new-mss=1432 \
    comment="" disabled=no
add chain=prerouting action=accept comment="" disabled=no

/ ip firewall address-list
add list=noNTH_IP address=202.118.118.0/24 comment="" disabled=no
add list=noNTH_IP address=222.121.112.51-222.121.112.60 comment="" disabled=no

/system script
add name="balance" source={
:local assign-address
:local new-address
:local status
:local x
:set x 3
:for i from=1 to=$x do={
    :set status [/interface get [/interface find  name=("pppoe-out" . $i)] running]
    :if ($status=true) do={
     :set new-address [/ip address get [/ip address find dynamic=yes interface=("pppoe-out" . $i)] address]
     :set new-address [:pick $new-address 0 ([:len $new-address] -3)]
     :set assign-address [/ip address get [/ip address find dynamic=no interface=("pppoe-out" . $i)] address]
     :set assign-address [:pick $assign-address 0 ([:len $assign-address] -3)]
        :if ($assign-address != $new-address) do={ /ip address set [/ip address find comment=$i] address=$new-address network=$new-address broadcast=$new-address
        /ip route set [/ip route find comment=$i] gateway=$new-address
        /ip firewall nat set [/ip firewall nat find comment=$i] to-addresses=$new-address
        /ip route set [/ip route find comment=$i] gateway=$new-address
       }
   }
}
}

/ system scheduler
add name="adsl" on-event=balance start-date=jan/01/1970 \
    start-time=00:00:00 interval=10s comment="" disabled=no




--------------------------------
我的QQ是76688980,期望得到指点.红色处有作修改,其他照抄.

[ 本帖最后由 seayou_wey 于 2008-9-26 00:16 编辑 ]
routeros
回复

使用道具 举报

发表于 2008-10-23 21:08:15 | 显示全部楼层
1、楼主的路由少了一条
/ip route add dst-address=0.0.0.0/0 gateway=116.116.116.116 comment="other" disabled=no
就是增加一条没有路由标记的路由,要不如果有某条线路掉线的话,会造成有1/3的新连接路由不出去(比如pppoe-out1掉了,那么routing-mark=1的包就发不出去了);当然对应的脚本也要修改,能够实时修改这条路由的gateway

2、12楼所说有connection-mark=(none)的连接,是因为这些连接没有被mangle标记过,比如:由外网主动发起的连接(因为源地址不是内网地址,不符合mangle表里的规则,所以不会被标记);同理,由路由器自己发出去的包也不会被标记

3、按楼主的作法,从外网是不能访问内网机器(作了映射也不行)或路由器本身的,因为从外网进来的包没有标记,所以也就无法在路由表找到对应路由;就算按我所说第1点加了路由,也只能用那条路由规则里的gateway来访问路由器,而不能用路由器的任意一个的公网IP来访问,所以还得在mangle添加规则作标记
/ip f m
add chain=prerouting in-interface=pppoe-out1 connection-state=new action=mark-connection new-connection-mark=1 passthrough=no
add  chain=prerouting in-interface=pppoe-out2 connection-state=new action=mark-connection new-connection-mark=2 passthrough=no
add  chain=prerouting in-interface=pppoe-out3 connection-state=new action=mark-connection new-connection-mark=3 passthrough=no
add  chain=output connection-mark=1 action=mark-routing new-routing-mark=1 passthrough=no
add  chain=output connection-mark=2 action=mark-routing new-routing-mark=2 passthrough=no
add  chain=output connection-mark=3 action=mark-routing new-routing-mark=3 passthrough=no

从外网到路由器的包只会经过prerouting和input链,而从路由器本身发出去的包只会经过output和postrouting,通过路由器转发的包只会经过prerouting\forward\postrouting链;上面的规则把目标为路由器的新连接作连接标记,然后把从路由器返回的外出包作路由标记,这样就可以用路由器的任意公网IP来访问了

[ 本帖最后由 hcpmm 于 2008-10-23 21:19 编辑 ]
NAT表.jpg.jpg
路由表.jpg
拔号界面.jpg
Mangle表.jpg.jpg
限制ssh暴力破解.jpg
routeros
回复

使用道具 举报

发表于 2008-10-23 21:10:24 | 显示全部楼层
真够复杂的!!好像我做三线,才这四分之一的设置量.
routeros
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-10-1 03:20 , Processed in 0.156244 second(s), 7 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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