本帖最后由 rappleboy 于 2015-3-10 16:01 编辑
家里有主路由网件4300和监控器路由 buffalo wzr-hp-300nh2两台,主路由联联通光线,监控路由192.168.1.100通过局域网连接主路由192.168.1.1,192.168.1.0网段内。 主要希望在单位能外网远程连接和管理监控路由。
防火墙打开主路由的WEB远程和SSH远程比较顺利:
在/etc/config/firewall文件中加入
config rule
option target 'ACCEPT'
option src 'wan'
option proto 'tcp'
option dest_port '8085'
option name 'web'
config redirect
option target 'DNAT'
option src 'wan'
option dest 'lan'
option proto 'tcp udp'
option src_dport '8085'
option dest_ip '192.168.1.1'
option dest_port '80'
option name '8085'
config redirect
option target 'DNAT'
option src 'wan'
option dest 'lan'
option proto 'tcp'
option src_dport '22'
option dest_ip '192.168.1.1'
option dest_port '22'
option name 'ssh'
/etc/init.d/firewall restart 后成功远程打开
但是打开监控路由192.168.1.100的8080监控WEB端口却怎么也不成功。
config rule
option target 'ACCEPT'
option src 'wan'
option proto 'tcp udp'
option dest_port '8080'
option name '8080'
config redirect
option target 'DNAT'
option src 'wan'
option dest 'lan'
option proto 'tcp'
option src_dport '8080'
option dest_ip '192.168.1.100'
option dest_port '8080'
option name 'jiankong'
打开http://DDNS:8080 总是显示网页无法打开。刚开始以为格式写的问题,但发现同样的写法,映射到一台电脑的UltraVNC的5900端口是可以正常打开和远程控制成功的。
于是在恩山和openwrt各种搜索和尝试,各种无果,各种失败,最后还是在openwrt的wiki里http://wiki.openwrt.org/doc/uci/firewall查到一个小讨厌
Masquerading on lan
The router 2 cannot reply to those packets because we didn't adjust its routing table, that is we didn't specify that the gateway to reply to "wan" sources is the router 1. Indeed those redirected packets will have an source ip external from the (default) "lan" zone 192.168.1.0/24.
We can solve this activating the masquerading on the "lan" zone on the router 1, in this way.
config zone option name 'lan' list network 'lan' option input 'ACCEPT' option output 'ACCEPT' option forward 'ACCEPT' option masq '1'
尝试着加入firewall, restart, 远程访问一下,我去,一看状态栏反应我就知道成功了,这个小讨厌让我耗费了一天时间阿,终于可以出去看看阳光了拉
总结一下,一般的端口映射是router->pc的,pc是终端用户,可以正常返回package, 但是router->router的端口映射比较特殊,目的router不可以直接返回package,需要在主路由的lan zone里设置允许冒充假pc来获得映射。
最后感谢一下 明月永在 rapistor, 两个路由都是用的他制作的openwrt 固件,很不错
|