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

实际在用的脚本,需要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:

然后是一个任务:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值