背景:
家里的 荣耀路由器 Pro 2 的 NAT 配置限制非常多,不能手动指定 IP 地址,只能选择设备。但是,这个设备还不能是路由器!
所以,我不能将请求路由给 LAN 口上的子路由器,导致子路由器上连接的设备无法从外部访问。
因此,我将内网中的树莓派4配置为 DMZ 主机,打算通过 iptables, nginx 等手段作为路由器的补充。
实现方案
背景
网络拓扑图如下:

网络结构非常简单,Server 作为 R1 的 DMZ 主机,如果要实现外网访问 Server,完全就是 R0 一条 NAT 的事情。
但是! R0 这类消费级的路由器,UI 缺少很多路由器本身能实现的功能,包括 静态路由表 等。更奇葩的是:
这个路由器的 NAT、DMZ 等功能不能选择路由器作为目标!且不能手动输入NAT、DMZ 的目标 IP 地址!
当前在线的终端如下:

DMZ 可选设备完整列表如下(NAT可选设备列表相同):


DMZ 和 NAT 都不可以选连接在 LAN 口上的路由器!
因此,本人尝试使用运行 Linux 系统的树莓派 RPi 实现 NAT 到子路由器的功能。
预期结果
RPi 作为 R0 的 DMZ 主机,只要 PC 能通过 RPi 连接 Server,外网就可以访问到 Server。

Nginx 实现(简单)
通过 Nginx 实现 TCP、UDP 等协议的转发比较简单
安装 Nginx (–with-stream)
可以通过 apt、yum 等直接安装功能比较全的版本 nginx-extras,该版本包括了 stream 等模块
sudo apt install -y nginx-extras
通过以下命令,确认 nginx 带有 --with-stream 编译参数
nginx -V
输出结果,可以看到 --with-stream=dynamic
nginx version: nginx/1.14.2
built with OpenSSL 1.1.1c 28 May 2019 (running with OpenSSL 1.1.1d 10 Sep 2019)
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-v2a0Oa/nginx-1.14.2=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_sli

本文介绍了一种利用树莓派和Nginx解决荣耀路由器Pro2 NAT配置限制的方法,通过配置树莓派作为DMZ主机,实现了内网设备的外部访问。
最低0.47元/天 解锁文章
562

被折叠的 条评论
为什么被折叠?



