使用场景

1.微信开发
2.在家需连接公司内网(注意公司的网络规范)

之前用过 ngrok ,但去国外转了一圈还是慢了些,和运维探讨了一下,他是用什么来做内网穿透的,了解到 frp。

frp 官方说明

1.利用处于内网或防火墙后的机器,对外网环境提供 http 或 https 服务;
2.对于 http, https 服务支持基于域名的虚拟主机,支持自定义域名绑定,使多个域名可以共用一个80端口;
3.利用处于内网或防火墙后的机器,对外网环境提供 tcp 和 udp 服务,例如在家里通过 ssh 访问处于公司内网环境内的主机。

配置步骤

1.从 Release 页面下载最新版本的程序 (https://github.com/fatedier/frp/releases)

2.将 frps 及 frps.ini 放到具有公网 IP 的机器上, 并使用 screen 让 frp 在后台运行:
screen -dmS frp
./frps -c ./frps.ini
(要进入这个会话: screen -r frp)

3.将 frpc 及 frpc.ini 放到处于内网环境的机器上, 并使用 screen 让 frp 在后台运行:
screen -dmS frp
./frpc -c ./frpc.ini
(要进入这个会话: screen -r frp)

配置示例

服务端(有固定外网IP的一端)使用 frps.ini

[common]
bind_port = 5000

客户端(内网服务器,没有固定IP的)使用 frpc.ini

[common]
server_addr = xxx.xxx.xxx.xxx
server_port = 5000

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

[mysql]
type = tcp
local_ip = 192.168.44.10
local_port = 3306
remote_port = 1006

[web]
type = http
local_port = 80
custom_domains = www.yourdomain.com

根据以上配置示例, 做如下解释:
1.[ssh] 解释: 通过公网 ip:xxx.xxx.xxx.xxx 机器代理,进入内网机器
ssh root@xxx.xxx.xxx.xxx -p 2222

2.[mysql] 解释: 通过公网 ip:xxx.xxx.xxx.xxx 机器代理,进入内网机器 MySQL
mysql -h xxx.xxx.xxx.xxx -uroot -P 1006 -proot

frp github

https://github.com/fatedier/frp/blob/master/README_zh.md