前言
前两周某NAS厂商爆出了“非授权访问系统路径及文件”的重大安全问题,我们再次不得不重视NAS设备的安全问题,这对于重度依赖以及喜欢折腾NAS的朋友来说是非常重要的
家用NAS带来了很大的便利性,但家用宽带通常没有固定的公网IP地址。我们在外网想访问家里的NAS服务,默认情况下是不行的
最直接的办法当然是申请固定公网IP,但需要找运营商申请,可能还要加💰
这里说的公网访问,主要是指如何自己实现从外(公)网访问家里的NAS设备。现在很多老牌NAS厂商和一些新兴的国产NAS厂商均会提供某些小白用户开箱即用的公网访问方案,这些方案本文不做分析及评价
前面写过组建WireGuard网络,我用此方案实现自己的多设备在外网情况下访问家中的NAS设备上的服务
在此之前,通过调研整理了以下几种解决方案,下面逐一介绍
方案分类
方案一:VPN隧道
此方案也是我认为目前最安全保险+够用的方案,毕竟安全生产是第一要素~
原理:建立加密的虚拟专网,外网设备先连VPN,然后像在本地一样访问NAS。
<svg aria-roledescription="flowchart-v2" document="" ms="" role="graphics-document" style="font-family:" viewbox="0" width="100%" xmlns="http://www.w3.org/2000/svg"><g><marker markerheight="8" markerunits="userSpaceOnUse" markerwidth="8" orient="auto" refx="5" refy="5" style="fill:" viewbox="0"><path d="M" l="" style="stroke-width:" z=""></path></marker><marker markerheight="8" markerunits="userSpaceOnUse" markerwidth="8" orient="auto" refx="4.5" refy="5" style="fill:" viewbox="0"><path d="M" l="" style="stroke-width:" z=""></path></marker><marker markerheight="11" markerunits="userSpaceOnUse" markerwidth="11" orient="auto" refx="11" refy="5" style="fill:" viewbox="0"><circle cx="5" cy="5" r="5" style="stroke-width:"></circle></marker><marker markerheight="11" markerunits="userSpaceOnUse" markerwidth="11" orient="auto" refx="-1" refy="5" style="fill:" viewbox="0"><circle cx="5" cy="5" r="5" style="stroke-width:"></circle></marker><marker markerheight="11" markerunits="userSpaceOnUse" markerwidth="11" orient="auto" refx="12" refy="5.2" style="fill:" viewbox="0"><path d="M" l="" m="" style="stroke-width:"></path></marker><marker markerheight="11" markerunits="userSpaceOnUse" markerwidth="11" orient="auto" refx="-1" refy="5.2" style="fill:" viewbox="0"><path d="M" l="" m="" style="stroke-width:"></path></marker><g><g></g><g><path d="M136,35L144.833,35C153.667,35,171.333,35,189,35C206.667,35,224.333,35,233.167,35L242,35" marker-end="url(#mermaid-1757251945827_flowchart-v2-pointEnd)" marker-start="url(#mermaid-1757251945827_flowchart-v2-pointStart)" none="" style="stroke-width:"></path><path d="M386.531,35L395.365,35C404.198,35,421.865,35,439.531,35C457.198,35,474.865,35,483.698,35L492.531,35" marker-end="url(#mermaid-1757251945827_flowchart-v2-pointEnd)" marker-start="url(#mermaid-1757251945827_flowchart-v2-pointStart)" none="" style="stroke-width:"></path></g><g><g center="" rgba="" style="background-color:" transform="translate(189,"><g ms="" style="font-family:" transform="translate(-32,"><foreignobject height="24" width="64"><p><span border-box="" center="" rgb="" rgba="" solid="" style="box-sizing:"><span leaf="">加密隧道</span></span></p></foreignobject></g></g><g center="" rgba="" style="background-color:" transform="translate(439.53125,"><g ms="" style="font-family:" transform="translate(-32,"><foreignobject height="24" width="64"><p><span border-box="" center="" rgb="" rgba="" solid="" style="box-sizing:"><span leaf="">加密隧道</span></span></p></foreignobject></g></g></g><g><g transform="translate(70,"><rect height="54" style="stroke:" width="124" x="-62" y="-27"></rect><g center="" ms="" style="font-family:" transform="translate(-32,"><rect style="fill:"></rect><foreignobject height="24" width="64"><section border-box="" center="" nowrap="nowrap" rgb="" solid="" style="box-sizing:" table-cell="" xmlns="http://www.w3.org/1999/xhtml"><span border-box="" rgb="" solid="" style="box-sizing:"><span leaf="">外网设备</span></span></section></foreignobject></g></g><g transform="translate(314.265625,"><rect height="54" style="stroke:" width="136.53125" x="-68.265625" y="-27"></rect><g center="" ms="" style="font-family:" transform="translate(-38.265625,"><rect style="fill:"></rect><foreignobject height="24" width="76.53125"><section border-box="" center="" nowrap="nowrap" rgb="" solid="" style="box-sizing:" table-cell="" xmlns="http://www.w3.org/1999/xhtml"><span border-box="" rgb="" solid="" style="box-sizing:"><span leaf="">VPN服务器</span></span></section></foreignobject></g></g><g transform="translate(556.203125,"><rect height="54" style="stroke:" width="119.34375" x="-59.671875" y="-27"></rect><g center="" ms="" style="font-family:" transform="translate(-29.671875,"><rect style="fill:"></rect><foreignobject height="24" width="59.34375"><section border-box="" center="" nowrap="nowrap" rgb="" solid="" style="box-sizing:" table-cell="" xmlns="http://www.w3.org/1999/xhtml"><span border-box="" rgb="" solid="" style="box-sizing:"><span leaf="">家里NAS</span></span></section></foreignobject></g></g></g></g></g></svg>
要求:需要VPN服务器(可以是家里的路由器,也可以是云服务器)
推荐工具:
类型工具/服务链接说明开源VPNWireGuardhttps://www.wireguard.com/现代化VPN协议,推荐
OpenVPNhttps://openvpn.net/老牌开源VPN优点:
- • 安全性高,全程加密
- • 可以访问家里所有设备
- • 云服务器方案不需要家里有公网IP
缺点:
- • 需要安装VPN客户端
- • 配置相对复杂
- • 云服务器方案有额外成本
方案二:DDNS + 直连
原理:通过动态域名解析 <code><span leaf="">Dynamic DNS</span></code>(DDNS)服务,将家里的动态公网IP地址绑定到一个固定域名上。外网设备通过这个域名访问家里的NAS设备。
<svg aria-roledescription="flowchart-v2" document="" ms="" role="graphics-document" style="font-family:" viewbox="0" width="100%" xmlns="http://www.w3.org/2000/svg"><g><marker markerheight="8" markerunits="userSpaceOnUse" markerwidth="8" orient="auto" refx="5" refy="5" style="fill:" viewbox="0"><path d="M" l="" style="stroke-width:" z=""></path></marker><marker markerheight="8" markerunits="userSpaceOnUse" markerwidth="8" orient="auto" refx="4.5" refy="5" style="fill:" viewbox="0"><path d="M" l="" style="stroke-width:" z=""></path></marker><marker markerheight="11" markerunits="userSpaceOnUse" markerwidth="11" orient="auto" refx="11" refy="5" style="fill:" viewbox="0"><circle cx="5" cy="5" r="5" style="stroke-width:"></circle></marker><marker markerheight="11" markerunits="userSpaceOnUse" markerwidth="11" orient="auto" refx="-1" refy="5" style="fill:" viewbox="0"><circle cx="5" cy="5" r="5" style="stroke-width:"></circle></marker><marker markerheight="11" markerunits="userSpaceOnUse" markerwidth="11" orient="auto" refx="12" refy="5.2" style="fill:" viewbox="0"><path d="M" l="" m="" style="stroke-width:"></path></marker><marker markerheight="11" markerunits="userSpaceOnUse" markerwidth="11" orient="auto" refx="-1" refy="5.2" style="fill:" viewbox="0"><path d="M" l="" m="" style="stroke-width:"></path></marker><g><g></g><g><path d="M132,47L136.167,47C140.333,47,148.667,47,156.333,47C164,47,171,47,174.5,47L178,47" marker-end="url(#mermaid-1757251945803_flowchart-v2-pointEnd)" none="" style="stroke-width:"></path><path d="M367.953,47L372.12,47C376.286,47,384.62,47,392.286,47C399.953,47,406.953,47,410.453,47L413.953,47" marker-end="url(#mermaid-1757251945803_flowchart-v2-pointEnd)" none="" style="stroke-width:"></path><path d="M555.328,47L559.495,47C563.661,47,571.995,47,579.661,47C587.328,47,594.328,47,597.828,47L601.328,47" marker-end="url(#mermaid-1757251945803_flowchart-v2-pointEnd)" none="" style="stroke-width:"></path><path d="M777.328,47L781.495,47C785.661,47,793.995,47,801.661,47C809.328,47,816.328,47,819.828,47L823.328,47" marker-end="url(#mermaid-1757251945803_flowchart-v2-pointEnd)" none="" style="stroke-width:"></path></g><g><g center="" rgba="" style="background-color:"><g ms="" style="font-family:" transform="translate(0,"><foreignobject height="0" width="0"><p><span border-box="" center="" rgb="" rgba="" solid="" style="box-sizing:"></span></p></foreignobject></g></g><g center="" rgba="" style="background-color:"><g ms="" style="font-family:" transform="translate(0,"><foreignobject height="0" width="0"><p><span border-box="" center="" rgb="" rgba="" solid="" style="box-sizing:"></span></p></foreignobject></g></g><g center="" rgba="" style="background-color:"><g ms="" style="font-family:" transform="translate(0,"><foreignobject height="0" width="0"><p><span border-box="" center="" rgb="" rgba="" solid="" style="box-sizing:"></span></p></foreignobject></g></g><g center="" rgba="" style="background-color:"><g ms="" style="font-family:" transform="translate(0,"><foreignobject height="0" width="0"><p><span border-box="" center="" rgb="" rgba="" solid="" style="box-sizing:"></span></p></foreignobject></g></g></g><g><g transform="translate(70,"><rect height="54" style="fill:" width="124" x="-62" y="-27"></rect><g center="" ms="" style="font-family:" transform="translate(-32,"><rect style="fill:"></rect><foreignobject height="24" width="64"><section border-box="" center="" nowrap="nowrap" rgb="" solid="" style="box-sizing:" table-cell="" xmlns="http://www.w3.org/1999/xhtml"><span border-box="" rgb="" solid="" style="box-sizing:"><span leaf="">外网设备</span></span></section></foreignobject></g></g><g transform="translate(274.9765625,"><rect height="78" style="fill:" width="185.953125" x="-92.9765625" y="-39"></rect><g center="" ms="" style="font-family:" transform="translate(-62.9765625,"><rect style="fill:"></rect><foreignobject height="48" width="125.953125"><section border-box="" center="" nowrap="nowrap" rgb="" solid="" style="box-sizing:" table-cell="" xmlns="http://www.w3.org/1999/xhtml"><span border-box="" rgb="" solid="" style="box-sizing:"><span leaf="">域名解析nas.example.com</span></span></section></foreignobject></g></g><g transform="translate(486.640625,"><rect height="78" style="fill:" width="137.375" x="-68.6875" y="-39"></rect><g center="" ms="" style="font-family:" transform="translate(-38.6875,"><rect style="fill:"></rect><foreignobject height="48" width="77.375"><section border-box="" center="" nowrap="nowrap" rgb="" solid="" style="box-sizing:" table-cell="" xmlns="http://www.w3.org/1999/xhtml"><span border-box="" rgb="" solid="" style="box-sizing:"><span leaf="">动态公网IPIPv4/IPv6</span></span></section></foreignobject></g></g><g transform="translate(691.328125,"><rect height="54" style="fill:" width="172" x="-86" y="-27"></rect><g center="" ms="" style="font-family:" transform="translate(-56,"><rect style="fill:"></rect><foreignobject height="24" width="112"><section border-box="" center="" nowrap="nowrap" rgb="" solid="" style="box-sizing:" table-cell="" xmlns="http://www.w3.org/1999/xhtml"><span border-box="" rgb="" solid="" style="box-sizing:"><span leaf="">路由器端口映射</span></span></section></foreignobject></g></g><g transform="translate(887,"><rect height="54" style="fill:" width="119.34375" x="-59.671875" y="-27"></rect><g center="" ms="" style="font-family:" transform="translate(-29.671875,"><rect style="fill:"></rect><foreignobject height="24" width="59.34375"><section border-box="" center="" nowrap="nowrap" rgb="" solid="" style="box-sizing:" table-cell="" xmlns="http://www.w3.org/1999/xhtml"><span border-box="" rgb="" solid="" style="box-sizing:"><span leaf="">NAS设备</span></span></section></foreignobject></g></g></g></g></g></svg>
要求:需要公网IP(IPv4或IPv6,动态IP也行)
推荐工具:
支持<code><span leaf="">DDNS</span></code>的客户端和服务商很多,<code><span leaf="">Google</span></code>一下一大把
类型工具/服务链接说明DDNS客户端DDNS-GOhttps://github.com/jeessy2/ddns-go开源DDNS客户端,支持多服务商
Luckyhttps://github.com/gdy666/lucky集成DDNS功能的网络工具DDNS服务商No-IPhttps://www.noip.com/老牌免费DDNS服务商
DuckDNShttps://www.duckdns.org/免费开源DDNS服务
CloudFlarehttps://www.cloudflare.com/CloudFlare提供的DDNS服务优点:
- • 访问速度快,真正的直连无延迟
- • 成本低,多数<code><span leaf="">DDNS</span></code>服务免费
- • 支持所有协议和端口
- • 同时支持IPv4和IPv6
缺点:
- • 需要公网IP(越来越稀缺)
- • 安全风险高,端口直接暴露
- • 需要配置防火墙等安全措施
- • IP变化时可能有短暂的解析延迟
方案三:内网穿透
原理:通过中转服务器,将内网服务暴露到公网。NAS主动连接到中转服务器,外网用户通过中转服务器访问。
<svg aria-roledescription="flowchart-v2" document="" ms="" role="graphics-document" style="font-family:" viewbox="0" width="100%" xmlns="http://www.w3.org/2000/svg"><g><marker markerheight="8" markerunits="userSpaceOnUse" markerwidth="8" orient="auto" refx="5" refy="5" style="fill:" viewbox="0"><path d="M" l="" style="stroke-width:" z=""></path></marker><marker markerheight="8" markerunits="userSpaceOnUse" markerwidth="8" orient="auto" refx="4.5" refy="5" style="fill:" viewbox="0"><path d="M" l="" style="stroke-width:" z=""></path></marker><marker markerheight="11" markerunits="userSpaceOnUse" markerwidth="11" orient="auto" refx="11" refy="5" style="fill:" viewbox="0"><circle cx="5" cy="5" r="5" style="stroke-width:"></circle></marker><marker markerheight="11" markerunits="userSpaceOnUse" markerwidth="11" orient="auto" refx="-1" refy="5" style="fill:" viewbox="0"><circle cx="5" cy="5" r="5" style="stroke-width:"></circle></marker><marker markerheight="11" markerunits="userSpaceOnUse" markerwidth="11" orient="auto" refx="12" refy="5.2" style="fill:" viewbox="0"><path d="M" l="" m="" style="stroke-width:"></path></marker><marker markerheight="11" markerunits="userSpaceOnUse" markerwidth="11" orient="auto" refx="-1" refy="5.2" style="fill:" viewbox="0"><path d="M" l="" m="" style="stroke-width:"></path></marker><g><g></g><g><path d="M132,72L136.167,72C140.333,72,148.667,72,156.333,72C164,72,171,72,174.5,72L178,72" marker-end="url(#mermaid-1757251945845_flowchart-v2-pointEnd)" none="" style="stroke-width:"></path><path d="M321.324,45L325.604,43.333C329.883,41.667,338.441,38.333,346.221,36.667C354,35,361,35,364.5,35L368,35" marker-end="url(#mermaid-1757251945845_flowchart-v2-pointEnd)" none="" style="stroke-width:"></path><path d="M512,35L516.167,35C520.333,35,528.667,35,536.389,36.554C544.112,38.108,551.223,41.215,554.779,42.769L558.335,44.323" marker-end="url(#mermaid-1757251945845_flowchart-v2-pointEnd)" none="" style="stroke-width:"></path><path d="M562,98.075L557.833,99.896C553.667,101.717,545.333,105.358,525.333,107.179C505.333,109,473.667,109,442,109C410.333,109,378.667,109,359.175,107.575C339.684,106.151,332.368,103.301,328.71,101.876L325.052,100.452" marker-end="url(#mermaid-1757251945845_flowchart-v2-pointEnd)" none="" style="stroke-width:"></path></g><g><g center="" rgba="" style="background-color:"><g ms="" style="font-family:" transform="translate(0,"><foreignobject height="0" width="0"><p><span border-box="" center="" rgb="" rgba="" solid="" style="box-sizing:"></span></p></foreignobject></g></g><g center="" rgba="" style="background-color:"><g ms="" style="font-family:" transform="translate(0,"><foreignobject height="0" width="0"><p><span border-box="" center="" rgb="" rgba="" solid="" style="box-sizing:"></span></p></foreignobject></g></g><g center="" rgba="" style="background-color:"><g ms="" style="font-family:" transform="translate(0,"><foreignobject height="0" width="0"><p><span border-box="" center="" rgb="" rgba="" solid="" style="box-sizing:"></span></p></foreignobject></g></g><g center="" rgba="" style="background-color:" transform="translate(442,"><g ms="" style="font-family:" transform="translate(-32,"><foreignobject height="24" width="64"><p><span border-box="" center="" rgb="" rgba="" solid="" style="box-sizing:"><span leaf="">主动连接</span></span></p></foreignobject></g></g></g><g><g transform="translate(70,"><rect height="54" style="fill:" width="124" x="-62" y="-27"></rect><g center="" ms="" style="font-family:" transform="translate(-32,"><rect style="fill:"></rect><foreignobject height="24" width="64"><section border-box="" center="" nowrap="nowrap" rgb="" solid="" style="box-sizing:" table-cell="" xmlns="http://www.w3.org/1999/xhtml"><span border-box="" rgb="" solid="" style="box-sizing:"><span leaf="">外网用户</span></span></section></foreignobject></g></g><g transform="translate(252,"><rect height="54" style="fill:" width="140" x="-70" y="-27"></rect><g center="" ms="" style="font-family:" transform="translate(-40,"><rect style="fill:"></rect><foreignobject height="24" width="80"><section border-box="" center="" nowrap="nowrap" rgb="" solid="" style="box-sizing:" table-cell="" xmlns="http://www.w3.org/1999/xhtml"><span border-box="" rgb="" solid="" style="box-sizing:"><span leaf="">中转服务器</span></span></section></foreignobject></g></g><g transform="translate(442,"><rect height="54" style="fill:" width="140" x="-70" y="-27"></rect><g center="" ms="" style="font-family:" transform="translate(-40,"><rect style="fill:"></rect><foreignobject height="24" width="80"><section border-box="" center="" nowrap="nowrap" rgb="" solid="" style="box-sizing:" table-cell="" xmlns="http://www.w3.org/1999/xhtml"><span border-box="" rgb="" solid="" style="box-sizing:"><span leaf="">家里路由器</span></span></section></foreignobject></g></g><g transform="translate(621.671875,"><rect height="54" style="fill:" width="119.34375" x="-59.671875" y="-27"></rect><g center="" ms="" style="font-family:" transform="translate(-29.671875,"><rect style="fill:"></rect><foreignobject height="24" width="59.34375"><section border-box="" center="" nowrap="nowrap" rgb="" solid="" style="box-sizing:" table-cell="" xmlns="http://www.w3.org/1999/xhtml"><span border-box="" rgb="" solid="" style="box-sizing:"><span leaf="">NAS设备</span></span></section></foreignobject></g></g></g></g></g></svg>
要求:不需要公网IP,但需要中转服务器
推荐工具:
类型工具/服务链接说明开源工具FRPhttps://github.com/fatedier/frp最流行的内网穿透工具
ngrokhttps://ngrok.com/简单易用,有免费版优点:
- • 不需要公网IP
- • 无需安装客户端,浏览器直接访问
- • 便于分享给他人
缺点:
- • 访问速度受中转服务器限制
- • 主要支持HTTP类服务
- • 依赖第三方服务稳定性
方案四:CloudFlare Zero Trust + Tunnel
原理:CloudFlare作为全球著名的网络安全和加速服务商,提供了一个基于零信任安全架构的现代化内网穿透技术。NAS通过CloudFlare
Tunnel建立出站连接到CloudFlare网络,外网用户通过CloudFlare
Zero Trust平台安全访问。本质上仍是内网穿透,但使用CloudFlare全球网络作为中转,无需自己搭建服务器。
cloudflare-tunnel相关文档:
- • CloudFlare Tunnel官方文档
- • 通过 Cloudflare Zero Trust 构建专用虚拟网络
<svg aria-roledescription="flowchart-v2" document="" ms="" role="graphics-document" style="font-family:" viewbox="0" width="100%" xmlns="http://www.w3.org/2000/svg"><g><marker markerheight="8" markerunits="userSpaceOnUse" markerwidth="8" orient="auto" refx="5" refy="5" style="fill:" viewbox="0"><path d="M" l="" style="stroke-width:" z=""></path></marker><marker markerheight="8" markerunits="userSpaceOnUse" markerwidth="8" orient="auto" refx="4.5" refy="5" style="fill:" viewbox="0"><path d="M" l="" style="stroke-width:" z=""></path></marker><marker markerheight="11" markerunits="userSpaceOnUse" markerwidth="11" orient="auto" refx="11" refy="5" style="fill:" viewbox="0"><circle cx="5" cy="5" r="5" style="stroke-width:"></circle></marker><marker markerheight="11" markerunits="userSpaceOnUse" markerwidth="11" orient="auto" refx="-1" refy="5" style="fill:" viewbox="0"><circle cx="5" cy="5" r="5" style="stroke-width:"></circle></marker><marker markerheight="11" markerunits="userSpaceOnUse" markerwidth="11" orient="auto" refx="12" refy="5.2" style="fill:" viewbox="0"><path d="M" l="" m="" style="stroke-width:"></path></marker><marker markerheight="11" markerunits="userSpaceOnUse" markerwidth="11" orient="auto" refx="-1" refy="5.2" style="fill:" viewbox="0"><path d="M" l="" m="" style="stroke-width:"></path></marker><g><g></g><g><path d="M132,72L136.167,72C140.333,72,148.667,72,156.333,72C164,72,171,72,174.5,72L178,72" marker-end="url(#mermaid-1757251945868_flowchart-v2-pointEnd)" none="" style="stroke-width:"></path><path d="M346.405,45L351.338,43.333C356.27,41.667,366.135,38.333,374.568,36.667C383,35,390,35,393.5,35L397,35" marker-end="url(#mermaid-1757251945868_flowchart-v2-pointEnd)" none="" style="stroke-width:"></path><path d="M525,35L529.167,35C533.333,35,541.667,35,549.389,36.554C557.112,38.108,564.223,41.215,567.779,42.769L571.335,44.323" marker-end="url(#mermaid-1757251945868_flowchart-v2-pointEnd)" none="" style="stroke-width:"></path><path d="M575,98.075L570.833,99.896C566.667,101.717,558.333,105.358,539.667,107.179C521,109,492,109,463,109C434,109,405,109,386.199,107.547C367.398,106.093,358.797,103.187,354.496,101.734L350.195,100.28" marker-end="url(#mermaid-1757251945868_flowchart-v2-pointEnd)" none="" style="stroke-width:"></path></g><g><g center="" rgba="" style="background-color:"><g ms="" style="font-family:" transform="translate(0,"><foreignobject height="0" width="0"><p><span border-box="" center="" rgb="" rgba="" solid="" style="box-sizing:"></span></p></foreignobject></g></g><g center="" rgba="" style="background-color:"><g ms="" style="font-family:" transform="translate(0,"><foreignobject height="0" width="0"><p><span border-box="" center="" rgb="" rgba="" solid="" style="box-sizing:"></span></p></foreignobject></g></g><g center="" rgba="" style="background-color:"><g ms="" style="font-family:" transform="translate(0,"><foreignobject height="0" width="0"><p><span border-box="" center="" rgb="" rgba="" solid="" style="box-sizing:"></span></p></foreignobject></g></g><g center="" rgba="" style="background-color:" transform="translate(463,"><g ms="" style="font-family:" transform="translate(-40,"><foreignobject height="24" width="80"><p><span border-box="" center="" rgb="" rgba="" solid="" style="box-sizing:"><span leaf="">仅出站连接</span></span></p></foreignobject></g></g></g><g><g transform="translate(70,"><rect height="54" style="stroke:" width="124" x="-62" y="-27"></rect><g center="" ms="" style="font-family:" transform="translate(-32,"><rect style="fill:"></rect><foreignobject height="24" width="64"><section border-box="" center="" nowrap="nowrap" rgb="" solid="" style="box-sizing:" table-cell="" xmlns="http://www.w3.org/1999/xhtml"><span border-box="" rgb="" solid="" style="box-sizing:"><span leaf="">外网用户</span></span></section></foreignobject></g></g><g transform="translate(266.5,"><rect height="54" style="stroke:" width="169" x="-84.5" y="-27"></rect><g center="" ms="" style="font-family:" transform="translate(-54.5,"><rect style="fill:"></rect><foreignobject height="24" width="109"><section border-box="" center="" nowrap="nowrap" rgb="" solid="" style="box-sizing:" table-cell="" xmlns="http://www.w3.org/1999/xhtml"><span border-box="" rgb="" solid="" style="box-sizing:"><span leaf="">CloudFlare网络</span></span></section></foreignobject></g></g><g transform="translate(463,"><rect height="54" style="fill:" width="124" x="-62" y="-27"></rect><g center="" ms="" style="font-family:" transform="translate(-32,"><rect style="fill:"></rect><foreignobject height="24" width="64"><section border-box="" center="" nowrap="nowrap" rgb="" solid="" style="box-sizing:" table-cell="" xmlns="http://www.w3.org/1999/xhtml"><span border-box="" rgb="" solid="" style="box-sizing:"><span leaf="">安全隧道</span></span></section></foreignobject></g></g><g transform="translate(634.671875,"><rect height="54" style="stroke:" width="119.34375" x="-59.671875" y="-27"></rect><g center="" ms="" style="font-family:" transform="translate(-29.671875,"><rect style="fill:"></rect><foreignobject height="24" width="59.34375"><section border-box="" center="" nowrap="nowrap" rgb="" solid="" style="box-sizing:" table-cell="" xmlns="http://www.w3.org/1999/xhtml"><span border-box="" rgb="" solid="" style="box-sizing:"><span leaf="">NAS设备</span></span></section></foreignobject></g></g></g></g></g></svg>
要求:不需要公网IP,不需要开放端口
重要说明:CloudFlare Tunnel默认会将服务暴露给整个公网,任何知道域名的人都可以访问。这与VPN方案不同,VPN只有安装配置了客户端的设备才能访问。如果需要访问控制,必须配置CloudFlare
Access策略进行身份验证和授权。
与传统内网穿透的区别:
对比项传统内网穿透(FRP/ngrok)零信任网络(CloudFlare Tunnel)中转服务器需要自己搭建或购买VPS使用CloudFlare全球网络服务质量取决于单台服务器性能全球CDN,就近接入安全架构简单的端口转发零信任安全模型成本服务器费用完全免费稳定性依赖单点服务器全球分布式网络优点:
- • 无需公网IP和端口映射
- • 仅出站连接,网络层面安全性高
- • 自动HTTPS和全球CDN加速
- • 完全免费,无需自建服务器
- • 全球分布式网络,高可用
- • 支持复杂的访问控制策略
缺点:
- • 需要域名托管在CloudFlare
- • 依赖CloudFlare服务可用性
- • 配置相对复杂
- • 本质上仍是中转访问,不是真正的直连
- • 默认暴露给公网:需要额外配置Access策略才能实现访问控制
- • 不如VPN方案的天然隐私保护
方案选择
按网络环境选择
网络情况推荐方案备选方案有公网IPDDNS + 直连VPN隧道运营商NATCloudFlare Tunnel云服务器VPN企业网络云服务器VPNCloudFlare Tunnel技术要求低CloudFlare Tunnel内网穿透(第三方)### 按使用需求选择
个人远程访问:推荐VPN方案,安全性好,功能完整
文件分享:推荐零信任网络,分享方便,安全性高
远程办公:推荐直连方案,速度最快
媒体服务器:推荐零信任网络,便于分享,支持流媒体
方案对比
-
• VPN方案:虚拟专网,需要客户端,天然隐私保护
-
• DDNS + 直连:真正的点对点连接,速度最快,支持IPv4/IPv6
-
• 内网穿透:通过中转服务器转发,包括传统的FRP/ngrok
-
• CloudFlare Tunnel:本质上是高级版的内网穿透,使用全球CDN网络作为中转,但默认暴露给公网
方案公网IP客户端安全性速度配置难度成本访问控制DDNS+直连需要不需要一般很快中等免费需自建VPN隧道可选需要很好较快较难有天然隐私内网穿透不需要不需要一般一般简单有需自建CloudFlare Tunnel不需要不需要中等较快中等免费需配置## 安全建议
不管选择哪种方案,都要注意安全:
-
- 修改默认端口:不要使用22、80、443等常见端口
-
- 强密码策略:使用复杂密码,启用二次验证
-
- 定期更新:及时更新系统和软件
-
- 访问控制:配置防火墙,限制访问来源
-
- 监控日志:定期检查访问日志,发现异常
总结
选择合适的方案主要看三个因素:
-
- 网络条件:是否有公网IP
-
- 使用需求:个人用还是分享用,安全要求高不高
-
- 技术能力:愿意折腾到什么程度
一般建议:
- • 有公网IP且追求速度:DDNS + 直连
- • 注重安全和隐私:VPN方案
- • 主要用于分享:CloudFlare Tunnel或内网穿透
- • 追求简单易用:CloudFlare Tunnel
根据自己的实际情况选择,没有完美的方案,只有最适合的方案。
See you ~
原创文章,作者:tualatin,如若转载,请注明出处:https://www.tualatin.cn/%e8%87%aa%e5%b7%b1%e5%8a%a8%e6%89%8b%e5%ae%9e%e7%8e%b0nas%e5%85%ac%e7%bd%91%e8%ae%bf%e9%97%ae/