自己动手实现NAS公网访问

前言

前两周某NAS厂商爆出了“非授权访问系统路径及文件”的重大安全问题,我们再次不得不重视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设备。

&lt;svg aria-roledescription=&quot;flowchart-v2&quot; document=&quot;&quot; ms=&quot;&quot; role=&quot;graphics-document&quot; style=&quot;font-family:&quot; viewbox=&quot;0&quot; width=&quot;100%&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;g&gt;&lt;marker markerheight=&quot;8&quot; markerunits=&quot;userSpaceOnUse&quot; markerwidth=&quot;8&quot; orient=&quot;auto&quot; refx=&quot;5&quot; refy=&quot;5&quot; style=&quot;fill:&quot; viewbox=&quot;0&quot;&gt;&lt;path d=&quot;M&quot; l=&quot;&quot; style=&quot;stroke-width:&quot; z=&quot;&quot;&gt;&lt;/path&gt;&lt;/marker&gt;&lt;marker markerheight=&quot;8&quot; markerunits=&quot;userSpaceOnUse&quot; markerwidth=&quot;8&quot; orient=&quot;auto&quot; refx=&quot;4.5&quot; refy=&quot;5&quot; style=&quot;fill:&quot; viewbox=&quot;0&quot;&gt;&lt;path d=&quot;M&quot; l=&quot;&quot; style=&quot;stroke-width:&quot; z=&quot;&quot;&gt;&lt;/path&gt;&lt;/marker&gt;&lt;marker markerheight=&quot;11&quot; markerunits=&quot;userSpaceOnUse&quot; markerwidth=&quot;11&quot; orient=&quot;auto&quot; refx=&quot;11&quot; refy=&quot;5&quot; style=&quot;fill:&quot; viewbox=&quot;0&quot;&gt;&lt;circle cx=&quot;5&quot; cy=&quot;5&quot; r=&quot;5&quot; style=&quot;stroke-width:&quot;&gt;&lt;/circle&gt;&lt;/marker&gt;&lt;marker markerheight=&quot;11&quot; markerunits=&quot;userSpaceOnUse&quot; markerwidth=&quot;11&quot; orient=&quot;auto&quot; refx=&quot;-1&quot; refy=&quot;5&quot; style=&quot;fill:&quot; viewbox=&quot;0&quot;&gt;&lt;circle cx=&quot;5&quot; cy=&quot;5&quot; r=&quot;5&quot; style=&quot;stroke-width:&quot;&gt;&lt;/circle&gt;&lt;/marker&gt;&lt;marker markerheight=&quot;11&quot; markerunits=&quot;userSpaceOnUse&quot; markerwidth=&quot;11&quot; orient=&quot;auto&quot; refx=&quot;12&quot; refy=&quot;5.2&quot; style=&quot;fill:&quot; viewbox=&quot;0&quot;&gt;&lt;path d=&quot;M&quot; l=&quot;&quot; m=&quot;&quot; style=&quot;stroke-width:&quot;&gt;&lt;/path&gt;&lt;/marker&gt;&lt;marker markerheight=&quot;11&quot; markerunits=&quot;userSpaceOnUse&quot; markerwidth=&quot;11&quot; orient=&quot;auto&quot; refx=&quot;-1&quot; refy=&quot;5.2&quot; style=&quot;fill:&quot; viewbox=&quot;0&quot;&gt;&lt;path d=&quot;M&quot; l=&quot;&quot; m=&quot;&quot; style=&quot;stroke-width:&quot;&gt;&lt;/path&gt;&lt;/marker&gt;&lt;g&gt;&lt;g&gt;&lt;/g&gt;&lt;g&gt;&lt;path d=&quot;M132,47L136.167,47C140.333,47,148.667,47,156.333,47C164,47,171,47,174.5,47L178,47&quot; marker-end=&quot;url(#mermaid-1757251945803_flowchart-v2-pointEnd)&quot; none=&quot;&quot; style=&quot;stroke-width:&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M367.953,47L372.12,47C376.286,47,384.62,47,392.286,47C399.953,47,406.953,47,410.453,47L413.953,47&quot; marker-end=&quot;url(#mermaid-1757251945803_flowchart-v2-pointEnd)&quot; none=&quot;&quot; style=&quot;stroke-width:&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M555.328,47L559.495,47C563.661,47,571.995,47,579.661,47C587.328,47,594.328,47,597.828,47L601.328,47&quot; marker-end=&quot;url(#mermaid-1757251945803_flowchart-v2-pointEnd)&quot; none=&quot;&quot; style=&quot;stroke-width:&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M777.328,47L781.495,47C785.661,47,793.995,47,801.661,47C809.328,47,816.328,47,819.828,47L823.328,47&quot; marker-end=&quot;url(#mermaid-1757251945803_flowchart-v2-pointEnd)&quot; none=&quot;&quot; style=&quot;stroke-width:&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g&gt;&lt;g center=&quot;&quot; rgba=&quot;&quot; style=&quot;background-color:&quot;&gt;&lt;g ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(0,&quot;&gt;&lt;foreignobject height=&quot;0&quot; width=&quot;0&quot;&gt;&lt;p&gt;&lt;span border-box=&quot;&quot; center=&quot;&quot; rgb=&quot;&quot; rgba=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;g center=&quot;&quot; rgba=&quot;&quot; style=&quot;background-color:&quot;&gt;&lt;g ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(0,&quot;&gt;&lt;foreignobject height=&quot;0&quot; width=&quot;0&quot;&gt;&lt;p&gt;&lt;span border-box=&quot;&quot; center=&quot;&quot; rgb=&quot;&quot; rgba=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;g center=&quot;&quot; rgba=&quot;&quot; style=&quot;background-color:&quot;&gt;&lt;g ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(0,&quot;&gt;&lt;foreignobject height=&quot;0&quot; width=&quot;0&quot;&gt;&lt;p&gt;&lt;span border-box=&quot;&quot; center=&quot;&quot; rgb=&quot;&quot; rgba=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;g center=&quot;&quot; rgba=&quot;&quot; style=&quot;background-color:&quot;&gt;&lt;g ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(0,&quot;&gt;&lt;foreignobject height=&quot;0&quot; width=&quot;0&quot;&gt;&lt;p&gt;&lt;span border-box=&quot;&quot; center=&quot;&quot; rgb=&quot;&quot; rgba=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g&gt;&lt;g transform=&quot;translate(70,&quot;&gt;&lt;rect height=&quot;54&quot; style=&quot;fill:&quot; width=&quot;124&quot; x=&quot;-62&quot; y=&quot;-27&quot;&gt;&lt;/rect&gt;&lt;g center=&quot;&quot; ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(-32,&quot;&gt;&lt;rect style=&quot;fill:&quot;&gt;&lt;/rect&gt;&lt;foreignobject height=&quot;24&quot; width=&quot;64&quot;&gt;&lt;section border-box=&quot;&quot; center=&quot;&quot; nowrap=&quot;nowrap&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot; table-cell=&quot;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;span border-box=&quot;&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;span leaf=&quot;&quot;&gt;外网设备&lt;/span&gt;&lt;/span&gt;&lt;/section&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(274.9765625,&quot;&gt;&lt;rect height=&quot;78&quot; style=&quot;fill:&quot; width=&quot;185.953125&quot; x=&quot;-92.9765625&quot; y=&quot;-39&quot;&gt;&lt;/rect&gt;&lt;g center=&quot;&quot; ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(-62.9765625,&quot;&gt;&lt;rect style=&quot;fill:&quot;&gt;&lt;/rect&gt;&lt;foreignobject height=&quot;48&quot; width=&quot;125.953125&quot;&gt;&lt;section border-box=&quot;&quot; center=&quot;&quot; nowrap=&quot;nowrap&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot; table-cell=&quot;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;span border-box=&quot;&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;span leaf=&quot;&quot;&gt;域名解析nas.example.com&lt;/span&gt;&lt;/span&gt;&lt;/section&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(486.640625,&quot;&gt;&lt;rect height=&quot;78&quot; style=&quot;fill:&quot; width=&quot;137.375&quot; x=&quot;-68.6875&quot; y=&quot;-39&quot;&gt;&lt;/rect&gt;&lt;g center=&quot;&quot; ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(-38.6875,&quot;&gt;&lt;rect style=&quot;fill:&quot;&gt;&lt;/rect&gt;&lt;foreignobject height=&quot;48&quot; width=&quot;77.375&quot;&gt;&lt;section border-box=&quot;&quot; center=&quot;&quot; nowrap=&quot;nowrap&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot; table-cell=&quot;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;span border-box=&quot;&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;span leaf=&quot;&quot;&gt;动态公网IPIPv4/IPv6&lt;/span&gt;&lt;/span&gt;&lt;/section&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(691.328125,&quot;&gt;&lt;rect height=&quot;54&quot; style=&quot;fill:&quot; width=&quot;172&quot; x=&quot;-86&quot; y=&quot;-27&quot;&gt;&lt;/rect&gt;&lt;g center=&quot;&quot; ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(-56,&quot;&gt;&lt;rect style=&quot;fill:&quot;&gt;&lt;/rect&gt;&lt;foreignobject height=&quot;24&quot; width=&quot;112&quot;&gt;&lt;section border-box=&quot;&quot; center=&quot;&quot; nowrap=&quot;nowrap&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot; table-cell=&quot;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;span border-box=&quot;&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;span leaf=&quot;&quot;&gt;路由器端口映射&lt;/span&gt;&lt;/span&gt;&lt;/section&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(887,&quot;&gt;&lt;rect height=&quot;54&quot; style=&quot;fill:&quot; width=&quot;119.34375&quot; x=&quot;-59.671875&quot; y=&quot;-27&quot;&gt;&lt;/rect&gt;&lt;g center=&quot;&quot; ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(-29.671875,&quot;&gt;&lt;rect style=&quot;fill:&quot;&gt;&lt;/rect&gt;&lt;foreignobject height=&quot;24&quot; width=&quot;59.34375&quot;&gt;&lt;section border-box=&quot;&quot; center=&quot;&quot; nowrap=&quot;nowrap&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot; table-cell=&quot;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;span border-box=&quot;&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NAS设备&lt;/span&gt;&lt;/span&gt;&lt;/section&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;

要求:需要公网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主动连接到中转服务器,外网用户通过中转服务器访问。

&lt;svg aria-roledescription=&quot;flowchart-v2&quot; document=&quot;&quot; ms=&quot;&quot; role=&quot;graphics-document&quot; style=&quot;font-family:&quot; viewbox=&quot;0&quot; width=&quot;100%&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;g&gt;&lt;marker markerheight=&quot;8&quot; markerunits=&quot;userSpaceOnUse&quot; markerwidth=&quot;8&quot; orient=&quot;auto&quot; refx=&quot;5&quot; refy=&quot;5&quot; style=&quot;fill:&quot; viewbox=&quot;0&quot;&gt;&lt;path d=&quot;M&quot; l=&quot;&quot; style=&quot;stroke-width:&quot; z=&quot;&quot;&gt;&lt;/path&gt;&lt;/marker&gt;&lt;marker markerheight=&quot;8&quot; markerunits=&quot;userSpaceOnUse&quot; markerwidth=&quot;8&quot; orient=&quot;auto&quot; refx=&quot;4.5&quot; refy=&quot;5&quot; style=&quot;fill:&quot; viewbox=&quot;0&quot;&gt;&lt;path d=&quot;M&quot; l=&quot;&quot; style=&quot;stroke-width:&quot; z=&quot;&quot;&gt;&lt;/path&gt;&lt;/marker&gt;&lt;marker markerheight=&quot;11&quot; markerunits=&quot;userSpaceOnUse&quot; markerwidth=&quot;11&quot; orient=&quot;auto&quot; refx=&quot;11&quot; refy=&quot;5&quot; style=&quot;fill:&quot; viewbox=&quot;0&quot;&gt;&lt;circle cx=&quot;5&quot; cy=&quot;5&quot; r=&quot;5&quot; style=&quot;stroke-width:&quot;&gt;&lt;/circle&gt;&lt;/marker&gt;&lt;marker markerheight=&quot;11&quot; markerunits=&quot;userSpaceOnUse&quot; markerwidth=&quot;11&quot; orient=&quot;auto&quot; refx=&quot;-1&quot; refy=&quot;5&quot; style=&quot;fill:&quot; viewbox=&quot;0&quot;&gt;&lt;circle cx=&quot;5&quot; cy=&quot;5&quot; r=&quot;5&quot; style=&quot;stroke-width:&quot;&gt;&lt;/circle&gt;&lt;/marker&gt;&lt;marker markerheight=&quot;11&quot; markerunits=&quot;userSpaceOnUse&quot; markerwidth=&quot;11&quot; orient=&quot;auto&quot; refx=&quot;12&quot; refy=&quot;5.2&quot; style=&quot;fill:&quot; viewbox=&quot;0&quot;&gt;&lt;path d=&quot;M&quot; l=&quot;&quot; m=&quot;&quot; style=&quot;stroke-width:&quot;&gt;&lt;/path&gt;&lt;/marker&gt;&lt;marker markerheight=&quot;11&quot; markerunits=&quot;userSpaceOnUse&quot; markerwidth=&quot;11&quot; orient=&quot;auto&quot; refx=&quot;-1&quot; refy=&quot;5.2&quot; style=&quot;fill:&quot; viewbox=&quot;0&quot;&gt;&lt;path d=&quot;M&quot; l=&quot;&quot; m=&quot;&quot; style=&quot;stroke-width:&quot;&gt;&lt;/path&gt;&lt;/marker&gt;&lt;g&gt;&lt;g&gt;&lt;/g&gt;&lt;g&gt;&lt;path d=&quot;M132,72L136.167,72C140.333,72,148.667,72,156.333,72C164,72,171,72,174.5,72L178,72&quot; marker-end=&quot;url(#mermaid-1757251945845_flowchart-v2-pointEnd)&quot; none=&quot;&quot; style=&quot;stroke-width:&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M321.324,45L325.604,43.333C329.883,41.667,338.441,38.333,346.221,36.667C354,35,361,35,364.5,35L368,35&quot; marker-end=&quot;url(#mermaid-1757251945845_flowchart-v2-pointEnd)&quot; none=&quot;&quot; style=&quot;stroke-width:&quot;&gt;&lt;/path&gt;&lt;path d=&quot;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&quot; marker-end=&quot;url(#mermaid-1757251945845_flowchart-v2-pointEnd)&quot; none=&quot;&quot; style=&quot;stroke-width:&quot;&gt;&lt;/path&gt;&lt;path d=&quot;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&quot; marker-end=&quot;url(#mermaid-1757251945845_flowchart-v2-pointEnd)&quot; none=&quot;&quot; style=&quot;stroke-width:&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g&gt;&lt;g center=&quot;&quot; rgba=&quot;&quot; style=&quot;background-color:&quot;&gt;&lt;g ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(0,&quot;&gt;&lt;foreignobject height=&quot;0&quot; width=&quot;0&quot;&gt;&lt;p&gt;&lt;span border-box=&quot;&quot; center=&quot;&quot; rgb=&quot;&quot; rgba=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;g center=&quot;&quot; rgba=&quot;&quot; style=&quot;background-color:&quot;&gt;&lt;g ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(0,&quot;&gt;&lt;foreignobject height=&quot;0&quot; width=&quot;0&quot;&gt;&lt;p&gt;&lt;span border-box=&quot;&quot; center=&quot;&quot; rgb=&quot;&quot; rgba=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;g center=&quot;&quot; rgba=&quot;&quot; style=&quot;background-color:&quot;&gt;&lt;g ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(0,&quot;&gt;&lt;foreignobject height=&quot;0&quot; width=&quot;0&quot;&gt;&lt;p&gt;&lt;span border-box=&quot;&quot; center=&quot;&quot; rgb=&quot;&quot; rgba=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;g center=&quot;&quot; rgba=&quot;&quot; style=&quot;background-color:&quot; transform=&quot;translate(442,&quot;&gt;&lt;g ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(-32,&quot;&gt;&lt;foreignobject height=&quot;24&quot; width=&quot;64&quot;&gt;&lt;p&gt;&lt;span border-box=&quot;&quot; center=&quot;&quot; rgb=&quot;&quot; rgba=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;span leaf=&quot;&quot;&gt;主动连接&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g&gt;&lt;g transform=&quot;translate(70,&quot;&gt;&lt;rect height=&quot;54&quot; style=&quot;fill:&quot; width=&quot;124&quot; x=&quot;-62&quot; y=&quot;-27&quot;&gt;&lt;/rect&gt;&lt;g center=&quot;&quot; ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(-32,&quot;&gt;&lt;rect style=&quot;fill:&quot;&gt;&lt;/rect&gt;&lt;foreignobject height=&quot;24&quot; width=&quot;64&quot;&gt;&lt;section border-box=&quot;&quot; center=&quot;&quot; nowrap=&quot;nowrap&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot; table-cell=&quot;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;span border-box=&quot;&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;span leaf=&quot;&quot;&gt;外网用户&lt;/span&gt;&lt;/span&gt;&lt;/section&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(252,&quot;&gt;&lt;rect height=&quot;54&quot; style=&quot;fill:&quot; width=&quot;140&quot; x=&quot;-70&quot; y=&quot;-27&quot;&gt;&lt;/rect&gt;&lt;g center=&quot;&quot; ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(-40,&quot;&gt;&lt;rect style=&quot;fill:&quot;&gt;&lt;/rect&gt;&lt;foreignobject height=&quot;24&quot; width=&quot;80&quot;&gt;&lt;section border-box=&quot;&quot; center=&quot;&quot; nowrap=&quot;nowrap&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot; table-cell=&quot;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;span border-box=&quot;&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;span leaf=&quot;&quot;&gt;中转服务器&lt;/span&gt;&lt;/span&gt;&lt;/section&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(442,&quot;&gt;&lt;rect height=&quot;54&quot; style=&quot;fill:&quot; width=&quot;140&quot; x=&quot;-70&quot; y=&quot;-27&quot;&gt;&lt;/rect&gt;&lt;g center=&quot;&quot; ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(-40,&quot;&gt;&lt;rect style=&quot;fill:&quot;&gt;&lt;/rect&gt;&lt;foreignobject height=&quot;24&quot; width=&quot;80&quot;&gt;&lt;section border-box=&quot;&quot; center=&quot;&quot; nowrap=&quot;nowrap&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot; table-cell=&quot;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;span border-box=&quot;&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;span leaf=&quot;&quot;&gt;家里路由器&lt;/span&gt;&lt;/span&gt;&lt;/section&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(621.671875,&quot;&gt;&lt;rect height=&quot;54&quot; style=&quot;fill:&quot; width=&quot;119.34375&quot; x=&quot;-59.671875&quot; y=&quot;-27&quot;&gt;&lt;/rect&gt;&lt;g center=&quot;&quot; ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(-29.671875,&quot;&gt;&lt;rect style=&quot;fill:&quot;&gt;&lt;/rect&gt;&lt;foreignobject height=&quot;24&quot; width=&quot;59.34375&quot;&gt;&lt;section border-box=&quot;&quot; center=&quot;&quot; nowrap=&quot;nowrap&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot; table-cell=&quot;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;span border-box=&quot;&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NAS设备&lt;/span&gt;&lt;/span&gt;&lt;/section&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;

要求:不需要公网IP,但需要中转服务器

推荐工具

类型工具/服务链接说明开源工具FRPhttps://github.com/fatedier/frp最流行的内网穿透工具
ngrokhttps://ngrok.com/简单易用,有免费版优点

  • • 不需要公网IP
  • • 无需安装客户端,浏览器直接访问
  • • 便于分享给他人

缺点

  • • 访问速度受中转服务器限制
  • • 主要支持HTTP类服务
  • • 依赖第三方服务稳定性

方案四:CloudFlare Zero Trust + Tunnel

原理:CloudFlare作为全球著名的网络安全和加速服务商,提供了一个基于零信任安全架构的现代化内网穿透技术。NAS通过CloudFlare
Tunnel建立出站连接到CloudFlare网络,外网用户通过CloudFlare
Zero Trust平台安全访问。本质上仍是内网穿透,但使用CloudFlare全球网络作为中转,无需自己搭建服务器。

自己动手实现NAS公网访问cloudflare-tunnel相关文档

  • • CloudFlare Tunnel官方文档
  • • 通过 Cloudflare Zero Trust 构建专用虚拟网络
&lt;svg aria-roledescription=&quot;flowchart-v2&quot; document=&quot;&quot; ms=&quot;&quot; role=&quot;graphics-document&quot; style=&quot;font-family:&quot; viewbox=&quot;0&quot; width=&quot;100%&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;g&gt;&lt;marker markerheight=&quot;8&quot; markerunits=&quot;userSpaceOnUse&quot; markerwidth=&quot;8&quot; orient=&quot;auto&quot; refx=&quot;5&quot; refy=&quot;5&quot; style=&quot;fill:&quot; viewbox=&quot;0&quot;&gt;&lt;path d=&quot;M&quot; l=&quot;&quot; style=&quot;stroke-width:&quot; z=&quot;&quot;&gt;&lt;/path&gt;&lt;/marker&gt;&lt;marker markerheight=&quot;8&quot; markerunits=&quot;userSpaceOnUse&quot; markerwidth=&quot;8&quot; orient=&quot;auto&quot; refx=&quot;4.5&quot; refy=&quot;5&quot; style=&quot;fill:&quot; viewbox=&quot;0&quot;&gt;&lt;path d=&quot;M&quot; l=&quot;&quot; style=&quot;stroke-width:&quot; z=&quot;&quot;&gt;&lt;/path&gt;&lt;/marker&gt;&lt;marker markerheight=&quot;11&quot; markerunits=&quot;userSpaceOnUse&quot; markerwidth=&quot;11&quot; orient=&quot;auto&quot; refx=&quot;11&quot; refy=&quot;5&quot; style=&quot;fill:&quot; viewbox=&quot;0&quot;&gt;&lt;circle cx=&quot;5&quot; cy=&quot;5&quot; r=&quot;5&quot; style=&quot;stroke-width:&quot;&gt;&lt;/circle&gt;&lt;/marker&gt;&lt;marker markerheight=&quot;11&quot; markerunits=&quot;userSpaceOnUse&quot; markerwidth=&quot;11&quot; orient=&quot;auto&quot; refx=&quot;-1&quot; refy=&quot;5&quot; style=&quot;fill:&quot; viewbox=&quot;0&quot;&gt;&lt;circle cx=&quot;5&quot; cy=&quot;5&quot; r=&quot;5&quot; style=&quot;stroke-width:&quot;&gt;&lt;/circle&gt;&lt;/marker&gt;&lt;marker markerheight=&quot;11&quot; markerunits=&quot;userSpaceOnUse&quot; markerwidth=&quot;11&quot; orient=&quot;auto&quot; refx=&quot;12&quot; refy=&quot;5.2&quot; style=&quot;fill:&quot; viewbox=&quot;0&quot;&gt;&lt;path d=&quot;M&quot; l=&quot;&quot; m=&quot;&quot; style=&quot;stroke-width:&quot;&gt;&lt;/path&gt;&lt;/marker&gt;&lt;marker markerheight=&quot;11&quot; markerunits=&quot;userSpaceOnUse&quot; markerwidth=&quot;11&quot; orient=&quot;auto&quot; refx=&quot;-1&quot; refy=&quot;5.2&quot; style=&quot;fill:&quot; viewbox=&quot;0&quot;&gt;&lt;path d=&quot;M&quot; l=&quot;&quot; m=&quot;&quot; style=&quot;stroke-width:&quot;&gt;&lt;/path&gt;&lt;/marker&gt;&lt;g&gt;&lt;g&gt;&lt;/g&gt;&lt;g&gt;&lt;path d=&quot;M132,72L136.167,72C140.333,72,148.667,72,156.333,72C164,72,171,72,174.5,72L178,72&quot; marker-end=&quot;url(#mermaid-1757251945868_flowchart-v2-pointEnd)&quot; none=&quot;&quot; style=&quot;stroke-width:&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M346.405,45L351.338,43.333C356.27,41.667,366.135,38.333,374.568,36.667C383,35,390,35,393.5,35L397,35&quot; marker-end=&quot;url(#mermaid-1757251945868_flowchart-v2-pointEnd)&quot; none=&quot;&quot; style=&quot;stroke-width:&quot;&gt;&lt;/path&gt;&lt;path d=&quot;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&quot; marker-end=&quot;url(#mermaid-1757251945868_flowchart-v2-pointEnd)&quot; none=&quot;&quot; style=&quot;stroke-width:&quot;&gt;&lt;/path&gt;&lt;path d=&quot;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&quot; marker-end=&quot;url(#mermaid-1757251945868_flowchart-v2-pointEnd)&quot; none=&quot;&quot; style=&quot;stroke-width:&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g&gt;&lt;g center=&quot;&quot; rgba=&quot;&quot; style=&quot;background-color:&quot;&gt;&lt;g ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(0,&quot;&gt;&lt;foreignobject height=&quot;0&quot; width=&quot;0&quot;&gt;&lt;p&gt;&lt;span border-box=&quot;&quot; center=&quot;&quot; rgb=&quot;&quot; rgba=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;g center=&quot;&quot; rgba=&quot;&quot; style=&quot;background-color:&quot;&gt;&lt;g ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(0,&quot;&gt;&lt;foreignobject height=&quot;0&quot; width=&quot;0&quot;&gt;&lt;p&gt;&lt;span border-box=&quot;&quot; center=&quot;&quot; rgb=&quot;&quot; rgba=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;g center=&quot;&quot; rgba=&quot;&quot; style=&quot;background-color:&quot;&gt;&lt;g ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(0,&quot;&gt;&lt;foreignobject height=&quot;0&quot; width=&quot;0&quot;&gt;&lt;p&gt;&lt;span border-box=&quot;&quot; center=&quot;&quot; rgb=&quot;&quot; rgba=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;g center=&quot;&quot; rgba=&quot;&quot; style=&quot;background-color:&quot; transform=&quot;translate(463,&quot;&gt;&lt;g ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(-40,&quot;&gt;&lt;foreignobject height=&quot;24&quot; width=&quot;80&quot;&gt;&lt;p&gt;&lt;span border-box=&quot;&quot; center=&quot;&quot; rgb=&quot;&quot; rgba=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;span leaf=&quot;&quot;&gt;仅出站连接&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g&gt;&lt;g transform=&quot;translate(70,&quot;&gt;&lt;rect height=&quot;54&quot; style=&quot;stroke:&quot; width=&quot;124&quot; x=&quot;-62&quot; y=&quot;-27&quot;&gt;&lt;/rect&gt;&lt;g center=&quot;&quot; ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(-32,&quot;&gt;&lt;rect style=&quot;fill:&quot;&gt;&lt;/rect&gt;&lt;foreignobject height=&quot;24&quot; width=&quot;64&quot;&gt;&lt;section border-box=&quot;&quot; center=&quot;&quot; nowrap=&quot;nowrap&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot; table-cell=&quot;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;span border-box=&quot;&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;span leaf=&quot;&quot;&gt;外网用户&lt;/span&gt;&lt;/span&gt;&lt;/section&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(266.5,&quot;&gt;&lt;rect height=&quot;54&quot; style=&quot;stroke:&quot; width=&quot;169&quot; x=&quot;-84.5&quot; y=&quot;-27&quot;&gt;&lt;/rect&gt;&lt;g center=&quot;&quot; ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(-54.5,&quot;&gt;&lt;rect style=&quot;fill:&quot;&gt;&lt;/rect&gt;&lt;foreignobject height=&quot;24&quot; width=&quot;109&quot;&gt;&lt;section border-box=&quot;&quot; center=&quot;&quot; nowrap=&quot;nowrap&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot; table-cell=&quot;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;span border-box=&quot;&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;span leaf=&quot;&quot;&gt;CloudFlare网络&lt;/span&gt;&lt;/span&gt;&lt;/section&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(463,&quot;&gt;&lt;rect height=&quot;54&quot; style=&quot;fill:&quot; width=&quot;124&quot; x=&quot;-62&quot; y=&quot;-27&quot;&gt;&lt;/rect&gt;&lt;g center=&quot;&quot; ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(-32,&quot;&gt;&lt;rect style=&quot;fill:&quot;&gt;&lt;/rect&gt;&lt;foreignobject height=&quot;24&quot; width=&quot;64&quot;&gt;&lt;section border-box=&quot;&quot; center=&quot;&quot; nowrap=&quot;nowrap&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot; table-cell=&quot;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;span border-box=&quot;&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;span leaf=&quot;&quot;&gt;安全隧道&lt;/span&gt;&lt;/span&gt;&lt;/section&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;g transform=&quot;translate(634.671875,&quot;&gt;&lt;rect height=&quot;54&quot; style=&quot;stroke:&quot; width=&quot;119.34375&quot; x=&quot;-59.671875&quot; y=&quot;-27&quot;&gt;&lt;/rect&gt;&lt;g center=&quot;&quot; ms=&quot;&quot; style=&quot;font-family:&quot; transform=&quot;translate(-29.671875,&quot;&gt;&lt;rect style=&quot;fill:&quot;&gt;&lt;/rect&gt;&lt;foreignobject height=&quot;24&quot; width=&quot;59.34375&quot;&gt;&lt;section border-box=&quot;&quot; center=&quot;&quot; nowrap=&quot;nowrap&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot; table-cell=&quot;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;span border-box=&quot;&quot; rgb=&quot;&quot; solid=&quot;&quot; style=&quot;box-sizing:&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NAS设备&lt;/span&gt;&lt;/span&gt;&lt;/section&gt;&lt;/foreignobject&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;

要求:不需要公网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不需要不需要中等较快中等免费需配置## 安全建议

不管选择哪种方案,都要注意安全:

    1. 修改默认端口:不要使用22、80、443等常见端口
    1. 强密码策略:使用复杂密码,启用二次验证
    1. 定期更新:及时更新系统和软件
    1. 访问控制:配置防火墙,限制访问来源
    1. 监控日志:定期检查访问日志,发现异常

总结

选择合适的方案主要看三个因素:

    1. 网络条件:是否有公网IP
    1. 使用需求:个人用还是分享用,安全要求高不高
    1. 技术能力:愿意折腾到什么程度

一般建议:

  • • 有公网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/

Like (0)
tualatin的头像tualatin
Previous 19小时前
Next 6天前

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注