内网穿透:frp、termite、异地组网、安卓手机搭建web

​中文文档:https://github.com/fatedier/frp/blob/dev/README_zh.md
软路由 通过 Openwrt 自带的 Frp 插件:https://zhuanlan.zhihu.com/p/367894569
内外网互通 ( Ngrok、钉钉、花生壳、frp ):https://www.it235.com/实用工具/内网穿透/pierce.html

关键字:内网穿透 域名映射

1、内网穿透

什么是内网穿透

"内网穿透" 就是 "公网的电脑" 可以直接访问 "位于其他局域网并且不能通过公网直接访问的电脑"。例如你在公司电脑不通过远程工具,也可以直接访问到家里的电脑。总结:内网穿透就是把局域网的端口暴露给公网,然后通过公网就可以访问局域网暴露端口的服务

通常实现内网穿透,是通过路由器上端口映射来实现的。但是路由器通常不是每个人都有权限可以访问和设置,而且可能存在多级路由器较为复杂的网络结构。端口映射也无法实现。

为什么需要内网穿透

需要用到内网穿透的原因:

  • 一是方便访问公司的内网环境,不喜欢使用远程工具。
  • 二是方便把个人电脑上的应用开放到外网进行访问。

外网访问内网:端口映射、端口转发。端口映射与端口转发这两个词在很多时候都混用了。

  • 端口映射发生于 节点 与 路由/网关 之间,以NAT(Network Address Translation,网络地址翻译)为原理;
  • 而端口转发以反向隧道、反向代理为原理,发生于两个网络节点的端口之间。

基于 端口映射

  • 路由器的虚拟服务器(端口映射)功能
  • Windows上专用的端口映射工具PortTunnel
  • Linux 端口映射工具:RINETD
  • nat123 的端口映射。nat123对Linux、Windows、Android都适用,官网有相应教程
  • 花生壳内网穿透 NAT-DDNS

端口转发需要一个公网IP服务器,如果自己没有的话,就只能寻找第三方提供的服务了。

基于 反向隧道 端口转发

反向隧道端口转发的典型是SSH端口转发

ssh端口转发
ssh端口转发基础知识
ssh的三个强大的端口转发命令:
        转发到远端:ssh -C -f -N -g -L 本地端口:目标IP:目标端口 用户名@目标IP
        转发到本地:ssh -C -f -N -g –R 本地端口:目标IP:目标端口 用户名@目标IP
        动态端口转发:ssh -C -f -N -g -D listen_port 用户名@目标IP

  • -C:压缩数据传输。
  • -f :后台认证用户/密码,通常和 -N 连用,不用登录到远程主机。
  • -N :不执行脚本或命令,通常与 -f 连用。
  • -g :在-L/-R/-D参数中,允许远程主机连接到建立的转发的端口,如果不加这个参数,只允许本地主机建立连接。
  • -L 本地端口:目标IP:目标端口:将本地机(客户机)的某个端口转发到远端指定机器的指定端口. 工作原理是这样的, 本地机器上分配了一个 socket 侦听 port 端口, 一旦这个端口上有了连接, 该连接就经过安全通道转发出去, 同时远程主机和 host 的 hostport 端口建立连接. 可以在配置文件中指定端口的转发. 只有 root 才能转发特权端口. IPv6 地址用另一种格式说明: port/host/hostport
  • -R 本地端口:目标IP:目标端口:将远程主机(服务器)的某个端口转发到本地端指定机器的指定端口. 工作原理是这样的, 远程主机上分配了一个 socket 侦听 port 端口, 一旦这个端口上有了连接, 该连接就经过安全通道转向出去, 同时本地主机和 host 的 hostport 端口建立连接. 可以在配置文件中指定端口的转发. 只有用 root 登录远程主机才能转发特权端口. IPv6 地址用另一种格式说明: port/host/hostport
  • -p :被登录的ssd服务器的sshd服务端口。
  • -D listen_port:指定一个本地机器 “动态的'’ 应用程序端口转发. 工作原理是这样的, 本地机器上分配了一个 socket 侦听 port 端口, 一旦这个端口上有了连接, 该连接就经过安全通道转发出去, 根据应用程序的协议可以判断出远程主机将和哪里连接. 目前支持 SOCKS4 协议, 将充当 SOCKS4 服务器. 只有 root 才能转发特权端口. 可以在配置文件中指定动态端口的转发.

ssh 端口转发简单测试 示例:
(1)只有树莓派和服务器
步骤1:在树莓派上,通过远程端口映射,将服务器的2222端口映射到树莓派的22端口:
ssh -fNR 2222:localhost:22 root@公网IP
步骤2:服务器上访问树莓派:
ssh -p 2222 pi@localhost
但事实上,有时候我们可能更需要另一个设备可以访问树莓派,而不是在服务器上访问。因此这个时候我们就需要做两次映射。
(2)树莓派、服务器、第三方设备
步骤1:在树莓派上,通过远程端口映射,将服务器的2222端口映射到树莓派的22端口:
ssh -fNR 2222:localhost:22 root@公网IP
步骤2:在第三方设备上,通过本地端口映射,将第三方设备的2222端口映射到服务器的2222端口:
ssh -fNL 2222:localhost:2222 root@公网IP
步骤3:在第三方设备上访问树莓派:
ssh -p 2222 pi@localhost

无需公网IP 的 内网穿透

内网穿透,c++实现,无需公网IP:https://github.com/lazy-luo/smarGate

cpolar:一款好用的内网穿透工具 - 无需公网IP:https://blog.csdn.net/u012039040/article/details/127490169

免费域名

freenom:https://www.freenom.com/zh/index.html?lang=zh

Android 手机搭建web服务器

由于手机连接路由器后有时候会被分配不同的 IP 地址,所以避免这个情况产生,可以在路由器设置中将手机 IP 与 MAC 地址绑定,这样手机每次连接后的 IP 地址就不会改变了。

KSWEB、Ngrok

安卓手机是基于Linux的,也就是说安卓手机本身就是一台Linux服务器,只要简单配置,就可以把它可以变成一台网站服务器

  • 第一阶段:把手机变成内网服务器,就是只能在一个局域网内访问该服务器的Web服务。在手机上搭建Web服务器的App很多,像 ksweb、Linux Deploy、termux、busybox等等。这里使用最简单的集成工具 ksweb
  • 第二阶段:想外网访问内网服务器,需要进行内网穿透。

KSWEB是俄罗斯人开发的基于安卓系统的web服务器,集成了php、Nginx、MySQL、Apache、FTP等,不过软件收费。

KSWEB 支持的服务

  • Lighttpd server v1.4.35
  • Nginx v1.13.1
  • Apache v2.4.28
  • PHP v8.0.6 (also can be selected 7.4.23, 7.3.30, 7.2.34, 7.1.33, 5.6.40)
  • MySQL v5.7.34 for Android > 8 (5.6.38 for all versions of Android included)
  • Msmtp v1.8.15
  • Web Interface v3.0
  • KSWEBFTP v1.0
  • Editor v1.2
  • Scheduler

KSWEB + termux + frp

旧手机搭建网站以及内网穿透:https://ii.do/24.html

手机+frp内网穿透搭建随身携带的服务器:https://blog.csdn.net/sinat_27938829/article/details/73604722

手机搭建个人网站 ( KSWEB+TERMUX+FRP内网穿透 ):https://www.jianshu.com/p/9981d27c0350

