> For the complete documentation index, see [llms.txt](https://youngzil.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://youngzil.gitbook.io/notes/ri-chang-chang-shi/da-jian-ti-zi-vpn/nei-wang-chuan-tou.md).

# 内网穿透

## 内网穿透

内网穿透，也即 NAT 穿透，进行 NAT 穿透是为了使具有某一个特定源 IP 地址和源端口号的数据包不被 NAT 设备屏蔽而正确路由到内网主机

UDP 内网穿透的实质是利用路由器上的NAT 系统。NAT 是一种将私有（保留）地址转化为合法IP地址的转换技术，它被广泛应用于各种类型 Internet 接入方式和各种类型的网络中。NAT可以完成重用地址，并且对于内部的网络结构可以实现对外隐蔽。

网络地址转换（Network Address Translation，NAT）机制的问题在于，NAT设备自动屏蔽了非内网主机主动发起的连接，也就是说，从外网发往内网的数据包将被NAT设备丢弃，这使得位于不同NAT设备之后的主机之间无法直接交换信息。这一方面保护了内网主机免于来自外部网络的攻击，另一方面也为P2P通信带来了一定困难。Internet上的NAT设备大多是地址限制圆锥形NAT或端口限制圆锥形 NAT，外部主机要与内网主机相互通信，必须由内网主机主动发起连接，使 NAT设备产生一个映射条目，这就有必要研究一下内网穿透技术。

NAT穿透的原理

内网穿透的原理很简单的说就是: 两台计算机A和B都处于不同的局域网中，A想要访问B, 就需要通过一台服务器做桥接的，

桥接的方式有两种，

* 一种是服务器相互转发流量 到A和B，
* 另一种是告诉对方公网IP地址，自己充当一个介绍人的角色, 专业术语叫DNAT目标地址转换。

NAT设备（或软件）维护一个状态表，用来把内部网络的私有IP地址映射到外部网络的合法IP地址上去。每个包头中的IP地址和端口信息在NAT设备（或软件）中都被修改并翻译成一正确的IP地址发往下一级。

当一个内网主机通过NAT打开一个“外出”的TCP或UDP会话时，NAPT分配给这个会话一个公网IP和端口，用来接收外网的响应的数据包，并经过转换通知内部网的主机。这样，NAPT在\[私有IP：私有端口]和\[公网IP：公网端口]之间建立了一个端口绑定

中转服务器发送 打洞命令或者说是打洞数据包

[内网穿透百度百科](https://baike.baidu.com/item/%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F)\
[什么是内网穿透？](https://flynat.51miaole.com/docs/start/what-nat/) [内网穿透原理是什么？](https://www.zhihu.com/question/276309837)

## 内网穿透工具

[NPS](https://github.com/ehang-io/nps)

一款轻量级、高性能、功能强大的内网穿透代理服务器。支持tcp、udp、socks5、http等几乎所有流量转发，可用来访问内网网站、本地支付接口调试、ssh访问、远程桌面，内网dns解析、内网socks5代理等等……，并带有功能强大的web管理端。 a lightweight, high-performance, powerful intranet penetration proxy server, with a powerful web management terminal.

[frp](https://github.com/fatedier/frp)

frp 是一个高性能的反向代理应用，可以帮助您轻松地进行内网穿透，对外网提供服务，支持 tcp, http, https 等协议类型，并且 web 服务支持根据域名进行路由转发。

[Ngrok](https://ngrok.com/)

ngrok 是一个反向代理，通过在公共的端点和本地运行的 Web 服务器之间建立一个安全的通道。

[蜻蜓映射](https://flynat.51miaole.com/)

蜻蜓映射是一款完全免费的端口映射工具，集成了动态域名解析和内网穿透。 支持多种类型的应用程序服务（办公OA、ERP、视频监控、微信开发等）。蜻蜓映射可以轻松的实现外网访问内网服务器，而无需运营商分配的公网IP地址，也无需动态域名。

[natapp](https://natapp.cn/)

基于ngrok的内网映射工具，免费版本提供http,tcp,udp全隧道穿透、随机域名/随机TCP,UDP端口、不定时强制更换域名/端口和自定义本地端口。

[花生壳](https://hsk.oray.com/)

简单好配置，可以下载客户端配置，也可以直接在他们官网注册，web页面上直接配置，简单快捷，重点不收费。

[推荐5款最好用的内网穿透工具](https://segmentfault.com/a/1190000038658138)\
[内网穿透的几款工具](https://blog.csdn.net/qq_36468810/article/details/109219639)

[内网穿透原理总结与工具推荐](https://juejin.cn/post/6844904169497690120)\
[实现内网穿透的十几种方法](https://www.jianshu.com/p/04521ab27e67)

[比较好用的内网穿透工具ngrok](https://www.huaweicloud.com/articles/5788150f9b40cf690752a4b73c5f5052.html)\
[内网穿透工具frp好用吗](https://hsk.oray.com/news/8440.html)

[ngrok搭建指南](https://luozm.github.io/ngrok)\
[10分钟教你搭建自己的ngrok服务器](https://blog.csdn.net/yjc_1111/article/details/79353718)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://youngzil.gitbook.io/notes/ri-chang-chang-shi/da-jian-ti-zi-vpn/nei-wang-chuan-tou.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
