17、ROS 动态映射
一、动态映射设置:
1、先手动静态映射一下:
IP —— Firewall —— NAT —— 点击加号
(General —— Chain:dstnat —— Dat.Address:要映射成的IP地址 —— Protocol:6 (tcp) —— Dst.Port:8080)
(Action —— Action:dst-nat —— To Address:要映射出去的地址 —— To Port:要映射出去的端口80)
2、使用脚本:使其动态获取ADSL拨号获得的IP地址,并将服务映射到该IP上:
System —— Scripts —— 点击加号 —— Name:动态映射 —— 添加脚本如下:
:global new
:global status
:global x 定义三个全局变量
:set x 9 有多少条ADSL拨号线设置为数字几
:for i from=1 to=$x do={
:set status [/interface get [/interface find name=("接口名称" . $i)] running]
:if ($status=true) do={
:set new [/ip address get [/ip address find dynamic=yes interface=("接口名称" . $i)] address ]
:set new [:pick $new 0 ([:len $new] -3)]
/ip firewall nat set [/ip firewall nat find comment=("备注名" . $i)] dst-address=$new
}
}
3、添加到计划任务,自动执行
System —— Scheduler —— 点击加号 —— Name:动态映射 —— Interval:多长时间执行一次 —— On Event:添加要执行的脚本名称 —— OK