网关软路由ROS固定IP、adsl双线NTH负载均衡

双线双ip  时间:2021-01-13  阅读:()

实验环境

虚拟设备

1 Router OS 2.9.27 三台

2 w inxpX P一台

虚拟机网络连接

Router OS- 1 Ether1桥接物理主机IP 192.168.0.164/24

Router OS – 1 Ether2分配给VMnet2 IP 1.0.0.1/24

Router OS – 2 Ether1桥接物理主机 IP 192.168.0.165/24

Router OS – 2 Ether2分配给VMnet3 IP 11.0.0.1/24

Router OS – 3 Ether 1分配给VMnet4 IP 172.16.0.254/24

Router OS – 3 Ether2分配给VMnet2 IP PPPOE自动获取

Router OS – 3 Ether3分配给VMnet3 IP 11.0.0.50/24

WINXP 网卡1分配给VMnet4 ip pppoe 自动获取

实验前已配置好的环境

1 确认各个接口 已PING通后删除ROU TEROS-3接口配置未实现NTH负载均衡。

2 ROUTER OS – 1和ROUTER OS- 3的PPPOE拨号服务器已配置好

3 ROUTER OS – 1和ROUTER OS – 2的NAT 已经配置完可以让WIN XP通过ROUTER OS-3 Ether3 的固定IP访问外部真实局域网。

配置过程以下操作均在ROUTER OS – 3进行

1 配置pppo e-c lient在Ether 2上给Ether 1和Ethe r3配置IP 以下所有注释不要更改为

其他的。

2 标记奇偶连接数据包(NTH)。因为是双线所以标记两条。再加一条

3 配置NAT。 1是随便设~TO-ADDRES S用脚本自动修改2就不能乱设了~要设置固定接

口的IP添加3这条是单线时 用到

4 添加静态路由表。 //3是用于单线双线时自动停用。 1、 2做路由分发这个不用选标记的路由包MARK空

5 添加bala nce脚本 PPPOE拨号掉线IP、 网关、NAT自动修改。

:local assign-address

:local new-address

:loc al status

:loc al adckip

:local new-gateway

:local x

:set x 1

#如果從1加1到等于变量x时则做,同时将X赋值给i

:for i from=1 to=$x do={

#查找接口名称=pppoe-out加i的接口是否激活,比如i循环到1那么就是p ppoe-out1.将结果赋给

:set status [/interfac e get [/interfac e find name=("pppoe-out" . $i)] running]

#如果stat us激活=真,则做

:if($s tatus=true)do={

#设置new-addres s,从IP地址列表里查找dy namic等于yes的接口,并取得该接口 的IP地址

:set new-address [/ip address get [/ip address find dynami c=yes interface=("pppoe-out" . $i)]addres s]

#将取得的IP地址,取总字符长度再减3

:set new-address [:pick$new-address 0([:len$new-address] -3)]

# //查找非动态接口地址,将它赋值给a ssign-addres s

:set assign-address [/ip address get [/ip address find dynami c=no interface=("pppoe-out" . $i)]addres s]

:set assign-address [:pick$assign-address 0([:len$assign-address] -3)]

#取拨号的动态网关可以将ppp oe-out1改为(“pppoe-out”.$i)

:set new-gateway [/ip addres s get [/ip addres s find dynami c=yes interf ace=pppoe-out1]netw ork]

#取netwa tch状态检查PPPOE拨号的hos t参数

:set adckip[/tool netwatch get [/tool netwatch find comment=$i]host]

#//如果pppo e-out加$i的$assign-addres s静态地址不等于$new-addres s,则做,将地址\子网\广播地址都设置为$new-addres s取得的地址.

:if ($assign-address != $new-address) do={ /ip addres s set [/ip addres s find commen t=$i]address=$new-address network=$new-address broadcast=$new-addres s

/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

}

#如果新的网关不等于$adckip则将PPPO E拨号链路状态检查IP设为新的

host=$new-gateway]

}

}

}

6 添加光纤当线脚本fdow n 自动停用NT H负载所需的参数

:local new-gateway

:set new-gateway[/ip address get [/ip address find dynamic=yes interface=pppoe-out1]network]#固定IP的链路当掉后将网关默认路由的下一跳的网关设为PPPO E获取的网关

/ip route set [/ip route find c omment=3]gateway=$new-gateway

/ip route enable [/ip route find comment=3]

/ip route dis [/ip route find c omment=1]

/ip route dis [/ip route find c omment=2]

/ip firewall nat enable [/ip firewall nat find comment=3]

/ip firewall nat dis [/ip firewall nat find comment=1]

/ip firewall nat dis [/ip firewall nat find comment=2]

7 添加ADSL当线脚本ad sldownADSL掉线后将默认路由下一跳网关设为固定IP的网关

/ip route set [/ip route find c omment=3]gateway=11.0.0.1

/ip route enable [/ip route find comment=3]

/ip route dis [/ip route find c omment=1]

/ip route dis [/ip route find c omment=2]

