WIFIHELL - 科技改变生活

 找回密码
 注册WIFIHELL

QQ登录

只需一步,快速开始

开启左侧

ROS做端口映射DDNS的N个做法详细教程

[复制链接]
222ba 发表于 2018-5-9 16:21:45 | 显示全部楼层 |阅读模式

注册WIFIHELL,浏览更多技术贴!

您需要 登录 才可以下载或查看,没有账号?注册WIFIHELL

x
[url=]1321人阅读[/url]

方法1(IP方法)
/ ip firewall nat
add chain=dstnat dst-address!=内网网关 protocol=tcp dst-port=要开放的外网端口 \
action=dst-nat to-addresses=要映射的内网IP地址 to-ports=要映射的内网端口 comment=”” \
disabled=no

列如:映射80端口到192.168.200的80端口
/ ip firewall nat
add chain=dstnat dst-address!=192.168.1.1 protocol=tcp dst-port=80 \
action=dst-nat to-addresses=192.168.200 to-ports=80 comment=”mapping” \
disabled=no
==================================================================

方法2(接口方法)
/ ip firewall nat
add chain=dstnat in-interface=adsl接口名 protocol=tcp dst-port=要开放的外网端口 \
action=dst-nat to-addresses=要映射的内网IP地址 to-ports=要映射的内网端口 comment=”” \
disabled=no

列如:映射80端口到192.168.200的80端口
/ ip firewall nat
add chain=dstnat in-interface=pppoe-out1 protocol=tcp dst-port=80 \
action=dst-nat to-addresses=192.168.1.200 to-ports=80 comment=”mapping” \
disabled=no
==================================================================
方法3(固定IP+脚本更新IP方法,通过注释判断comment=”mapping”)

/ ip firewall nat
add chain=dstnat dst-address=10.10.10.10 protocol=tcp dst-port=80 \
action=dst-nat to-addresses=192.168.200 to-ports=80 comment=”mapping” \
disabled=no
#刷新脚本(此脚本放到调度程序里面定时运行来更新ADSL的IP到映射的IP)
#调度程序位置在 system – scheduler
:local oldip
:local newip
:set newip [/ip address get [/ip address find dynamic=yes interface=pppoe-out1 ] address ]
:put $newip
:set oldip [/ip firewall nat get [find comment=mapping] dst-address ]
:if ($newip != $oldip) do={
/ip firewall nat set [find comment=mapping] dst-address=$newip
}

或在终端运行以下代码
add name=”schedule111″ \
on-event=”#刷新脚本(此脚本放到调度程序里面定时运行来更新ADSL的IP到映射的IP)\

\n:local oldip
\n:local newip
\n:set newip \[/ip address get \[/ip \
address find dynamic=yes interface=pppoe-out1 \] address \]
\n:put \
\$newip
\n:set oldip \[/ip firewall nat get \[find comment=mapping\] \
dst-address \]
\n:if (\$newip != \$oldip) do={
\n/ip firewall nat \
set \[find comment=mapping\] dst-address=\$newip
\n}” \
start-date=jan/01/1970 start-time=00:00:00 interval=30s comment=”” \
disabled=no

运行后会自动在调度程序里添加上面那个脚本(默认30秒运行一次)
在调度程序system – scheduler可以看到该脚本

==================================================================
#IP伪装
/ ip firewall nat
add chain=srcnat action=masquerade comment=”” disabled=no

#IP回流
add chain=srcnat src-address=内网IP段/24 protocol=tcp action=masquerade \
comment=”” disabled=no

==================================================================
方法4(简单直接)
/ ip firewall nat
add chain=dstnat src-address!=内网IP段 dst-address!=内网网关 protocol=tcp dst-port=要开放的外网端口 \
action=dst-nat to-addresses=要映射的内网IP地址 to-ports=要映射的内网端口 comment=”” \
disabled=no

列如:映射80端口到192.168.200的80端口
/ ip firewall nat
add chain=dstnat src-address!=192.168.1.0/24 dst-address!=192.168.1.1 protocol=tcp dst-port=80 \
action=dst-nat to-addresses=192.168.200 to-ports=80 comment=”mapping” \
disabled=no

动态域名解析:
3322解析脚本:

:local ednsuser “user”
:local ednspass “password”
:local ednshost “user.3322.org”
:local ednsinterface “pppoe-out1″
:local members “http://members.3322.org/dyndns/update?system=dyndns
#:local members “http://members.dyndns.org/nic/update?
:local status
:local status [/interface get [/interface find  name=$ednsinterface] running]
:if ($status!=false) do={
:local ednslastip [:resolve $ednshost]
:if ([ :typeof $ednslastip ] = nil ) do={ :local ednslastip “0″ }
:local ednsiph [ /ip address get [/ip address find interface=$ednsinterface ] address ]
:local ednsip [:pick $ednsiph 0 [:find $ednsiph “/”]]
:local ednsstr “&hostname=$ednshost&myip=$ednsip”
:if ($ednslastip != $ednsip) do={/tool fetch url=($members . $ednsstr) mode=http user=$ednsuser password=$ednspass dst-path=$ednshost
:delay 2
:local result [/file get $ednshost contents]
:log info ($ednshost . ” ” .$result)
/file remove $ednshost ;
}
}

changeip.net 脚本
:global ddnsuser “user”

:global ddnspass “pass”

:global ddnshost “user.changeip.net”

:global ddnsinterface “pppoe-out1″

:global ddnslastip

:global ddnsip [ /ip address get [/ip address find dynamic=yes interface=$ddnsinterface ] address ]
:if ( [:typeof $ddnslastip]=”nothing” ) do={ :global ddnslastip 0.0.0.0/0 }
:if ( [:typeof $ddnsip]=”nothing” ) do={
:log info (“DDNS: No ip address present on ” . $ddnsinterface . “, please check.”)
} else={
:if ($ddnsip != $ddnslastip) do={
:log info “DDNS: Sending Update!”
:log info [ /tool dns-update name=$ddnshost address=[:pick $ddnsip 0 [:find $ddnsip “/”] ] key-name=$ddnsuser key=$ddnspass ]
:global ddnslastip $ddnsip
} else={
:log info “DDNS: No change”
}
}
:log info “DDNS: End”

论坛发现有人求助,如何定时启动脚本、定时开关某个或者某些防火墙。其实这是一个很简单的问题,大侠们都已
经很熟了。但还是有写菜鸟不怎么会,那我就来讲解下,非脚本-winbox下的操作。
1:定时任务。
我进入到system里找到schedule点开。点击+号,新建一个定时任务,如图

6 天前 上传
下载附件 (34.49 KB)

Strat Date 这里定义任务什么日期开始执行,如非特殊情况不需更改,除非你要这个任务100年后执行可以改为
Jan/01/2111
Start Time  这里定义任务开始的时间,例如下午3点执行,里面的值就是15:00:00
Interval      这里定义任务多久执行一次r,例如1天一次,里面的值就是1d 00:00:00
30分钟一次,里面的值就是00:30:00

到此我们清楚各项的含义,就可以组合起来使用了:
例1:我要执行一个任务每10秒执行一次
Strat Date 默认  Start Time  00:00:00 Interval 00:00:10 就可以了
如此定义每10分中执行一次,10小时一次,10天一次 项Interval值做相应的改变就是了

例2:我要执行一个任务每天8点20分执行
Strat Date 默认  Start Time  08:20:00 Interval 1d 00:00:00 就可以了
此时要注意的是,看看/system clock 里的时间是否准确,否者你会发现脚本执行的时间不是你定义的时间

脚本如何定时执行我们了解了,那么如何定时开关某些东西,运行某些东西呢?此时On Event:里面的内容就是肉
戏了我们都是知道在ros 里面大多地方我都可以为一些东西定义comment值来做说明,例如网卡、ip address、防火墙、
限速等等。commnet的意义不只是止于说明而已,通过comment的值我们可以开发很多脚本,例如论他很多大大开发
的PCC断线修改PCC参数脚本等都利用了comment值,当然我说这么多不是要讲comment的应用,嗯,淡定、淡定,我
想说的是,用这个comment值,我们配喝schedule来执行一些简单的开关而已、请大家淡定。
举例说明:(内容不包含已说明的如何定时执行)
例1:我要关闭一些防火墙,我们定义这些防火墙的comment值为 1
在On Event: 里写入
/ip firewall filter (进入防火墙目录)
disable “1″       (关闭所有comment值为1的项,当然开启就是enable)

例2:我要关闭一些网卡,我们定义这些网卡的comment值为 1
在On Event: 里写入
/interface   (进入网卡目录)
disable “1″       (关闭所有comment值为1的网卡,当然开启就是enable)

例3:我要开启一些简单限速脚本,我们定义这些脚本的comment值为 1
在On Event: 里写入
/queues simple  (进入简单限速目录)
enable “1″       (开启所有comment值为1的简单限速)
例4:我要执行/system script 下名称为 xxx的脚本
在On Event: 里写入
xxx




WIFIHELL | 万丰乐活 2020开启新的征程,好货不断!
关闭

站点推荐上一条 /1 下一条

万丰乐活

GMT+8, 2024-4-28 02:17

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表