android 版端口映射

http://www.nat123.com/pages_8_564.jsp

android版详细特性: 

免费域名、80映射、https映射、非80网站映射、非网站映射、全端口映射P2P穿透、动态域名解析…
- 提供免费域名,支持所有域名解析,泛域名解析。
- 适合任意网络环境。只要能上网即可使用。
- 自动恢复联网。本地网络中断等异常及恢复后,自动重连。
端口映射:
- 无需公网ip,无需路由映射。在任何环境都可发布网站,访问内网。
- 灵活的内网地址格式。如127.0.0.1/192.168.1.9/localhost/hostname。
- 经映射的网站客户端用户访问真实IP不丢失。
- 支持内网同一端口绑定多个域名映射。
- http穿透。
- 80映射。80端口穿透。
- 自定义端口映射。外网访问端口自定义。
- 全端口映射P2P穿透,无需改变访问端口。适用于多端口、固定端口、C/S架构、UDP等所有应用。
- 网站加速。解决本地公网带宽上行小,提升网站访问加载速度。
- 意外离线提示自定义、离线转跳。
动态域名解析:
- 解决动态公网IP问题,实时获取本地最新公网IP地址。
- 意外离线保持IP解析。电脑死机重启等本地网络意外离线时,自动保持域名解析IP,提升应用稳定。
- 意外离线提示自定义、离线转跳。

cpolar (全平台支持)

cpolar (极点云):公开一个本地Web站点至公网:https://www.cpolar.com/download

cpolar 也是一款强大的内网穿透工具。

免费版:随机URL二级域名、随机TCP端口、HTTP / TCP 隧道支持、1个在线cpolar进程、4个隧道/cpolar进程

异地 组网

"异地组网" 就是让不同地方的局域网实现相互访问。异地组网可适用于复杂的网络结构,无需公网IP,就能快速组建虚拟专用网络,实现异地设备之间的互访,让彼此就像在同一局域网内。

星空组网:https://ip4.ink/
Zerotier 异地组网:https://blog.dreamfall.cn/post/zerotier/
Tailscale:https://tailscale.com/download
贝锐:https://pgy.oray.com/

蒲公英 异地组网 界面:

2、Frp 介绍

Github:https://github.com/fatedier/frp

FRP 全名 Fast Reverse Proxy,是用 Go 语言开发的高性能的反向代理应用,专注于内网穿透。

frp 工作原理

  • 服务端 frps 运行,监听一个主端口,等待 客户端 frpc 的连接;
  • 客户端连接到服务端的主端口(默认7000),同时告诉服务端要监听的端口和转发类型;
  • 服务端 fork 新的进程监听客户端指定的端口;
  • 外网用户连接到客户端指定的端口,服务端通过和客户端的连接将数据转发到客户端;
  • 客户端进程再将数据转发到本地服务,从而实现内网对外暴露服务的能力。

frp 支持多种代理类型,以适应不同的使用场景。可以根据需求选择合适的代理类型来配置 frp。以下是一些常见的代理类型:

  • TCP:提供纯粹的 TCP 端口映射,使服务端能够根据不同的端口将请求路由到不同的内网服务。
  • UDP:提供纯粹的 UDP 端口映射,与 TCP 代理类似,但用于 UDP 流量。
  • HTTP:专为 HTTP 应用设计,支持修改 Host Header 和增加鉴权等额外功能。
  • HTTPS:类似于 HTTP 代理,但专门用于处理 HTTPS 流量。
  • STCP:提供安全的 TCP 内网代理,要求在被访问者和访问者的机器上都部署 frpc,不需要在服务端暴露端口。
  • SUDP:提供安全的 UDP 内网代理,与 STCP 类似,需要在被访问者和访问者的机器上都部署 frpc,不需要在服务端暴露端口。
  • XTCP:点对点内网穿透代理,与 STCP 类似,但流量不需要经过服务器中转。
  • TCPMUX:支持服务端 TCP 端口的多路复用,允许通过同一端口访问不同的内网服务。

使用 frp工具有以下优势:

  • 多种协议支持
  • TCP 连接流式复用:在单个连接上承载多个请求,减少连接建立时间,降低请求延迟。
  • 代理组间的负载均衡。
  • 端口复用:多个服务可以通过同一个服务端端口暴露。
  • P2P 通信:流量不必经过服务器中转,充分利用带宽资源。
  • 客户端插件:提供多个原生支持的客户端插件,如静态文件查看、HTTPS/HTTP 协议转换、HTTP、SOCKS5 代理等,以便满足各种需求。
  • 服务端插件系统:高度可扩展的服务端插件系统,便于根据自身需求进行功能扩展。
  • 用户友好的 UI 页面:提供服务端和客户端的用户界面,使配置和监控变得更加方便。

下载、部署

从 GitHub 的 Release 页面中下载最新版本的客户端和服务器二进制文件。所有文件都打包在一个压缩包中,还包含了一份完整的配置参数说明

  1. 解压下载的压缩包。
  2. 将 frpc 复制到内网服务所在的机器上。
  3. 将 frps 复制到拥有公网 IP 地址的机器上,并将它们放在任意目录。

开始使用

  1. 编写配置文件,目前支持的文件格式包括 TOML/YAML/JSON,旧的 INI 格式仍然支持,但已经不再推荐。
  2. 使用以下命令启动服务器:./frps -c ./frps.toml
  3. 使用以下命令启动客户端:./frpc -c ./frpc.toml
  4. 如果需要在后台长期运行,建议结合其他工具,如 systemd 和 supervisor

frps 服务端一键配置脚本

FRP 的部署安装比较简单。不过手动部署还是有点麻烦,可以使用下面的一键安装脚本:https://github.com/MvsCode/frps-onekey

frp 命令行

服务端命令:

