方法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 }
或在终端运行以下代码
system – scheduler add name=”schedule111″ on-event=”#刷新脚本(此脚本放到调度程序里面定时运行来更新ADSL的IP到映射的IP)" :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}” 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”
评论前必须登录!
注册