{"slug":"across-nat","title":"究极喂饭教程，手把手教你内网穿透","description":"使用Zerotier，Tailscale，Cloudflare Tunnel可以实现多种内网穿透，其中有适用于个人访问的，也有适用于公众访问的","coverImage":"https://b.acofork.com/img/across-nat-2024-10-28-17-00-25-image.webp","coverWidth":2526,"coverHeight":1366,"date":"2024-10-27","tags":["网络"],"pinned":false,"wordCount":2465,"html":"<h2 id=\"经实测-zerotier的打洞能力明显优于tailscale-所以建议通过zerotier来实现内网穿透\">经实测，Zerotier的打洞能力明显优于Tailscale，所以建议通过Zerotier来实现内网穿透</h2><p>详细报表：</p>\n<table>\n<thead>\n<tr>\n<th></th>\n<th>Zerotier</th>\n<th>Tailscale</th>\n</tr>\n</thead>\n<tbody><tr>\n<td>单端DMZ（单端NAT1）</td>\n<td>STUN</td>\n<td>STUN</td>\n</tr>\n<tr>\n<td>仅单端UPnP（单端NAT3）</td>\n<td>UDP P2P</td>\n<td>玄学穿透</td>\n</tr>\n<tr>\n<td>双端UPnP（双端NAT3）</td>\n<td>UDP P2P</td>\n<td>玄学穿透</td>\n</tr>\n<tr>\n<td>双端无UPnP/DMZ（双端NAT3/NAT4）</td>\n<td>UDP P2P</td>\n<td>无法穿透</td>\n</tr>\n<tr>\n<td>自建中继/握手节点</td>\n<td>√</td>\n<td>√</td>\n</tr>\n</tbody></table>\n<p>其实实际情况会更加复杂一点，但是你只要有 <strong>公网IPv6、UPnP、DMZ</strong> 中的其中一项，Zerotier就几乎是100%的打洞成功率</p>\n<p>如何知道我是P2P还是中继？\nping你的对端设备，如果延迟大于200ms或者经常丢包大概率就是中继节点（也有小概率是你的设备负载过高导致无法及时接收和返回ping包）</p>\n<h2 id=\"啥是内网穿透\">啥是内网穿透？</h2><p>当我们在家中有个NAS，想要在学校/公司的网络来访问，就需要用到内网穿透，实现外网访问内网服务。原理一般是P2P打洞和服务器中转流量</p>\n<h2 id=\"前期准备\">前期准备</h2><p>路由器开启UPnP<img src=\"https://b.acofork.com/img/across-nat-2024-10-28-17-08-00-image.webp\" alt=\"\" width=\"1654\" height=\"1165\" loading=\"eager\" decoding=\"async\" />  </p>\n<p>关闭路由器的IPv4，IPv6防火墙 <strong>（可选）</strong><img src=\"https://b.acofork.com/img/across-nat-2024-10-28-17-09-19-image.webp\" alt=\"\" width=\"1654\" height=\"1167\" loading=\"lazy\" decoding=\"async\" /></p>\n<h2 id=\"使用zerotier-tailscale进行内网穿透\"><em>使用Zerotier/Tailscale进行内网穿透</em></h2><blockquote>\n<p>他们俩的原理都是尝试对端建立P2P连接，需要对端安装一个软件并且长期运行</p>\n</blockquote>\n<h2 id=\"使用zerotier进行内网穿透的详细教程\">使用Zerotier进行内网穿透的详细教程</h2><h3 id=\"创建zerotier账号\">创建Zerotier账号</h3><p>前往：<a href=\"https://www.zerotier.com/\" target=\"_blank\" rel=\"noopener noreferrer\">ZeroTier | Global Networking Solution for IoT, SD-WAN, and VPN</a>。如果你进不去，请尝试挂梯子。如果看不懂英文可以开启浏览器的翻译功能<img src=\"https://b.acofork.com/img/across-nat-2024-10-28-17-12-51-image.webp\" alt=\"\" width=\"2560\" height=\"1479\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>选择 <code>Sign up</code><img src=\"https://b.acofork.com/img/across-nat-2024-10-28-17-13-06-image.webp\" alt=\"\" width=\"2526\" height=\"1358\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>如果你到了这个界面，请仍然选择<code>Sign up</code><img src=\"https://b.acofork.com/img/across-nat-2024-10-28-17-15-08-image.webp\" alt=\"\" width=\"2549\" height=\"1361\" loading=\"lazy\" decoding=\"async\" /></p>\n<p><img src=\"https://b.acofork.com/img/across-nat-2024-10-28-17-16-52-image.webp\" alt=\"\" width=\"1213\" height=\"1361\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>账号创建完毕后，登录即可<img src=\"https://b.acofork.com/img/across-nat-2024-10-28-17-17-47-image.webp\" alt=\"\" width=\"848\" height=\"878\" loading=\"lazy\" decoding=\"async\" /></p>\n<h3 id=\"创建一个新的zerotier网络组\">创建一个新的Zerotier网络组</h3><p>当你账号登录成功后，会自动跳转到这个页面，点击<code>Create A Network</code>。如果没有，请访问<a href=\"https://my.zerotier.com/\" target=\"_blank\" rel=\"noopener noreferrer\">ZeroTier Central</a></p>\n<p><img src=\"https://b.acofork.com/img/across-nat-2024-10-28-17-20-24-image.webp\" alt=\"\" width=\"2549\" height=\"1361\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>下面的列表会增加一个新的网络组，点击它<img src=\"https://b.acofork.com/img/across-nat-2024-10-28-17-21-31-image.webp\" alt=\"\" width=\"2549\" height=\"1361\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>Zerotier默认的网络组模式为<code>Private</code>。即私密模式，哪怕别人知道了你的<code>Network ID</code>尝试加入你的网络组也需要你进行验证</p>\n<p><img src=\"https://b.acofork.com/img/across-nat-2024-10-28-17-22-38-image.webp\" alt=\"\" width=\"2526\" height=\"1528\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>复制这个<code>Network ID</code><img src=\"https://b.acofork.com/img/across-nat-2024-10-28-17-22-13-image.webp\" alt=\"\" width=\"2560\" height=\"1369\" loading=\"lazy\" decoding=\"async\" /></p>\n<hr />\n<h2 id=\"在设备上安装zerotier应用\">在设备上安装Zerotier应用</h2><h3 id=\"windows\">Windows：</h3><p>前往<a href=\"https://www.zerotier.com/download/\" target=\"_blank\" rel=\"noopener noreferrer\">Download - ZeroTier</a>，下载exe安装文件<img src=\"https://b.acofork.com/img/across-nat-2024-10-28-17-25-52-image.webp\" alt=\"\" width=\"2560\" height=\"1369\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>打开Zerotier<img src=\"https://b.acofork.com/img/across-nat-2024-10-28-17-27-20-image.webp\" alt=\"\" width=\"1072\" height=\"1190\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>查看右下角托盘，按照图片操作加入网络组<img src=\"https://b.acofork.com/img/across-nat-2024-10-28-17-28-20-image.webp\" alt=\"\" width=\"399\" height=\"358\" loading=\"lazy\" decoding=\"async\" /><img src=\"https://b.acofork.com/img/across-nat-2024-10-28-17-29-12-image.webp\" alt=\"\" width=\"556\" height=\"392\" loading=\"lazy\" decoding=\"async\" /><img src=\"https://b.acofork.com/img/across-nat-2024-10-28-17-30-26-image.webp\" alt=\"\" width=\"527\" height=\"235\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>这里可以查询到你的设备ID和你在这个网络组的IP</p>\n<p><img src=\"https://b.acofork.com/img/across-nat-2024-10-28-18-03-19-image.webp\" alt=\"\" width=\"1161\" height=\"614\" loading=\"lazy\" decoding=\"async\" /></p>\n<p><strong>然后参考：<a href=\"#zerotier授权设备\">Zerotier授权设备</a></strong></p>\n<h3 id=\"linux-飞牛os\">Linux（飞牛OS）：</h3><p>通过SSH连接上你的Linux设备</p>\n<p>查看安装命令：<a href=\"https://www.zerotier.com/download/\" target=\"_blank\" rel=\"noopener noreferrer\">Download - ZeroTier</a><img src=\"https://b.acofork.com/img/across-nat-2024-10-28-17-38-19-image.webp\" alt=\"\" width=\"2560\" height=\"1369\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>终端执行： <code>curl -s https://install.zerotier.com | sudo bash</code></p>\n<p>看到这一行即安装完毕，后面那一串即你的设备ID：<img src=\"https://b.acofork.com/img/across-nat-2024-10-28-17-39-23-image.webp\" alt=\"\" width=\"967\" height=\"1312\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>加入网络：<code>sudo zerotier-cli join 你的Network ID</code><img src=\"https://b.acofork.com/img/across-nat-2024-10-28-17-42-01-image.webp\" alt=\"\" width=\"748\" height=\"69\" loading=\"lazy\" decoding=\"async\" /></p>\n<p><strong>然后参考：<a href=\"#zerotier%E6%8E%88%E6%9D%83%E8%AE%BE%E5%A4%87\">Zerotier授权设备</a></strong></p>\n<h3 id=\"android-安卓\">Android（安卓）</h3><p>下载客户端</p>\n<ol>\n<li><p>Zerotier One：<a href=\"https://apkpure.net/zerotier-one/com.zerotier.one\" target=\"_blank\" rel=\"noopener noreferrer\">ZeroTier One APK Download for Android - Latest Version</a></p>\n</li>\n<li><p>ZerotierFix：<a href=\"https://github.com/kaaass/ZerotierFix/releases\" target=\"_blank\" rel=\"noopener noreferrer\">Releases · kaaass/ZerotierFix</a></p>\n</li>\n</ol>\n<p>如图操作</p>\n<p><img src=\"https://b.acofork.com/img/across-nat-2024-10-28-17-59-06-image.webp\" alt=\"\" width=\"499\" height=\"1127\" loading=\"lazy\" decoding=\"async\" /><img src=\"https://b.acofork.com/img/across-nat-2024-10-28-17-59-46-image.webp\" alt=\"\" width=\"499\" height=\"1156\" loading=\"lazy\" decoding=\"async\" /></p>\n<p><strong>然后参考：<a href=\"#zerotier%E6%8E%88%E6%9D%83%E8%AE%BE%E5%A4%87\">Zerotier授权设备</a></strong></p>\n<hr />\n<h2 id=\"zerotier授权设备\">Zerotier授权设备</h2><p>前往Zerotier的网页控制台：<a href=\"https://my.zerotier.com/\" target=\"_blank\" rel=\"noopener noreferrer\">ZeroTier Central</a></p>\n<p>授权刚才加入的设备<img src=\"https://b.acofork.com/img/across-nat-2024-10-28-17-31-51-image.webp\" alt=\"\" width=\"2560\" height=\"1369\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>勾选然后保存<img src=\"https://b.acofork.com/img/across-nat-2024-10-28-17-33-10-image.webp\" alt=\"\" width=\"2526\" height=\"1361\" loading=\"lazy\" decoding=\"async\" /></p>\n<hr />\n<h2 id=\"zerotier访问测试\">Zerotier访问测试</h2><p>如果你同一个网络组里已经有两台以上的设备了，可以尝试ping一下测试连通性，请先确保两台设备不在同一个局域网（比如手机开流量，NAS用家里的无线网）</p>\n<p>IP可以在这里查看<img src=\"https://b.acofork.com/img/across-nat-2024-10-28-18-02-00-image.webp\" alt=\"\" width=\"2526\" height=\"1366\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>ping测试：<img src=\"https://b.acofork.com/img/across-nat-2024-10-28-18-07-13-image.webp\" alt=\"\" width=\"784\" height=\"347\" loading=\"lazy\" decoding=\"async\" /></p>\n<hr />\n<h2 id=\"使用tailscale进行内网穿透的详细教程\">使用Tailscale进行内网穿透的详细教程</h2><h3 id=\"创建tailscale账号\">创建Tailscale账号</h3><p>前往：<a href=\"https://login.tailscale.com/start\" target=\"_blank\" rel=\"noopener noreferrer\">Tailscale</a>。如果你进不去，请尝试挂梯子。如果看不懂英文可以开启浏览器的翻译功能</p>\n<p>选择任意一个登录方式<img src=\"https://b.acofork.com/img/across-nat-2024-10-28-18-24-32-image.webp\" alt=\"\" width=\"753\" height=\"1085\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>账号创建完毕后，登录即可</p>\n<hr />\n<h2 id=\"在设备上安装tailscale应用\">在设备上安装Tailscale应用</h2><h3 id=\"windows-2\">Windows：</h3><p>前往<a href=\"https://tailscale.com/download\" target=\"_blank\" rel=\"noopener noreferrer\">Download · Tailscale</a>，下载exe安装文件</p>\n<p>官方教程：<img src=\"https://b.acofork.com/img/across-nat-2024-10-28-18-31-48-image.webp\" alt=\"\" width=\"965\" height=\"279\" loading=\"lazy\" decoding=\"async\" /></p>\n<h3 id=\"linux-飞牛os-2\">Linux（飞牛OS）：</h3><p>通过SSH连接上你的Linux设备</p>\n<p>查看安装命令：<a href=\"https://tailscale.com/download/linux\" target=\"_blank\" rel=\"noopener noreferrer\">Download · Tailscale</a><img src=\"https://b.acofork.com/img/across-nat-2024-10-28-18-32-58-image.webp\" alt=\"\" width=\"2526\" height=\"1366\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>终端执行： <code>curl -fsSL https://tailscale.com/install.sh | sh</code></p>\n<p>等待安装完毕后输入：<code>tailscale login</code></p>\n<p>打开弹出的浏览器窗口，登录你的账号即可</p>\n<h3 id=\"android-安卓-2\">Android（安卓）</h3><p>下载客户端（Google Play）：<a href=\"https://tailscale.com/download/android\" target=\"_blank\" rel=\"noopener noreferrer\">Download · Tailscale</a></p>\n<p>登录你的账号即可</p>\n<hr />\n<h3 id=\"tailscale访问测试\">Tailscale访问测试</h3><p>前往Tailscale的网页控制台：<a href=\"https://login.tailscale.com/admin/machines\" target=\"_blank\" rel=\"noopener noreferrer\">Machines - Tailscale</a>。可以查看到每个设备Tailscale分配的IP<img src=\"https://b.acofork.com/img/across-nat-2024-10-28-18-26-58-image.webp\" alt=\"\" width=\"2560\" height=\"1462\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>ping测试<img src=\"https://b.acofork.com/img/across-nat-2024-10-28-18-41-45-image.webp\" alt=\"\" width=\"777\" height=\"417\" loading=\"lazy\" decoding=\"async\" /></p>\n<hr />\n<h2 id=\"使用cloudflare-tunnel进行内网穿透\">使用Cloudflare Tunnel进行内网穿透</h2><blockquote>\n<p>这种方法可以不进行任何配置直接在公网上被访问，但是仅限Web服务。如果你想穿透游戏服务器等则不可用。你需要先将域名托管到Cloudflare</p>\n</blockquote>\n<p>创建Cloudflare账号<a href=\"https://dash.cloudflare.com/\" target=\"_blank\" rel=\"noopener noreferrer\">主页 | Cloudflare</a></p>\n<p>进入<a href=\"https://one.dash.cloudflare.com/\" target=\"_blank\" rel=\"noopener noreferrer\">Cloudflare One</a>（需要绑定PayPal）</p>\n<p>如图操作，创建一个Tunnel<img src=\"https://b.acofork.com/img/across-nat-2024-10-28-18-45-41-image.webp\" alt=\"\" width=\"2560\" height=\"1369\" loading=\"lazy\" decoding=\"async\" /><img src=\"https://b.acofork.com/img/across-nat-2024-10-28-18-45-54-image.webp\" alt=\"\" width=\"2560\" height=\"1369\" loading=\"lazy\" decoding=\"async\" /><img src=\"https://b.acofork.com/img/across-nat-2024-10-28-18-46-22-image.webp\" alt=\"\" width=\"2560\" height=\"1369\" loading=\"lazy\" decoding=\"async\" /></p>\n<h3 id=\"docker方式\">Docker方式</h3><p><strong>使用1Panel</strong></p>\n<p>复制如图的命令</p>\n<p><img src=\"https://b.acofork.com/img/across-nat-48e9c43eb5c0fb49cc5517687698e3d9d1e60220.webp\" alt=\"\" width=\"2560\" height=\"1369\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>将其粘贴，并且复制后面的令牌<img src=\"https://b.acofork.com/img/across-nat-a2e18519d3782d765d7293c7a3d21031c787d575.webp\" alt=\"\" width=\"1461\" height=\"1124\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>1Panel应用商店搜索<code>cloudflared</code><img src=\"https://b.acofork.com/img/across-nat-cf2eba61f0aaa7605240187e1c46f80a3954edfa.webp\" alt=\"\" width=\"2560\" height=\"1369\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>填入令牌<img src=\"https://b.acofork.com/img/across-nat-6f661ffa778b2be2e108912d3d44d8b3301df6d6.webp\" alt=\"\" width=\"2560\" height=\"1369\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>然后前往<a href=\"#查看cloudflared的ip\">查看IP</a></p>\n<p><strong>使用命令运行</strong></p>\n<p>复制底下的命令然后SSH连接到Linux（飞牛OS）在终端输入</p>\n<p><img src=\"https://b.acofork.com/img/across-nat-2024-10-28-18-46-49-image.webp\" alt=\"\" width=\"2560\" height=\"1369\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>然后前往<a href=\"#%E6%9F%A5%E7%9C%8Bcloudflared%E7%9A%84ip\">查看IP</a></p>\n<h4 id=\"查看cloudflared的ip\">查看cloudflared的IP</h4><p>因为我们是Docker模式，所以IP需要通过SSH终端输入<code>ip a</code>来查看。我这里是<code>192.168.124.34</code></p>\n<div class=\"markdown-code\" data-language=\"text\"><div class=\"markdown-code-header\"><span class=\"markdown-code-language\"><svg class=\"code-language-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z\"></path><path d=\"M14 2v5a1 1 0 0 0 1 1h5\"></path><path d=\"M10 9H8\"></path><path d=\"M16 13H8\"></path><path d=\"M16 17H8\"></path></svg><span>text</span></span><button type=\"button\" class=\"code-block-copy\" aria-label=\"复制代码\" title=\"复制代码\"><svg class=\"code-block-copy-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"></rect><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"></path></svg></button></div><pre><code class=\"hljs language-text\">root@n100-debian:~# ip a\n1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000\n    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00\n    inet 127.0.0.1/8 scope host lo\n       valid_lft forever preferred_lft forever\n    inet6 ::1/128 scope host noprefixroute\n       valid_lft forever preferred_lft forever\n2: ens18: tiROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc fq_codel state UP group default qlen 1000\n    link/ether bc:24:11:33:e1:7d brd ff:ff:ff:ff:ff:ff\n    altname enp0s18\n    inet 192.168.124.34/24 brd 192.168.124.255 scope global dynamic ens18\n       valid_lft 46579sec preferred_lft 46579sec\n    inet6 2409:8a30:320:a170:be24:11ff:fe33:e17d/64 scope global dynamic mngtmpaddr\n       valid_lft 1902sec preferred_lft 1898sec\n    inet6 fe80::be24:11ff:fe33:e17d/64 scope link\n       valid_lft forever preferred_lft foreverti</code></pre></div><p><strong>然后前往<a href=\"#配置并访问tunnel\">配置并访问Tunnel</a></strong></p>\n<h3 id=\"原生模式-以debian为例\">原生模式（以Debian为例）</h3><p>选择Debian，然后复制底下的命令，直接到终端执行</p>\n<p><img src=\"https://b.acofork.com/img/across-nat-2024-10-28-20-00-49-image.webp\" alt=\"\" width=\"2560\" height=\"1369\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>如果你的环境无法连接上Github</p>\n<p>尝试手动下载：<a href=\"https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb\" target=\"_blank\" rel=\"noopener noreferrer\">https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb</a></p>\n<p>然后将其通过SSH等方式传到Linux上，如图终端为MobaXterm<img src=\"https://b.acofork.com/img/across-nat-2024-10-29-10-18-29-image.webp\" alt=\"\" width=\"1365\" height=\"1235\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>然后使用：<code>dpkg -i cloudflared-linux-amd64.deb</code>安装这个软件包</p>\n<p>然后直接复制右边的命令到SSH终端执行<img src=\"https://b.acofork.com/img/across-nat-2024-10-29-10-19-27-3dcfad6977bdecf80fc0366f257788e6.webp\" alt=\"\" width=\"2560\" height=\"1369\" loading=\"lazy\" decoding=\"async\" /></p>\n<p><strong>然后前往<a href=\"#%E9%85%8D%E7%BD%AE%E5%B9%B6%E8%AE%BF%E9%97%AEtunnel\">配置并访问Tunnel</a></strong></p>\n<h3 id=\"android-termux\">Android（Termux）</h3><p>在Android上安装<a href=\"https://termux.dev\" target=\"_blank\" rel=\"noopener noreferrer\">Termux | The main termux site and help pages.</a></p>\n<p>在终端执行：<code>pkg install cloudflared</code></p>\n<p>选择<code>Debian</code>然后复制最右边的命令到终端执行<img src=\"https://b.acofork.com/img/across-nat-2024-10-29-08-42-38-image.webp\" alt=\"\" width=\"2560\" height=\"1369\" loading=\"lazy\" decoding=\"async\" />\n如果你无法使用Termux自带的cloudflared，请尝试安装proot容器实现</p>\n<p>依次输入命令：</p>\n<div class=\"markdown-code\" data-language=\"shell\"><div class=\"markdown-code-header\"><span class=\"markdown-code-language\"><svg class=\"code-language-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M12 19h8\"></path><path d=\"m4 17 6-6-6-6\"></path></svg><span>shell</span></span><button type=\"button\" class=\"code-block-copy\" aria-label=\"复制代码\" title=\"复制代码\"><svg class=\"code-block-copy-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"></rect><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"></path></svg></button></div><pre><code class=\"hljs language-shell\">pkg update &amp;&amp; pkg upgrade\npkg install proot\npkg install proot-distro\nproot-distro list\nproot-distro install debian\nproot-distro login debian\napt install wget\nwget https://github.com/cloudflare/cloudflared/releases/download/2024.10.1/cloudflared-linux-arm64.deb\ndpkg -i cloudflared-linux-amd64.deb</code></pre></div><p>然后直接复制右边的命令到SSH终端执行</p>\n<p><img src=\"https://b.acofork.com/img/across-nat-2024-10-29-08-42-38-image.webp\" alt=\"\" width=\"2560\" height=\"1369\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>如果你无法通过令牌配置cloudflared，请参见<a href=\"#本地方式\">本地方式配置cloudflared</a></p>\n<p><strong>然后前往<a href=\"#%E9%85%8D%E7%BD%AE%E5%B9%B6%E8%AE%BF%E9%97%AEtunnel\">配置并访问Tunnel</a></strong></p>\n<hr />\n<h2 id=\"配置并访问tunnel\">配置并访问Tunnel</h2><h3 id=\"通过网页配置\">通过网页配置</h3><blockquote>\n<p>这种方法需要直接在安装了cloudflared的设备上通过令牌运行</p>\n</blockquote>\n<p>如图进入，创建一个HTTP隧道</p>\n<p><img src=\"https://b.acofork.com/img/across-nat-2024-10-28-18-49-21-image.webp\" alt=\"\" width=\"2555\" height=\"1361\" loading=\"lazy\" decoding=\"async\" /><img src=\"https://b.acofork.com/img/across-nat-2024-10-28-18-49-44-image.webp\" alt=\"\" width=\"2560\" height=\"1369\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>填写你的IP和端口，非Docker模式可以直接填写localhost<img src=\"https://b.acofork.com/img/across-nat-2024-10-28-18-53-37-image.webp\" alt=\"\" width=\"2560\" height=\"1369\" loading=\"lazy\" decoding=\"async\" /></p>\n<h3 id=\"本地方式\">本地方式</h3><blockquote>\n<p>这种方法只需要在安装了cloudflared的设备上输入一些命令然后通过网页授权，后续更改配置也需要在本地操作</p>\n</blockquote>\n<p>登录并授权：<code>cloudflared tunnel login</code></p>\n<p>创建隧道并设置隧道（HTTP模式穿透，目标地址<code>127.0.0.1</code>，端口：<code>8080</code>，外部域名：<code>test.onani.cn</code>）：<code>cloudflared tunnel --name test --url http://127.0.0.1:8080 --http2 --hostname test.onani.cn</code></p>\n<h3 id=\"访问测试\">访问测试</h3><p>成功访问<img src=\"https://b.acofork.com/img/across-nat-2024-10-28-18-54-42-image.webp\" alt=\"\" width=\"2560\" height=\"1455\" loading=\"lazy\" decoding=\"async\" /></p>\n<h2 id=\"使用stun打洞\">使用STUN打洞</h2><blockquote>\n<p>这种方法可以不进行任何配置直接在公网上被访问，并且所有类型的服务都能正常使用。但是这种方式进行的内网穿透无法固定也无法指定IP和端口，在3~7天后会改变</p>\n</blockquote>\n<h3 id=\"安装lucky\">安装Lucky</h3><p>执行：<code>curl -o /tmp/install.sh http://6.666666.host:6/files/golucky.sh &amp;&amp; sh /tmp/install.sh http://6.666666.host:6/files 2.13.4</code></p>\n<p>通过<code>host:16601</code> 进入Lucky后台，设置STUN穿透。如果DMZ主机不设为Lucky主机可能会失败。打码的地方即公网访问的IP和端口<img src=\"https://b.acofork.com/img/across-nat-2024-10-28-18-56-16-image.webp\" alt=\"\" width=\"2560\" height=\"1369\" loading=\"lazy\" decoding=\"async\" /></p>\n","toc":[{"id":"经实测-zerotier的打洞能力明显优于tailscale-所以建议通过zerotier来实现内网穿透","text":"经实测，Zerotier的打洞能力明显优于Tailscale，所以建议通过Zerotier来实现内网穿透","depth":2},{"id":"啥是内网穿透","text":"啥是内网穿透？","depth":2},{"id":"前期准备","text":"前期准备","depth":2},{"id":"使用zerotier-tailscale进行内网穿透","text":"使用Zerotier/Tailscale进行内网穿透","depth":2},{"id":"使用zerotier进行内网穿透的详细教程","text":"使用Zerotier进行内网穿透的详细教程","depth":2},{"id":"创建zerotier账号","text":"创建Zerotier账号","depth":3},{"id":"创建一个新的zerotier网络组","text":"创建一个新的Zerotier网络组","depth":3},{"id":"在设备上安装zerotier应用","text":"在设备上安装Zerotier应用","depth":2},{"id":"windows","text":"Windows：","depth":3},{"id":"linux-飞牛os","text":"Linux（飞牛OS）：","depth":3},{"id":"android-安卓","text":"Android（安卓）","depth":3},{"id":"zerotier授权设备","text":"Zerotier授权设备","depth":2},{"id":"zerotier访问测试","text":"Zerotier访问测试","depth":2},{"id":"使用tailscale进行内网穿透的详细教程","text":"使用Tailscale进行内网穿透的详细教程","depth":2},{"id":"创建tailscale账号","text":"创建Tailscale账号","depth":3},{"id":"在设备上安装tailscale应用","text":"在设备上安装Tailscale应用","depth":2},{"id":"windows-2","text":"Windows：","depth":3},{"id":"linux-飞牛os-2","text":"Linux（飞牛OS）：","depth":3},{"id":"android-安卓-2","text":"Android（安卓）","depth":3},{"id":"tailscale访问测试","text":"Tailscale访问测试","depth":3},{"id":"使用cloudflare-tunnel进行内网穿透","text":"使用Cloudflare Tunnel进行内网穿透","depth":2},{"id":"docker方式","text":"Docker方式","depth":3},{"id":"查看cloudflared的ip","text":"查看cloudflared的IP","depth":4},{"id":"原生模式-以debian为例","text":"原生模式（以Debian为例）","depth":3},{"id":"android-termux","text":"Android（Termux）","depth":3},{"id":"配置并访问tunnel","text":"配置并访问Tunnel","depth":2},{"id":"通过网页配置","text":"通过网页配置","depth":3},{"id":"本地方式","text":"本地方式","depth":3},{"id":"访问测试","text":"访问测试","depth":3},{"id":"使用stun打洞","text":"使用STUN打洞","depth":2},{"id":"安装lucky","text":"安装Lucky","depth":3}]}