/ip firewall nat enable [/ip firewall nat find comment=3]

/ip firewall nat dis [/ip firewall nat find comment=1]

/ip firewall nat dis[/ip firewall nat find comment=2]

8. .添加双线判断正常脚本li nkup。即两条线路UP的时候开启NTH负载均衡。

:global a

:global b

#取当前两条链路状态

:set a[/tool netwatch get [/tool netwatch find comment=1] status]

:set b[/tool netwatch get [/tool netwatch find host=11.0.0.1] status]

#如果两条线路都为UP则启用NTH负载均衡设置。

:if(($a="up")&&($b="up"))do={

/ip route dis [/ip route find c omment=3]

/ip route ena[/ip route find c omment=1]

/ip route ena[/ip route find c omment=2]

/ip firewall nat dis [/ip firewall nat find comment=3]

/ip firewall nat ena [/ip firewall nat find comment=1]

/ip firewall nat ena [/ip firewall nat find comment=2]}

9.为balan ce脚本设置定时运行

10.设置定时检查两条线路的状态UP或dow n则触发事件运行脚本。 //

加注释1一定要加不然不会自动更改host,因为这条是A DSL的线路。

好设置完毕还要运行下脚本初始化先fdown,再linku p,OK了现在测试nt h负载均衡 一个失误~哈哈没改成1

郁闷可能是论坛没开所以打不开网页

得了~看流量刚刚的配置生效需要一点时间

测试下载文件我这个XP的拨号是限制最大4M下载流量的等我开HTTP服务器先~看到了把 ether2是AD S L ether 3是固定IP因为XP的拨号帐号是最大下载4M所以两条线下载的不会超4M

好了现在测试其中掉线切换为单线先停掉1.0.0.1的路由器  当掉后自动停用了路由表。只起用3

打开论坛试试ping真实局域网的IP 192.168.0.158OK

再开启1.0.0.1

等下UP了之后就会启用负载均衡稍等~看

关掉固定IP的路由器11 .0.0.1稍等

启用单线了~再开启11.0.0.1测试负载均衡稍等UP了

Dynadot多种后缀优惠域名优惠码 ,.COM域名注册$6.99

Dynadot 是一家非常靠谱的域名注册商家,老唐也从来不会掩饰对其的喜爱,目前我个人大部分域名都在 Dynadot,还有一小部分在 NameCheap 和腾讯云。本文分享一下 Dynadot 最新域名优惠码,包括 .COM,.NET 等主流后缀的优惠码,以及一些新顶级后缀的优惠。对于域名优惠,NameCheap 的新后缀促销比较多,而 Dynadot 则是对于主流后缀的促销比较多,所以可以各取所...

RAKsmart 黑色星期五云服务器七折优惠 站群服务器首月半价

一年一度的黑色星期五和网络星期一活动陆续到来,看到各大服务商都有发布促销活动。同时RAKsmart商家我们也是比较熟悉的,这次是继双十一活动之后的促销活动。在活动产品中基本上沿袭双11的活动策略,比如有提供云服务器七折优惠,站群服务器首月半价、还有新人赠送红包等活动。如果我们有需要RAKsmart商家VPS、云服务器、独立服务器等产品的可以看看他们家的活动。这次活动截止到11月30日。第一、限时限...

MineServer:香港CMI/洛杉矶GIA VPS,2核/2GB内存/20GB NVME/3.5TB流量/200Mbps/KVM,288元/年

mineserver怎么样?mineserver是一家国人商家,主要提供香港CN2 KVM VPS、香港CMI KVM VPS、日本CN2 KVM VPS、洛杉矶cn2 gia端口转发等服务,云服务器网(yuntue.com)介绍过几次,最近比较活跃。现在新推出了3款特价KVM VPS,性价比高,香港CMI/洛杉矶GIA VPS,2核/2GB内存/20GB NVME/3.5TB流量/200Mbps...

双线双ip为你推荐
美国虚拟主机美国虚拟主机购买具体注意什么。。虚拟主机服务器服务器于虚拟主机之间的区别,详细点。info域名注册INFO域名有没有注册价值?免费虚拟主机申请求免费可以申请的域名和虚拟主机网站服务器租用哪些网站适合独立服务器租用?价格方面怎么样?me域名.me域名和com的价值对比,懂的告诉我呀php虚拟空间我已经有一套网站php代码和模板,并且有自己的虚拟空间和域名,怎么才能把我的代码加入到网站上.深圳网站空间菜鸟问:网站空间如何选择,与空间的基本知识?apache虚拟主机如何用Apache配置安全虚拟主机 - PHP进阶讨论域名网站域名和网址一样吗?
2019年感恩节 荣耀欧洲 linode日本 suspended directadmin 日本空间 hinet 银盘服务是什么 西安服务器托管 服务器维护 江苏徐州移动 黑科云 杭州电信 数据湾 锐速 so域名 卡巴斯基免费版下载 神棍节 ssd 西安电信测速网 更多