网关软路由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了

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...

SpinServers(月89美元) 2*e5-2630L v2,美国独立服务器

SpinServers服务商也不算是老牌的服务商,商家看介绍是是2018年成立的主机品牌,隶属于Majestic Hosting Solutions LLC旗下。商家主要经营独立服务器租用和Hybrid Dedicated服务器等,目前包含的数据中心在美国达拉斯、圣何塞机房,自有硬件和IP资源等,商家还自定义支持用户IP广播到机房。看到SpinServers推出了美国独服的夏季优惠促销活动,最低月...

ProfitServer$34.56/年,5折限时促销/可选西班牙vps、荷兰vps、德国vps/不限制流量/支持自定义ISO

ProfitServer怎么样?ProfitServer好不好。ProfitServer是一家成立于2003的主机商家,是ITC控股的一个部门,主要经营的产品域名、SSL证书、虚拟主机、VPS和独立服务器,机房有俄罗斯、新加坡、荷兰、美国、保加利亚,VPS采用的是KVM虚拟架构,硬盘采用纯SSD,而且最大的优势是不限制流量,大公司运营,机器比较稳定,数据中心众多。此次ProfitServer正在对...

双线双ip为你推荐
网络域名注册什么叫做网络域名 怎么注册网络域名 以及它的收费方式主机租赁电脑租赁的缺点网站空间租赁网站空间租用费多少.net虚拟主机.net虚拟主机空间怎么选择,国内虚拟主机哪家比较好,各有什么特色免费云主机永久免费的云主机哎或者空间或者vps海外主机美国主机与国内主机有哪些区别网站服务器租用个人网站服务器租用一年多少钱免费vps服务器请推荐一个免费的云服务器?天津虚拟主机天津APP开发的比较专业的公司有哪些?深圳虚拟主机深圳鼎峰网络科技 虚拟主机空间怎么样
php主机空间 万网域名代理 域名备案批量查询 西安电信测速 Dedicated 59.99美元 mediafire下载 debian源 中国电信测速112 空间论坛 七夕促销 admit的用法 老左正传 空间购买 linode支付宝 rewritecond 腾讯云平台 蓝队云 linux服务器系统 删除域名 更多