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

相關文章
相關標籤/搜索