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

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

列如:映射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
==================================================================tcp

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

列如:映射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”)fetch

/ 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
}url

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

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

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

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

#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

相关文章
相关标签/搜索