1、FRP介绍
frp 是一个专注于内网穿透的高性能的反向代理应用,支持 TCP、UDP、HTTP、HTTPS 等多种协议。可以将内网服务以安全、便捷的方式通过具有公网 IP 节点的中转暴露到公网。
- 官网:https://gofrp.org
- Github:https://github.com/fatedier/frp/releases
- 中文文档:https://gofrp.org/docs/overview/
解压缩下载的压缩包,将其中的 frpc 拷贝到内网服务所在的机器上,将 frps 拷贝到具有公网 IP 的机器上,放置在任意目录。然后修改配置文件即可使用
2、FRP的使用
2.1 通过SSH访问内网机器
2.1.1 服务端
配置
[common]
bind_port = 7000 # 客户端通信端口
启动
./frps -c ./frps.ini # 临时
nohup ./frps -c ./frps.ini & # 后台
2.1.2 客户端
配置
[common]
server_addr = x.x.x.x
server_port = 7000
[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 6000
local_ip
配置为本地需要暴露到公网的服务地址。
local_port
配置为本地需要暴露到公网的服务端口。
remote_port
表示在 frp 服务端监听的端口,访问此端口的流量将会被转发到本地服务对应的端口。
启动
./frpc -c ./frpc.ini # 临时
nohup ./frpc -c ./frpc.ini & # 后台
2.1.3 使用
ssh -oPort=6000 test@x.x.x.x
frp 会将请求 x.x.x.x:6000 的流量转发到内网机器的 22 端口
2.2 通过HTTP协议访问内网WEB服务
HTTP 类型的代理相比于 TCP 类型,不仅在服务端只需要监听一个额外的端口 vhost_http_port
用于接收 HTTP 请求,还额外提供了基于 HTTP 协议的诸多功能。
2.2.1 服务端配置
修改 frps.ini 文件,设置监听 HTTP 请求端口为 8080:
[common]
bind_port = 7000
vhost_http_port = 8080
2.2.2 客户端配置
修改 frpc.ini 文件,假设 frps 所在的服务器的 IP 为 x.x.x.x,local_port
为本地机器上 Web 服务监听的端口, 绑定自定义域名为 custom_domains
。
[common]
server_addr = x.x.x.x
server_port = 7000
[web]
type = http
local_port = 80
custom_domains = www.yourdomain.com
[web2]
type = http
local_port = 8080
custom_domains = www.yourdomain2.com
2.2.3 使用
- 分别启动 frps 和 frpc。
- 将
www.yourdomain.com
和www.yourdomain2.com
的域名 A 记录解析到 IPx.x.x.x
,如果服务器已经有对应的域名,也可以将 CNAME 记录解析到服务器原先的域名。或者可以通过修改 HTTP 请求的 Host 字段来实现同样的效果。 - 通过浏览器访问
http://www.yourdomain.com:8080
即可访问到处于内网机器上 80 端口的服务,访问http://www.yourdomain2.com:8080
则访问到内网机器上 8080 端口的服务。
2.3 通过socks5搭建隧道
2.3.1 服务端配置
修改frps.ini配置文件
[common]
bind_port = 7000
bind_port:绑定的端口
2.3.2 客户端配置
修改frpc.ini配置文件
[common]
server_addr = x.x.x.x
server_port = 7000
[test]
remote_port = 10000 #代理的端口
plugin = socks5 #使用的协议
use_encryption = true #是否加密
use_compression = true
- remote_port: 代理的端口
- plugin: 使用的协议
- use_encryption: 是否加密
- plugin_user= admin #socks5用户名
- plugin_passwd= admin #socks5密码
2.3.3 使用
然后可以本机设置代理: socks5 xxx.xxx.xxx.xxx(VPS) 10000,即可访问内网系统
可以利用命令如下命令来测试sockets代理搭建的是否成功
curl --socks5 x.x.x.x:10000 http://www.baidu.com
另外可以在SwitchyOmega中配置sockets5代理可以实现2.2的功能
3、sockets5+ssh 配置
3.1 服务端frps.ini
[common]
bind_addr = 0.0.0.0
bind_port = 17000
dashboard_addr = 0.0.0.0
dashboard_port = 27500
dashboard_user = root
dashboard_pwd = 123456
token = 1q2w3e
heartbeat_timeout = 90
bind_addr = 0.0.0.0 #绑定的ip
bind_port = 17000 #绑定的端口
dashboard_addr = 0.0.0.0 #管理地址
dashboard_port = 27500 #管理端口
dashboard_user = root #管理的用户名
dashboard_pwd = 123456 #管理用户的密码
token = 1q2w3e #客户端服务端连接的密码
heartbeat_timeout = 90 #心跳超时时间
3.2 客户端frpc.ini
[common]
server_addr = x.x.x.x
server_port = 17000
token = 1q2w3e
pool_count = 5
protocol = tcp
health_check_type = tcp
health_check_interval_s = 100
[test]
remote_port = 10000
plugin = socks5
use_encryption = true
use_compression = true
[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 6000