扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
本文介绍了双ADSL下的NTH的负载均衡设置问题。包括普通脚本,nat,还有IP等相关内容。那么,具体的代码,请从下文中参考。
说了很多关于数据库,服务器等负载均衡问题。现在,我们来讨论一下ADSL的负载均衡设置。主要我们需要对脚本进行“改造”,也就是NTH负载均衡的设置问题,文中包括很多脚本代码,希望大家能仔细的浏览,帮大家解决问题。
建立PPP拨号,把其中一条拨号名命名为ADSL1,另一个命明为ADSL2,并把内网网卡命名为LAN,然后等待拨号成功,设置参考下图
拨号成功后,PPPOE会自动添加IP地址和网关,找到地址和网关,复制下来,替换到下面脚本中,把A1IP替换成ADSL1的IP,A1网关替换成ADSL1的网关,把A2IP替换成ADSL2的IP,A2网关替换成ADSL2的网关.之后慢慢添脚本,添完成功后,把拨号的Add Default Route的勾去掉,看负载均衡是否可以正常工作!
编辑推荐
负载均衡技术基础专题
当前,无论在企业网、园区网还是在广域网上,即使按照当时最优配置建设的网络,业务量的发展都超出了过去..
本文介绍了双ADSL下的NTH的负载均衡设置问题。包括普通脚本,nat,还有IP等相关内容。那么,具体的代码,请从下文中参考。
1.普通脚本设置
/ ip firewall nat
add chain=srcnat action=masquerade comment="3" disabled=yes
/ ip address
add address=A1IP interface=ADSL1 comment="1" disabled=no
add address=A2IP interface=ADSL2 comment="2" disabled=no
/ ip route
add dst-address=0.0.0.0/0 gateway=A1网关 routing-mark=1 comment="1"
add dst-address=0.0.0.0/0 gateway=A2网关 routing-mark=2 comment="2"
add dst-address=0.0.0.0/0 gateway=A1网关 comment="3"
2.添加NAT,NTH脚本
/ ip firewall mangle
add chain=prerouting in-interface=LAN protocol=tcp connection-state=new nth=1,1,0 action=mark-connection \\
new-connection-mark=1 passthrough=yes comment="A1 NTH" disabled=no
add chain=prerouting in-interface=LAN protocol=tcp connection-mark=1 action=mark-routing new-routing-mark=1 \\
passthrough=no comment="A1 NTH" disabled=no
add chain=prerouting in-interface=LAN protocol=tcp connection-state=new nth=1,1,1 action=mark-connection \\
new-connection-mark=2 passthrough=yes comment="A2 NTH" disabled=no
add chain=prerouting in-interface=LAN protocol=tcp connection-mark=2 action=mark-routing new-routing-mark=2 \\
passthrough=no comment="A2 NTH" disabled=no
/ ip firewall nat
add chain=srcnat connection-mark=1 action=src-nat to-addresses=A1IP to-ports=0-65535 comment="1" disabled=no
add chain=srcnat connection-mark=2 action=src-nat to-addresses=A2IP to-ports=0-65535 comment="2" disabled=no
编辑推荐
负载均衡技术基础专题
当前,无论在企业网、园区网还是在广域网上,即使按照当时最优配置建设的网络,业务量的发展都超出了过去..
本文介绍了双ADSL下的NTH的负载均衡设置问题。包括普通脚本,nat,还有IP等相关内容。那么,具体的代码,请从下文中参考。
3.同步NAT,ADSL动态IP,网关脚本:位置winbox-system-script 点“+ ”号,改name为sync,然后复制下面的脚本到source里
: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)]
:set new-gateway [/ip address get [/ip address find dynamic=yes interface=("ADSL" . $i)] network]
:set adckip [/tool netwatch get [/tool netwatch find comment=$i] host]
: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-gateway]
/ip firewall nat set [/ip firewall nat find comment=$i] to-addresses=$new-address
/ip route set [/ip route find comment=$i] gateway=$new-gateway]
}
:if ($new-gateway != $adckip) do={/tool netwatch set [/tool netwatch find comment=$i] host=$new-gateway]
}
}
}
4.添加ADSL1当线脚本A1Down,自动停用NTH负载均衡所需的参数,并将标记3的网关设为ADSL2的网关,位置winbox-system-script 点“+ ”号,改name为A1Down,然后复制下面的脚本到source里
:local new-gateway
:set new-gateway [/ ip address get [/ip address find dynamic=yes interface=ADSL2] network]
/ip route set [/ip route find comment=3] gateway=$new-gateway
/ip route enable [/ip route find comment=3]
/ip route disabled [/ip route find comment=1]
/ip route disabled [/ip route find comment=2]
/ip firewall nat enable [/ip firewall nat find comment=3]
/ip firewall nat disabled [/ip firewall nat find comment=1]
/ip firewall nat disabled [/ip firewall nat find comment=2]
5.添加ADSL2当线脚本A2Down,自动停用NTH负载均衡所需的参数,并将标记3的网关设为ADSL1的网关,位置winbox-system-script 点“+ ”号,改name为A2Down,然后复制下面的脚本到source里
:local new-gateway
:set new-gateway [/ ip address get [/ip address find dynamic=yes interface=ADSL1] network]
/ip route set [/ip route find comment=3] gateway=$new-gateway
/ip route enable [/ip route find comment=3]
/ip route disabled [/ip route find comment=1]
/ip route disabled [/ip route find comment=2]
/ip firewall nat enable [/ip firewall nat find comment=3]
/ip firewall nat disabled [/ip firewall nat find comment=1]
/ip firewall nat disabled[/ip firewall nat find comment=2]
编辑推荐
负载均衡技术基础专题
当前,无论在企业网、园区网还是在广域网上,即使按照当时最优配置建设的网络,业务量的发展都超出了过去..
本文介绍了双ADSL下的NTH的负载均衡设置问题。包括普通脚本,nat,还有IP等相关内容。那么,具体的代码,请从下文中参考。
6.添加ADSL掉线判断NETWATCH
/ tool netwatch
add host=A1网关 timeout=1s interval=1m up-script="" down-script="A1Down" comment="1"
add host=A2网关 timeout=1s interval=1m up-script="" down-script="A2Down" comment="2"
7.添加双线判断正常脚本allup。即两条线路UP的时候开启NTH负载均衡。位置winbox-system-script 点“+ ”号,改name为allup,然后复制下面的脚本到source里
:global a
:global b
:set a [/tool netwatch get [/tool netwatch find comment=1] status]
:set b [/tool netwatch get [/tool netwatch find comment=2] status]
:if (($a="up") && ($b="up")) do={
/ip route disabled [/ip route find comment=3]
/ip route enable [/ip route find comment=1]
/ip route enable [/ip route find comment=2]
/ip firewall nat disabled [/ip firewall nat find comment=3]
/ip firewall nat enable [/ip firewall nat find comment=1]
/ip firewall nat enable [/ip firewall nat find comment=2]}
8.添加脚本计划任务
/ system scheduler
add name="tasksync" on-event=sync start-date=jan/01/1970 start-time=00:00:00 interval=10s comment=""
add name="taskup" on-event=allup start-date=jan/01/1970 start-time=00:00:00 interval=10s comment=""
佟媛微
编辑推荐
负载均衡技术基础专题
当前,无论在企业网、园区网还是在广域网上,即使按照当时最优配置建设的网络,业务量的发展都超出了过去..
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。