frps是frpc的服务端  (https://github.com/fatedier/frp)

用法:
  frps [flags]
  frps [command]

可用命令:
  completion  为指定的shell生成自动完成脚本
  help        帮助。示例:frps [command] --help
  verify      验证配置是否有效

Flags:
      --allow-ports string               允许哪些端口被分配,可以防止端口被滥用。
      --bind-addr string                 frps服务绑定的地址 (default "0.0.0.0")
  -p, --bind-port int                    frps服务绑定的端口 (default 7000)
  -c, --config string                    frps的配置文件
      --dashboard-addr string            仪表盘地址 (default "0.0.0.0")
      --dashboard-port int               仪表盘端口
      --dashboard-pwd string             仪表盘密码 (default "admin")
      --dashboard-tls-cert-file string   仪表盘tls证书(cert)文件
      --dashboard-tls-key-file string    仪表盘tls秘钥文件
      --dashboard-tls-mode               启用仪表盘 tls 模式
      --dashboard-user string            仪表盘用户名 (default "admin")
      --disable-log-color                禁用控制台的彩色log输出
      --enable-prometheus                启用 prometheus 仪表盘
  -h, --help                             frps帮助
      --kcp-bind-port int                kcp 绑定的 udp 店口
      --log-file string                  log文件 (default "console")
      --log-level string                 log级别 (default "info")
      --log-max-days int                 log保存最大天数 (default 3)
      --max-ports-per-client int         每个客户端最大使用的端口数
      --proxy-bind-addr string           proxy bind address (default "0.0.0.0")
      --strict-config                    严格的配置解析模式,未知字段会导致错误(默认true)
      --subdomain-host string            子域名主机
      --tls-only                         仅使用frps tls
  -t, --token string                     认证 token
  -v, --version                          frps 版本
      --vhost-http-port int              vhost http port
      --vhost-http-timeout int           vhost http response 超时设置 (default 60)
      --vhost-https-port int             vhost https port

客户端命令:

frpc是frps的客户端 (https://github.com/fatedier/frp)

用法:
  frpc [flags]
  frpc [command]

可用命令:
  completion  为指定的shell生成自动完成脚本
  help        关于任何命令的帮助。示例:frpc [command] --help
  http        以http proxy模式运行frpc
  https       以https proxy模式运行frpc
  nathole     Actions about nathole
  reload      热重载配置
  status      查看所有代理的状态
  stcp        以stcp proxy模式运行frpc
  stop        停止 frpc
  sudp        以sudp proxy模式运行frpc
  tcp         以tcp proxy模式运行frpc
  tcpmux      以tcpmux proxy模式运行frpc
  udp         以udp proxy模式运行frpc
  verify      验证配置是否有效
  xtcp        以xtcp proxy模式运行frpc

Flags:
  -c, --config string       frpc配置文件
      --config-dir string   配置目录下,为配置目录下的每个文件运行一个FRPC服务
  -h, --help                帮助
      --strict-config       严格的配置解析模式,未知字段将导致错误(默认为true)
  -v, --version             版本

GUI 客户端

Windows 平台的 FRP GUI 客户端:https://github.com/koho/frpmgr

访问 frp web 页面

通过 Dashboard (仪表盘) 可以查看 FRP 的状态以及代理统计信息展示。需要在FRP服务端配置文件中指定 Dashboard 服务使用的 IP和端口:

webServer.addr = "0.0.0.0"
webServer.port = 7500
webServer.user = "admin"
webServer.password = "admin"

访问 Dashboard 界面:http://[server_addr]:7500 用户名密码默认都为 admin。

完整配置 说明

toml 配置 语法:https://toml.io/cn/v1.0.0

frpc_full_example.toml、frps_full_example.toml:https://github.com/fatedier/frp/tree/dev/conf

TCP & UDP

是 frp 中两种最基础的代理类型,用于代理监听在 TCP 和 UDP 端口的服务。

[[proxies]]
name = "ssh"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22
remotePort = 6000

通过 type 指定代理类型。frp 会为本地服务的 22 端口,在 frps 所在的服务端监听 6000 端口,将 6000 端口接收到的连接和本地服务的 22 端口关联,透传流量,从而实现让用户在外部访问到内部服务。

[[proxies]]

name = "dns"
type = udp
localIP = 8.8.8.8
localPort = 53
remotePort = 6001

通过dig命令测试UDP包转发是否成功:dig @110.110.110.110 -p 6001 www.google.com

STCP & SUDP

STCP 和 SUDP 的 (S) 的含义是 Secret。其作用是为 TCP 和 UDP 类型的服务提供一种安全访问的能力,避免让端口直接暴露在公网上导致任何人都能访问到。

这两种代理要求在被访问服务的机器上以及要访问的用户的机器上都部署上 frp 的客户端。被访问的服务所在机器叫做服务端,另一端叫做访问端。

frp 会在访问端监听一个端口和服务端的端口做映射。访问端的用户需要提供相同的密钥才能连接成功,从而保证安全性。

XTCP

XTCP 的配置方式和 STCP 很类似。但是会采用 P2P 的方式进行打洞穿透,如果成功,后续的流量将不会经过 frps,而是直接通信,不再受到 frps 所在服务器的带宽限制。由于打洞成功率取决于所处网络的 NAT 类型,所以 XTCP 的可用性和稳定性无法保证。在需要可靠连接的情况下,建议使用 STCP 替代。当 visitor 配置了 keepTunnelOpen = true 时,frpc 会定期检测隧道是否打开,如果没有,则会尝试打洞建立隧道,这样可以始终保持隧道打开,在需要连接对端服务时,可以避免延迟。默认情况下,visitor 会在接收到用户连接后尝试打洞,如果打洞失败,可以尝试多次建立连接,程序会尝试其他的打洞策略,有可能在多次重试后成功打洞。一旦打洞成功,后续新增连接不必重复打洞,而是可以复用隧道。

可以通过配置 fallback 到 stcp visitor 实现在打洞失败时,回退到 stcp 建立连接。

[[visitors]]
name = "stcp-visitor"
type = "stcp"
serverName = "stcp-test"
secretKey = "abc"
bindPort = -1

[[visitors]]
name = "xtcp-visitor"
type = "xtcp"
serverName = "xtcp-test"
secretKey = "abc"
bindAddr = "127.0.0.1"
bindPort = 9002
fallbackTo = "stcp-visitor"
fallbackTimeoutMs = 200

当连接 127.0.0.1:9002 超过 200ms p2p 打洞还未成功的话,会回退到使用 stcp-visitor 建立连接。fallback 后,之前触发的打洞操作仍然会继续,一般来说打洞完成需要的耗时会比较长。如果打洞成功,下次建立新的连接时,将不需要再次打洞,会很快完成连接建立,不会触发 fallback。需要注意根据访问端和被访问端的延迟情况来合理设置超时时间,以避免超时时间太短,即使打洞成功连接也来不及建立,而一直触发 fallback。stcp-visitor 的 bindPort 设置为 -1 表示不需要监听物理端口,只接受 fallback 的连接即可。

TCPMUX

frp 支持将单个端口收到的连接路由到不同的代理,类似 vhostHTTPPort 和 vhostHTTPSPort。目前支持的复用器只有 httpconnect。当在 frps.toml 中设置 tcpmuxHTTPConnectPort,frps 将会监听在这个端口,接收 HTTP CONNECT 请求。frps 会根据 HTTP CONNECT 请求中的 host 路由到不同的后端代理。示例配置如下:

# frps.toml
        bindPort = 7000
        tcpmuxHTTPConnectPort = 1337

# frpc.toml
        serverAddr = "x.x.x.x"
        serverPort = 7000
        
        [[proxies]]
        name = "proxy1"
        type = "tcpmux"
        multiplexer = "httpconnect"
        customDomains = ["test1"]
        localPort = 80
        
        [[proxies]]
        name = "proxy2"
        type = "tcpmux"
        multiplexer = "httpconnect"
        customDomains = ["test2"]
        localPort = 8080

上面的配置,frps 如果收到 HTTP CONNECT 请求内容:CONNECT test1 HTTP/1.1\r\n\r\n 该连接将会被路由到 proxy1 。

HTTP & HTTPS

HTTP 和 HTTPS 是 frp 中针对这两种协议额外提供了一些特殊的能力。本质上目前这两种应用层协议的底层协议都是 TCP。如果不需要用到相关的特殊功能,可以直接使用 TCP 类型的代理,更加简单方便。HTTP 和 HTTPS 协议的一个特点是发送的请求都具有 Host 字段,通过该字段描述要访问的服务。基于这个特点,frp 服务端只需要监听在一个端口(通过 vhostHTTPPort 和 vhostHTTPSPort 指定)。就可以根据请求的 Host 来决定需要路由给哪一个代理,而不需要像

修改 Host Header。通常情况下 frp 不会修改转发的任何数据。但有一些后端服务会根据 HTTP 请求 header 中的 Host 字段来展现不同的网站,例如 nginx 的虚拟主机服务,启用 Host Header 的修改功能可以动态修改 HTTP 请求中的 Host 字段。需要注意的是,该功能仅限于 HTTP 类型的代理。示例:原来 HTTP 请求中的 Host 字段 test.yourdomain.com 转发到后端服务时会被替换为 dev.yourdomain.com

# frpc.toml
[[proxies]]
name = "web"
type = "http"
localPort = 80
customDomains = ["test.yourdomain.com"]
hostHeaderRewrite = "dev.yourdomain.com"

设置普通 Header。对于类型为 HTTP 的代理,可以设置在转发中动态添加的 Header 参数。示例:会在请求的 Header 中加上 x-from-where: frp。

# frpc.toml
[[proxies]]
name = "web"
type = "http"
localPort = 80
customDomains = ["test.yourdomain.com"]
hostHeaderRewrite = "dev.yourdomain.com"
requestHeaders.set.x-from-where = "frp"

设置 BasicAuth 鉴权。由于所有客户端共用一个 frps 的 HTTP 服务端口,任何知道你的域名和 URL 的人都能访问到你部署在内网的服务,但是在某些场景下需要确保只有限定的用户才能访问。frp 支持通过 HTTP Basic Auth 来保护你的 web 服务,使用户需要通过用户名和密码才能访问到你的服务。该功能目前仅限于 HTTP 类型的代理,需要在 frpc 的代理配置中添加用户名和密码的设置。

# frpc.toml
[[proxies]]
name = "web"
type = "http"
localPort = 80
customDomains = ["test.yourdomain.com"]
httpUser = "abc"
httpPassword = "abc"
通过浏览器访问 http://test.yourdomain.com,需要输入配置的用户名和密码才能访问。

自定义二级域名。在多人同时使用一个 frps 时,通过自定义二级域名的方式来使用会更加方便。通过在 frps 的配置文件中配置 subdomainHost,就可以启用该特性。之后在 frpc 的 http、https 类型的代理中可以不配置 customDomains,而是配置一个 subdomain 参数。只需要将 *.{subdomainHost} 解析到 frps 所在服务器。之后用户可以通过 subdomain 自行指定自己的 web 服务所需要使用的二级域名,通过 {subdomain}.{subdomainHost} 来访问自己的 web 服务。

# frps.toml
        subdomainHost = "frps.com"
        #将泛域名*.frps.com解析到 frps 所在服务器的 IP 地址。

# frpc.toml
        [[proxies]]
        name = "web"
        type = "http"
        localPort = 80
        subdomain = "test"

frps 和 frpc 都启动成功后,通过 test.frps.com 就可以访问到内网的 web 服务。注:如果 frps 配置了 subdomainHost,则 customDomains 中不能是属于 subdomainHost 的子域名或者泛域名。同一个 HTTP 或 HTTPS 类型的代理中 customDomains 和 subdomain 可以同时配置。

URL 路由。frp 支持根据请求的 URL 路径路由转发到不同的后端服务。通过配置文件中的 locations 字段指定一个或多个 proxy 能够匹配的 URL 前缀(目前仅支持最大前缀匹配,之后会考虑正则匹配)。例如指定 locations = "/news",则所有 URL 以 /news 开头的请求都会被转发到这个服务。

# frpc.toml
[[proxies]]
name = "web01"
type = "http"
localPort = 80
customDomains = ["web.yourdomain.com"]
locations = ["/"]

[[proxies]]
name = "web02"
type = "http"
localPort = 81
customDomains = ["web.yourdomain.com"]
locations = ["/news", "/about"]

配置后,web.yourdomain.com 这个域名下所有以 /news 以及 /about 作为前缀的 URL 请求都会被转发到 web02,其余的请求会被转发到 web01。

配置  示例

想要配置 frp 穿透,必须要有一台具有外网 ip 的服务器。如果没有,下面的就不用看了。

  • 1:服务器端 (外网服务器) 的配置;服务端通常部署在具有公网 IP 的机器上
  • 2:客户端 (内网服务器) 配置。客户端通常部署在需要穿透的内网服务所在的机器上

frps 配置 连接池

默认情况下,当用户请求建立连接后,FRP服务端才会请求FRP客户端主动与后端服务建立一个连接。当为指定的FRP服务端启用连接池功能后,FRP会预先和后端服务建立起指定数量的连接,每次接收到用户请求后,会从连接池中取出一个连接和用户连接关联起来,避免了等待与后端服务建立连接以及FRP客户端 和FRP服务端之间传递控制信息的时间。

首先需要在FRP服务端配置文件中设置每个代理可以创建的连接池上限,避免大量资源占用,客户端设置超过此配置后会被调整到当前值:transport.maxPoolCount = 5

frpc 加密与压缩

如果公司内网防火墙对外网访问进行了流量识别与屏蔽,例如禁止了SSH协议等,可通过设置将FRP客户端与FRP服务端之间的通信内容加密传输,将会有效防止流量被拦截。如果传输的报文长度较长,通过设置对传输内容进行压缩,可以有效减小FRP客户端 与FRP服务端之间的网络流量,来加快流量转发速度,但是会额外消耗一些 CPU 资源。这两个功能默认是不开启的,

frpc.toml

# 如果是 true, 这个代理的流量会被加密, 默认 false
transport.useEncryption = false
# 如果是 true, 流量会被压缩
transport.useCompression = false

访问内网 ssh

就是通过外网的 SSH 来访问内网机器

https://gofrp.org/zh-cn/docs/examples/ssh/

通过简单配置 TCP 类型的代理,使用户能够访问内网服务器。

ssh / http 端口复用

https://gofrp.org/zh-cn/docs/examples/multiple-ssh-over-same-port/

通过使用 tcpmux 类型的代理,您可以实现多个 SSH 服务通过同一端口进行暴露。这种方法还适用于任何支持 HTTP Connect 代理连接方式的客户端,以实现端口的复用。

代理内网机器 访问外网

FRP 客户端内置了http_proxy和socks5插件,通过这两个插件可以使其它内网机器通过FPR客户端的的网络访问互联网。要启用此功能,首先需要在FRP客户端配置文件中启用相关插件,这里以http_proxy 插件为例:编辑 frpc.toml

[[proxies]]
name = "plugin_http_proxy"
type = "tcp"
remotePort = 6004
[proxies.plugin]
type = "http_proxy"
httpUser = "abc"
httpPassword = "abc"

http_proxy 插件也支持认证机制。如需启用Socks5代理,只需将 plugin 的值更换为 socks5 即可。

[[proxies]]
name = "plugin_socks5"
type = "tcp"
remotePort = 6005
[proxies.plugin]
type = "socks5"
username = "abc"
password = "abc"

访问内网 Web 服务

访问内网 Web 服务,又叫 http穿透,是为了更方便的访问内网的web服务

https://gofrp.org/zh-cn/docs/examples/vhost-http/

通过简单配置 HTTP 类型的代理,您可以让用户通过自定义域名访问内网的 Web 服务。

# 设置通过密码访问 内网web服务

frpc.toml
[[proxies]]
type = http
local_port = 80
custom_domains = xxx.com
# 设置认证的用户名
http_user = abc
# 设置认证的密码
http_pwd = abc

HTTP穿透:服务端配置

[common]
bind_port = 7000
vhost_http_port = 80    # 将服务器的 80 端口用作 http 协议的通信
vhost_https_port = 443  # 进服务器的 443 端口用作 https 协议通信
privilege_token = token123456789  # frp的认证,对应的客户也需要配置一样,才可以进行通信

HTTP穿透:客户端配置

[common]
server_addr = 云服务器ip
server_port = 7000
privilege_token = token123456789 #frp的认证

[web_http]
type=http #通信类型为http
local_ip = 127.0.0.1
local_port = 8080
custom_domains = 二级域名/公网ip

[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 6000

type = http : 这个是因为我们想要创建的隧道是进行 http 通信的,也就是用来访问本地 web 应用;custom_domains = 二级域名/公网ip :这个配置一般使用一个二级域名来配置,用于通过域名来访问你的穿透服务器,如果没有域名,那么我们写上一个服务器的公网 ip 也是可以的,用 ip 的话,在外网访问的时候,就只能通过 ip 进行访问了,效果都一样;

frpc 通过代理 连接 frps

在只能通过代理访问外网的环境内,FRP客户端支持通过HTTP_PROXY参数来配置代理和FRP服务端进行通信。要使用此功能可以通过设置系统环境变量HTTP_PROXY或者通过在FRP客户端的配置文件中设置http_proxy参数来使用此功能。

# 编辑 frpctoml

# 仅在tcp协议时生效
# transport.proxyURL = "http://user:passwd@192.168.1.128:8080"
# transport.proxyURL = "socks5://user:passwd@192.168.1.128:1080"
# transport.proxyURL = "ntlm://user:passwd@192.168.1.128:2080"

转发 DNS 查询请求

https://gofrp.org/zh-cn/docs/examples/dns/

本示例演示如何通过简单配置 UDP 类型的代理来实现 DNS 查询请求的转发。

转发 Unix 域套接字

https://gofrp.org/zh-cn/docs/examples/unix-domain-socket/

通过配置 Unix 域套接字客户端插件,您可以使用 TCP 端口访问内网的 Unix 域套接字服务,例如 Docker Daemon。

访问内网 文件访问服务

https://gofrp.org/zh-cn/docs/examples/static-file/

通过配置 static_file 客户端插件,您可以将本地文件暴露在公网上,以供其他人访问。

内网电脑开启文件服务,让外网电脑访问

[my_static_file]
type = tcp
remote_port = 6001
plugin = static_file
plugin_local_path = E:\\temp
plugin_strip_prefix = static
plugin_http_user = abc
plugin_http_passwd = 123

​plugin 是需要用到的插件
plugin_local_path 是要对外暴露的文件目录
plugin_strip_prefix 访问url携带的前缀
plugin_http_user 访问账号
plugin_http_passwd 访问密码
在 公司电脑 的浏览器输入:http://1.1.1.1:6001/static/
输入账号密码就可查看家里电脑分享的文件,其中1.1.1.1是腾讯云服务器对外的IP

内网 HTTP 转 HTTPS

https://gofrp.org/zh-cn/docs/examples/https2http/

使用 https2http 插件将本地 HTTP 服务转换为 HTTPS 服务,以供外部访问。

安全地暴露内网服务

https://gofrp.org/zh-cn/docs/examples/stcp/

通过创建一个只有授权用户能够访问的 SSH 服务代理,实现内网服务的安全暴露。

p2p (点对点) 内网穿透

https://gofrp.org/zh-cn/docs/examples/xtcp/

这个示例将演示如何通过点对点 (P2P) 连接来访问内网服务,流量不会通过服务器中转。

访问内网 Unix 套接字

通过TCP端口访问内网的Unix域套接字,这里以和本地机器上的 Docker Daemon 通信为例。

主要是使用plugin和plugin_unix_path两个参数

[[proxies]]
type = tcp
remote_port = 6002
plugin = unix_domain_socket
plugin_unix_path = /var/run/docker.sock

测试:curl http://110.110.110.110:6002/version

服务端 配置 (linux 为例)

下载地址:https://github.com/fatedier/frp/releases

下载好后上传到服务器上:scp xxxxx.tar.gz 用户名@服务端ip:~/
或者在服务器上直接下载:mwget 或者 wget 

解压 frp 压缩包:tar -zxvf  xxxxx.tar.gz 

  • frpc  frpc.toml  :frpc 开头的代表着 客户端 使用。.toml  是配置文件
  • frps  frps.toml:frps 开头的代表 服务端 使用。.toml  是配置文件

frps_full_example.toml

# This configuration file is for reference only. Please do not use this configuration directly to run the program as it may have various issues.

# A literal address or host name for IPv6 must be enclosed
# in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"
# For single "bindAddr" field, no need square brackets, like `bindAddr = "::"`.
bindAddr = "0.0.0.0"
bindPort = 7000

# udp port used for kcp protocol, it can be same with 'bindPort'.
# if not set, kcp is disabled in frps.
kcpBindPort = 7000

# udp port used for quic protocol.
# if not set, quic is disabled in frps.
# quicBindPort = 7002

# Specify which address proxy will listen for, default value is same with bindAddr
# proxyBindAddr = "127.0.0.1"

# quic protocol options
# transport.quic.keepalivePeriod = 10
# transport.quic.maxIdleTimeout = 30
# transport.quic.maxIncomingStreams = 100000

# Heartbeat configure, it's not recommended to modify the default value
# The default value of heartbeatTimeout is 90. Set negative value to disable it.
# transport.heartbeatTimeout = 90

# Pool count in each proxy will keep no more than maxPoolCount.
transport.maxPoolCount = 5

# If tcp stream multiplexing is used, default is true
# transport.tcpMux = true

# Specify keep alive interval for tcp mux.
# only valid if tcpMux is true.
# transport.tcpMuxKeepaliveInterval = 60

# tcpKeepalive specifies the interval between keep-alive probes for an active network connection between frpc and frps.
# If negative, keep-alive probes are disabled.
# transport.tcpKeepalive = 7200

# transport.tls.force specifies whether to only accept TLS-encrypted connections. By default, the value is false.
transport.tls.force = false

# transport.tls.certFile = "server.crt"
# transport.tls.keyFile = "server.key"
# transport.tls.trustedCaFile = "ca.crt"

# If you want to support virtual host, you must set the http port for listening (optional)
# Note: http port and https port can be same with bindPort
vhostHTTPPort = 80
vhostHTTPSPort = 443

# Response header timeout(seconds) for vhost http server, default is 60s
# vhostHTTPTimeout = 60

# tcpmuxHTTPConnectPort specifies the port that the server listens for TCP
# HTTP CONNECT requests. If the value is 0, the server will not multiplex TCP
# requests on one single port. If it's not - it will listen on this value for
# HTTP CONNECT requests. By default, this value is 0.
# tcpmuxHTTPConnectPort = 1337

# If tcpmuxPassthrough is true, frps won't do any update on traffic.
# tcpmuxPassthrough = false

# Configure the web server to enable the dashboard for frps.
# dashboard is available only if webServer.port is set.
webServer.addr = "127.0.0.1"
webServer.port = 7500
webServer.user = "admin"
webServer.password = "admin"
# webServer.tls.certFile = "server.crt"
# webServer.tls.keyFile = "server.key"
# dashboard assets directory(only for debug mode)
# webServer.assetsDir = "./static"

# Enable golang pprof handlers in dashboard listener.
# Dashboard port must be set first
webServer.pprofEnable = false

# enablePrometheus will export prometheus metrics on webServer in /metrics api.
enablePrometheus = true

# console or real logFile path like ./frps.log
log.to = "./frps.log"
# trace, debug, info, warn, error
log.level = "info"
log.maxDays = 3
# disable log colors when log.to is console, default is false
log.disablePrintColor = false

# DetailedErrorsToClient defines whether to send the specific error (with debug info) to frpc. By default, this value is true.
detailedErrorsToClient = true

# auth.method specifies what authentication method to use authenticate frpc with frps.
# If "token" is specified - token will be read into login message.
# If "oidc" is specified - OIDC (Open ID Connect) token will be issued using OIDC settings. By default, this value is "token".
auth.method = "token"

# auth.additionalScopes specifies additional scopes to include authentication information.
# Optional values are HeartBeats, NewWorkConns.
# auth.additionalScopes = ["HeartBeats", "NewWorkConns"]

# auth token
auth.token = "12345678"

# oidc issuer specifies the issuer to verify OIDC tokens with.
auth.oidc.issuer = ""
# oidc audience specifies the audience OIDC tokens should contain when validated.
auth.oidc.audience = ""
# oidc skipExpiryCheck specifies whether to skip checking if the OIDC token is expired.
auth.oidc.skipExpiryCheck = false
# oidc skipIssuerCheck specifies whether to skip checking if the OIDC token's issuer claim matches the issuer specified in OidcIssuer.
auth.oidc.skipIssuerCheck = false

# userConnTimeout specifies the maximum time to wait for a work connection.
# userConnTimeout = 10

# Only allow frpc to bind ports you list. By default, there won't be any limit.
allowPorts = [
  { start = 2000, end = 3000 },
  { single = 3001 },
  { single = 3003 },
  { start = 4000, end = 50000 }
]

# Max ports can be used for each client, default value is 0 means no limit
maxPortsPerClient = 0

# If subDomainHost is not empty, you can set subdomain when type is http or https in frpc's configure file
# When subdomain is test, the host used by routing is test.frps.com
subDomainHost = "frps.com"

# custom 404 page for HTTP requests
# custom404Page = "/path/to/404.html"

# specify udp packet size, unit is byte. If not set, the default value is 1500.
# This parameter should be same between client and server.
# It affects the udp and sudp proxy.
udpPacketSize = 1500

# Retention time for NAT hole punching strategy data.
natholeAnalysisDataReserveHours = 168

# ssh tunnel gateway
# If you want to enable this feature, the bindPort parameter is required, while others are optional.
# By default, this feature is disabled. It will be enabled if bindPort is greater than 0.
# sshTunnelGateway.bindPort = 2200
# sshTunnelGateway.privateKeyFile = "/home/frp-user/.ssh/id_rsa"
# sshTunnelGateway.autoGenPrivateKeyPath = ""
# sshTunnelGateway.authorizedKeysFile = "/home/frp-user/.ssh/authorized_keys"

[[httpPlugins]]
name = "user-manager"
addr = "127.0.0.1:9000"
path = "/handler"
ops = ["Login"]

[[httpPlugins]]
name = "port-manager"
addr = "127.0.0.1:9001"
path = "/handler"
ops = ["NewProxy"]

启动 frp 服务

可以把 frp 加入到 systemd 服务中,使用 systemd 进行管理。
sudo systemctl enable frps
sudo systemctl start frps

防火墙开放端口

防火墙要放行设置的端口。

如果是 ubuntu 或者 centos 6,请使用 ufw / iptables 工具放行端口;

7000 和 7500 两个端口分别对应 frps.ini 配置中的 bind_port 和 dashboard_port

客户端内网服务器 ) 配置

把 frpc 开头的文件复制到内网服务器上( 就是要把内网端口暴露给外网的访问的服务器上 ),

frpc_full_example.toml

# This configuration file is for reference only. Please do not use this configuration directly to run the program as it may have various issues.

# your proxy name will be changed to {user}.{proxy}
user = "your_name"

# A literal address or host name for IPv6 must be enclosed
# in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"
# For single serverAddr field, no need square brackets, like serverAddr = "::".
serverAddr = "0.0.0.0"
serverPort = 7000

# STUN server to help penetrate NAT hole.
# natHoleStunServer = "stun.easyvoip.com:3478"

# Decide if exit program when first login failed, otherwise continuous relogin to frps
# default is true
loginFailExit = true

# console or real logFile path like ./frpc.log
log.to = "./frpc.log"
# trace, debug, info, warn, error
log.level = "info"
log.maxDays = 3
# disable log colors when log.to is console, default is false
log.disablePrintColor = false

auth.method = "token"
# auth.additionalScopes specifies additional scopes to include authentication information.
# Optional values are HeartBeats, NewWorkConns.
# auth.additionalScopes = ["HeartBeats", "NewWorkConns"]

# auth token
auth.token = "12345678"

# oidc.clientID specifies the client ID to use to get a token in OIDC authentication.
# auth.oidc.clientID = ""
# oidc.clientSecret specifies the client secret to use to get a token in OIDC authentication.
# auth.oidc.clientSecret = ""
# oidc.audience specifies the audience of the token in OIDC authentication.
# auth.oidc.audience = ""
# oidc.scope specifies the permissions of the token in OIDC authentication if AuthenticationMethod == "oidc". By default, this value is "".
# auth.oidc.scope = ""
# oidc.tokenEndpointURL specifies the URL which implements OIDC Token Endpoint.
# It will be used to get an OIDC token.
# auth.oidc.tokenEndpointURL = ""

# oidc.additionalEndpointParams specifies additional parameters to be sent to the OIDC Token Endpoint.
# For example, if you want to specify the "audience" parameter, you can set as follow.
# frp will add "audience=<value>" "var1=<value>" to the additional parameters.
# auth.oidc.additionalEndpointParams.audience = "https://dev.auth.com/api/v2/"
# auth.oidc.additionalEndpointParams.var1 = "foobar"

# Set admin address for control frpc's action by http api such as reload
webServer.addr = "127.0.0.1"
webServer.port = 7400
webServer.user = "admin"
webServer.password = "admin"
# Admin assets directory. By default, these assets are bundled with frpc.
# webServer.assetsDir = "./static"

# Enable golang pprof handlers in admin listener.
webServer.pprofEnable = false

# The maximum amount of time a dial to server will wait for a connect to complete. Default value is 10 seconds.
# transport.dialServerTimeout = 10

# dialServerKeepalive specifies the interval between keep-alive probes for an active network connection between frpc and frps.
# If negative, keep-alive probes are disabled.
# transport.dialServerKeepalive = 7200

# connections will be established in advance, default value is zero
transport.poolCount = 5

# If tcp stream multiplexing is used, default is true, it must be same with frps
# transport.tcpMux = true

# Specify keep alive interval for tcp mux.
# only valid if tcpMux is enabled.
# transport.tcpMuxKeepaliveInterval = 60

# Communication protocol used to connect to server
# supports tcp, kcp, quic, websocket and wss now, default is tcp
transport.protocol = "tcp"

# set client binding ip when connect server, default is empty.
# only when protocol = tcp or websocket, the value will be used.
transport.connectServerLocalIP = "0.0.0.0"

# if you want to connect frps by http proxy or socks5 proxy or ntlm proxy, you can set proxyURL here or in global environment variables
# it only works when protocol is tcp
# transport.proxyURL = "http://user:passwd@192.168.1.128:8080"
# transport.proxyURL = "socks5://user:passwd@192.168.1.128:1080"
# transport.proxyURL = "ntlm://user:passwd@192.168.1.128:2080"

# quic protocol options
# transport.quic.keepalivePeriod = 10
# transport.quic.maxIdleTimeout = 30
# transport.quic.maxIncomingStreams = 100000

# If tls.enable is true, frpc will connect frps by tls.
# Since v0.50.0, the default value has been changed to true, and tls is enabled by default.
transport.tls.enable = true

# transport.tls.certFile = "client.crt"
# transport.tls.keyFile = "client.key"
# transport.tls.trustedCaFile = "ca.crt"
# transport.tls.serverName = "example.com"

# If the disableCustomTLSFirstByte is set to false, frpc will establish a connection with frps using the
# first custom byte when tls is enabled.
# Since v0.50.0, the default value has been changed to true, and the first custom byte is disabled by default.
# transport.tls.disableCustomTLSFirstByte = true

# Heartbeat configure, it's not recommended to modify the default value.
# The default value of heartbeatInterval is 10 and heartbeatTimeout is 90. Set negative value
# to disable it.
# transport.heartbeatInterval = 30
# transport.heartbeatTimeout = 90

# Specify a dns server, so frpc will use this instead of default one
# dnsServer = "8.8.8.8"

# Proxy names you want to start.
# Default is empty, means all proxies.
# start = ["ssh", "dns"]

# Specify udp packet size, unit is byte. If not set, the default value is 1500.
# This parameter should be same between client and server.
# It affects the udp and sudp proxy.
udpPacketSize = 1500

# Additional metadatas for client.
metadatas.var1 = "abc"
metadatas.var2 = "123"

# Include other config files for proxies.
# includes = ["./confd/*.ini"]

[[proxies]]
# 'ssh' is the unique proxy name
# If global user is not empty, it will be changed to {user}.{proxy} such as 'your_name.ssh'
name = "ssh"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22
# Limit bandwidth for this proxy, unit is KB and MB
transport.bandwidthLimit = "1MB"
# Where to limit bandwidth, can be 'client' or 'server', default is 'client'
transport.bandwidthLimitMode = "client"
# If true, traffic of this proxy will be encrypted, default is false
transport.useEncryption = false
# If true, traffic will be compressed
transport.useCompression = false
# Remote port listen by frps
remotePort = 6001
# frps will load balancing connections for proxies in same group
loadBalancer.group = "test_group"
# group should have same group key
loadBalancer.groupKey = "123456"
# Enable health check for the backend service, it supports 'tcp' and 'http' now.
# frpc will connect local service's port to detect it's healthy status
healthCheck.type = "tcp"
# Health check connection timeout
healthCheck.timeoutSeconds = 3
# If continuous failed in 3 times, the proxy will be removed from frps
healthCheck.maxFailed = 3
# Every 10 seconds will do a health check
healthCheck.intervalSeconds = 10
# Additional meta info for each proxy. It will be passed to the server-side plugin for use.
metadatas.var1 = "abc"
metadatas.var2 = "123"
# You can add some extra information to the proxy through annotations.
# These annotations will be displayed on the frps dashboard.
[proxies.annotations]
key1 = "value1"
"prefix/key2" = "value2"

[[proxies]]
name = "ssh_random"
type = "tcp"
localIP = "192.168.31.100"
localPort = 22
# If remotePort is 0, frps will assign a random port for you
remotePort = 0

[[proxies]]
name = "dns"
type = "udp"
localIP = "114.114.114.114"
localPort = 53
remotePort = 6002

# Resolve your domain names to [serverAddr] so you can use http://web01.yourdomain.com to browse web01 and http://web02.yourdomain.com to browse web02
[[proxies]]
name = "web01"
type = "http"
localIP = "127.0.0.1"
localPort = 80
# http username and password are safety certification for http protocol
# if not set, you can access this customDomains without certification
httpUser = "admin"
httpPassword = "admin"
# if domain for frps is frps.com, then you can access [web01] proxy by URL http://web01.frps.com
subdomain = "web01"
customDomains = ["web01.yourdomain.com"]
# locations is only available for http type
locations = ["/", "/pic"]
# route requests to this service if http basic auto user is abc
# routeByHTTPUser = abc
hostHeaderRewrite = "example.com"
requestHeaders.set.x-from-where = "frp"
healthCheck.type = "http"
# frpc will send a GET http request '/status' to local http service
# http service is alive when it return 2xx http response code
healthCheck.path = "/status"
healthCheck.intervalSeconds = 10
healthCheck.maxFailed = 3
healthCheck.timeoutSeconds = 3
# set health check headers
healthCheck.httpHeaders=[
    { name = "x-from-where", value = "frp" }
]

[[proxies]]
name = "web02"
type = "https"
localIP = "127.0.0.1"
localPort = 8000
subdomain = "web02"
customDomains = ["web02.yourdomain.com"]
# if not empty, frpc will use proxy protocol to transfer connection info to your local service
# v1 or v2 or empty
transport.proxyProtocolVersion = "v2"

[[proxies]]
name = "tcpmuxhttpconnect"
type = "tcpmux"
multiplexer = "httpconnect"
localIP = "127.0.0.1"
localPort = 10701
customDomains = ["tunnel1"]
# routeByHTTPUser = "user1"

[[proxies]]
name = "plugin_unix_domain_socket"
type = "tcp"
remotePort = 6003
# if plugin is defined, localIP and localPort is useless
# plugin will handle connections got from frps
[proxies.plugin]
type = "unix_domain_socket"
unixPath = "/var/run/docker.sock"

[[proxies]]
name = "plugin_http_proxy"
type = "tcp"
remotePort = 6004
[proxies.plugin]
type = "http_proxy"
httpUser = "abc"
httpPassword = "abc"

[[proxies]]
name = "plugin_socks5"
type = "tcp"
remotePort = 6005
[proxies.plugin]
type = "socks5"
username = "abc"
password = "abc"

[[proxies]]
name = "plugin_static_file"
type = "tcp"
remotePort = 6006
[proxies.plugin]
type = "static_file"
localPath = "/var/www/blog"
stripPrefix = "static"
httpUser = "abc"
httpPassword = "abc"

[[proxies]]
name = "plugin_https2http"
type = "https"
customDomains = ["test.yourdomain.com"]
[proxies.plugin]
type = "https2http"
localAddr = "127.0.0.1:80"
crtPath = "./server.crt"
keyPath = "./server.key"
hostHeaderRewrite = "127.0.0.1"
requestHeaders.set.x-from-where = "frp"

[[proxies]]
name = "plugin_https2https"
type = "https"
customDomains = ["test.yourdomain.com"]
[proxies.plugin]
type = "https2https"
localAddr = "127.0.0.1:443"
crtPath = "./server.crt"
keyPath = "./server.key"
hostHeaderRewrite = "127.0.0.1"
requestHeaders.set.x-from-where = "frp"

[[proxies]]
name = "plugin_http2https"
type = "http"
customDomains = ["test.yourdomain.com"]
[proxies.plugin]
type = "http2https"
localAddr = "127.0.0.1:443"
hostHeaderRewrite = "127.0.0.1"
requestHeaders.set.x-from-where = "frp"

[[proxies]]
name = "secret_tcp"
# If the type is secret tcp, remotePort is useless
# Who want to connect local port should deploy another frpc with stcp proxy and role is visitor
type = "stcp"
# secretKey is used for authentication for visitors
secretKey = "abcdefg"
localIP = "127.0.0.1"
localPort = 22
# If not empty, only visitors from specified users can connect.
# Otherwise, visitors from same user can connect. '*' means allow all users.
allowUsers = ["*"]

[[proxies]]
name = "p2p_tcp"
type = "xtcp"
secretKey = "abcdefg"
localIP = "127.0.0.1"
localPort = 22
# If not empty, only visitors from specified users can connect.
# Otherwise, visitors from same user can connect. '*' means allow all users.
allowUsers = ["user1", "user2"]

# frpc role visitor -> frps -> frpc role server
[[visitors]]
name = "secret_tcp_visitor"
type = "stcp"
# the server name you want to visitor
serverName = "secret_tcp"
secretKey = "abcdefg"
# connect this address to visitor stcp server
bindAddr = "127.0.0.1"
# bindPort can be less than 0, it means don't bind to the port and only receive connections redirected from
# other visitors. (This is not supported for SUDP now)
bindPort = 9000

[[visitors]]
name = "p2p_tcp_visitor"
type = "xtcp"
# if the server user is not set, it defaults to the current user
serverUser = "user1"
serverName = "p2p_tcp"
secretKey = "abcdefg"
bindAddr = "127.0.0.1"
# bindPort can be less than 0, it means don't bind to the port and only receive connections redirected from
# other visitors. (This is not supported for SUDP now)
bindPort = 9001
# when automatic tunnel persistence is required, set it to true
keepTunnelOpen = false
# effective when keepTunnelOpen is set to true, the number of attempts to punch through per hour
maxRetriesAnHour = 8
minRetryInterval = 90
# fallbackTo = "stcp_visitor"
# fallbackTimeoutMs = 500

验证服务端是否启动成功

访问:http://服务器IP:后台管理端口 ,输入 用户名、密码 可以查看连接状态。如:http://62.244.114.4:7500/,用户名和密码分别对应 frps.ini 文件中的 dashboard_user 和dashboard_pwd 登录之后界面如下:

注意:[ssh] 这样的名称必须全局唯一,即就算有多个客户端,也只能使用一次,其他的可以用[ssh2]、[ssh3] 等;意思就是说,如果你要配置多个客户端,必须将另外的客户端的 [ssh] 改为[ssh2]、[ssh3] 等,并且 remote_port 也要变,比如 6002,6003 等

防火墙开放端口

sudo firewall-cmd --permanent --add-port=6000/tcp
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload

启动客户端:./frpc -c frpc.toml

3、内网穿透利器 --- Termite

​官网:https://rootkiter.com/Termite/
官网说明:http://rootkiter.com/Termite/README.txt
github:https://github.com/rootkiter/Binary-files​

下载地址:https://github.com/ph-cwtcwt/IT-tool/tree/termite

Termite 是一款内网穿透利器,分为管理端 admin 和代理端 agent。它支持多平台、跳板机间正反向级联、内置 shell 管理等。

管理端 (Admin) 功能参数

代理端 (Agent) 功能参数

Admin 连接 agent 后的功能参数

不同场景中的使用

1、目标在公网

使用:
(1)目标A:agent_win32.exe -l 8888
(2)PC:admin_win32.exe -c 目标ip -p 8888

2、目标在内网(能出网)

使用:
(1)在vps运行:agent_win32.exe -l 8888
(2)在自己机器运行:admin_win32.exe -c vps_ip -p 8888
(3)在目标机器运行:agent_win32.exe -c vps_ip -p 8888

3、目标B在内网(不出网,通出网机器A)

(1)agent 间正向连接

使用:
a.在 vps 运行:agent_win32.exe -l 8888
b.在 PC 运行:admin_win32.exe -c vps_ip -p 8888
c.在出网机器 A 运行:agent_win32.exe -c vps_ip -p 8888
d.在目标 B运行:agent_win32.exe -l 9000
e.在 PC 运行:goto A_id → connect B_ip 9000

(2)agent 间反向连接

说明:
a.在vps运行:agent_win32.exe -l 8888
b.在PC运行:admin_win32.exe -c vps_ip -p 8888
c.在出网机器A运行:agent_win32.exe -c vps_ip -p 8888
d.在PC运行:goto A_id -> listen 9000
e.在目标B运行:agent_win32.exe -c A_ip -p 9000

常用功能

socks 代理

(1)goto 对应id
(2)socks 1080

shell 管理

(1)shell 4444
(2)nc -v 127.0.0.1 4444

端口转发

lcxtran 本地端口 目标ip 目标端口

上传下载文件

upfile 本地文件路径 目标路径
downfile 目标文件路径 本地存放路径

4、免费 的 内网穿透

飞鸽内网穿透

官网:https://www.fgnwct.com/
免费版:速度 0.5Mbps、20 并发连接、免费域名、可自定义域名、2个TCP/UDP端口号、无限流量、每日签到可叠加时长

nps

nps 是一款轻量级、高性能、功能强大的 内网穿透代理服务器。目前支持 tcp、udp 流量转发,可支持任何 tcp、udp 上层协议( 访问内网网站、本地支付接口调试、ssh访问、远程桌面,内网dns解析等等……),此外还 支持内网http代理、内网socks5代理p2p等并带有功能强大的 we b管理端。

github:https://github.com/ehang-io/nps/blob/master/README_zh.md

神卓互联内网穿透

神卓互联内网穿透就属于企业级的映射工具。
神卓互联内网穿:https://blog.csdn.net/qq_45392321/article/details/109017481

Sakura Frp ( 樱花 frp )

官网:https://www.natfrp.com/
免费用户:隧道限速10 Mibps、隧道数量2 条、每月流量5G。

Sunny-Ngrok

官网地址:https://www.ngrok.cc/
文档:https://www.ngrok.cc/_book/

ngrok内网穿透:https://zhuanlan.zhihu.com/p/664601185

ngrok 有国内的版本,叫 Sunny-Ngrok,首先在 https://www.ngrok.cc/ 注册成会员。

关于 Sunny-Ngrok

  • 提供免费内网穿透服务,免费服务器支持绑定自定义域名
  • 管理内网服务器,内网web进行演示
  • 快速开发微信程序和第三方支付平台调试
  • 本地WEB外网访问、本地开发微信、TCP端口转发
  • 本站新增FRP服务器,基于 FRP 实现https、udp转发
  • 无需任何配置,下载客户端之后直接一条命令让外网访问您的内网

n2n

github:https://github.com/ntop/n2n

n2n 内网穿透:https://blog.csdn.net/a478555/article/details/89501904

蜻蜓映射

官网地址:https://flynat.51miaole.com/
免费的内网穿透软件。适用于远程桌面、远程服务器、远程办公、游戏联机、开发调试等场景。

NATAPP

官网:https://natapp.cn/
免费版:提供http,tcp,udp全隧道穿透、随机域名/随机TCP,UDP端口、不定时强制更换域名/端口、自定义本地端口

花生壳 

官网:https://hsk.oray.com/
客户端下载:https://hsk.oray.com/download
不想付费,又想用大于两个映射,那么花生壳 + NATAPP 也许是一个不错的选择。
优点:赠送一个域名、免费两个映射、每月免费 1G 流量

  • 3
    点赞
  • 81
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值