ROS路由器环回脚本,实际在用,只需要更新一个IP地址

发布时间 2023-09-11 12:40:40作者: 海宏软件

实际在用的脚本,需要ros版本较高,低版本可以照着自己改改用,亲测可以。

 

#取当前拨号ip地址
:global ednsiph [ /ip address get [/ip address find interface="pppoe-out1" ] address ]
:global newip [:pick \$ednsiph 0 [:find \$ednsiph \"/\"]]

#新建回流规则
/ip firewall nat
add action=dst-nat chain=dstnat comment="huiliu" dst-address=$newip\
    dst-address-type=local dst-port=88 protocol=tcp \
    to-addresses=192.168.88.3 to-ports=80
add action=masquerade chain=srcnat comment="huiliu-99" \
    out-interface-list=LAN src-address=192.168.88.0/24


#新建任务,每隔10分钟更新一遍huiliu的目标ip地址
/system scheduler
add name=huiliu comment="\B8\FC\D0\C2\BB\D8\C1\F7\B2\A6\BA\C5\B5\C4IP\B5\D8\D6\B7" \
    interval=10m on-event=":global adsl \"pppoe-out1\"\r\
    \n:global oldip [ /ip firewall nat get [/ip firewall nat find comment=\"huiliu\"] dst-address ]\r\
    \n:global ednsiph [ /ip address get [/ip address find interface=\$adsl ] address ]\r\
    \n:global newip [:pick \$ednsiph 0 [:find \$ednsiph \"/\"]]\r\
    \n#:log info \$oldip\r\
    \n#:log info \$newip\r\
    \n:if (\$newip != \$oldip) do={ \r\
    \n  :log info [/ip firewall nat set [/ip firewall nat find comment=\"huiliu\"] dst-address=\$newip ]\r\
    \n  :log info \"\CD\E2\CD\F8\B5\D8\D6\B7\CE\AA(\$newip)\" \r\
    \n}" start-time=00:00:00

一共两个:

 

第一个dstnat:

 

第二个 srcnat:

 

然后是一个任务:

 

海宏原创,转载请标明。