routeros双线ADSL

本文介绍如何在RouterOS设备上配置双线ADSL负载均衡,包括设置PPPoE拨号、手动添加IP地址及网关、配置网段分流脚本、IP伪装以及实现ADSL掉线自动恢复等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://www.txwb.com/Article/serverHelp/wljs/200812/27163.html

ROS双线ADSL不同网关按网段分流

 

[作者: lessf 来源: lunhui.net 时间: 2008-12-16添加到QQ收藏QQ书签]我来说两句 大 中 小】
建立PPP拨号,把其中一条拨号名命名为ADSL1,另一个命明为ADSL2,首先等待拨号成功。

设置参考图1:
点击全屏浏览


拨号成功后,PPPOE会自动添加IP地址和网关,我们要做的就是,手动再添加一次这些地址,以配合脚本。
手动添加2个和PPP自动添加出来一样的IP,并标记为1和2,1为ADSL1的IP,2为ADSL2的IP:

绿色代表我们添加时取的数字,红框代表的是我们添加的内容,说简单点,就是复制一份自动分配得来的IP地址,然后做个标记

位置winbox-ip-addresses

设置如图2
点击全屏浏览

下面是手动添加2个和PPP自动添加出来一样的router(称作外网网关),并标记为1和2,1为ADSL1的外网网关,2为ADSL2的外网网关:

黑色代表我们添加时取的数字,红框代表的是我们添加的内容,说简单点,就是复制一份自动分配得来的外网网关,然后做个标记

位置winbox-ip-routes

设置如图3
点击全屏浏览


添加完毕后,打开winbox-new terminal,复制下面的脚本,在终端上点右键,选paste

1.添加IP地址伪装

/ ip firewall nat
add chain=srcnat action=masquerade comment="" disabled=no



2.添加网段分流脚本,请手动修改红色部分

红色部分代表了192.168.1.1-192.168.1.120用ADSL1,192.168.1.121-192.168.1.240用ADSL1

修改完毕后,复制修改后的内容,在终端上paste


/ ip firewall mangle
add chain=prerouting src-address=192.168.1.1-192.168.1.120 action=mark-routing new-routing-mark=1 passthrough=yes /
    comment="" disabled=no
add chain=prerouting src-address=192.168.1.121-192.168.1.240 action=mark-routing new-routing-mark=2 passthrough=yes /
    comment="" disabled=no
add chain=postrouting protocol=tcp tcp-flags=syn action=change-mss new-mss=1400 comment="" disabled=no

3.添加ADSL掉线后自动添加新IP和网关脚本

位置winbox-system-script 点“+ ”号,改name为script,然后复制下面的脚本到source里,添加完毕后效果如图4

:local assign-address
:local new-address
:local status
:local x
:set x 2
:for i from=1 to=$x do={
    :set status [/interface get [/interface find name=("ADSL" . $i)] running]
    :if ($status=true) do={
     :set new-address [/ip address get [/ip address find dynamic=yes interface=("ADSL" . $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=("ADSL" . $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 route set [/ip route find comment=$i] gateway=$new-address
       }
   }
}




点击全屏浏览

4.添加脚本计划任务

10秒钟运行一次script脚本,就是上面那个,来防掉线!!

/ system scheduler
add name="task" on- EVEnt=script start-date=jan/01/1970 start-time=00:00:00 interval=10s comment="" /
    disabled=no

router os 双线adsl负载均衡配置过程

作者:红易网络    发表时间: 2007-12-28 
 

※广告3※

 

先来看看配置之后的效果图

 

1

以下是详细配置过程:
1 标记连接和路由
配置mangle后的效果图
2

以下是详细配置过程

 

3

4

5

6

7

8

9

10

11

12

2 配置网关(此步之前需要先配置好pppoe,配置过程请到论坛上找)
由下图可知,我加了2条规则,分别对应两个pppoe获得的地址,特点是address=network=broadcast。
这样做的目的是让ros能够根据这里所设的网关分别路由。
注意comment中的1和2,再运行脚本时要用到。

 

13

3 配置srcnat(ip伪装)
总配置效果图,注意comment的设置,在运行脚本时要用到

 

14

配置截图:

 

15

16

17

18

4 配置路由
总配置效果图,注意comment的设置,在运行脚本时要用到
可以看到,我在路由表中加入了3条规则,前两条分别对应于在mangle中设置的两个路由标记
另外一条没有路由标记,官方解释说是用于路由被标记之外的ros本身的包,具体什么意思我也没有彻底明白
19

5 加入防adsl掉线脚本

再到system->schedulerl加入:
:local assign-address
:local new-address
:local status
:local x
:set x 2
: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 fir nat set [/ip fir nat find comment=$i] to-addresses=$new-address
        /ip route set [/ip route find comment=$i] gateway=$new-address
       }
   }
}

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值