需要一台公网服务器

1 服务端

1.1 安装frp

下载地址:frp下载

选择对应的版本下载,在linux上可以执行如下命令下载

1
wget https://github.com/fatedier/frp/releases/download/v0.31.2/frp_0.31.2_linux_amd64.tar.gz

解压缩并进入frp目录

1
2
tar -zxvf  frp_0.31.2_linux_amd64.tar.gz
cd frp_0.31.2_linux_amd64

其中frpc是客户端文件,frps是服务端文件,可以将客户端的文件删除

1.2 配置frp

打开配置文件

1
vi frps.ini

修改以下内容

1
2
3
[common]
bind_port = 7000 #与客户端进行通信的端口
vhost_http_port = 8721 #外网访问内网客户端时使用的端口号

保存并退出

1.3 启动服务

前台启动

1
./frps -c ./frps.ini

后台启动

1
nohup ./frps -c ./frps.ini &

2 客户端

从上面的地址下载相应的版本,解压后打开frpc.ini配置文件并根据需要修改

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[common]
server_addr = 1.1.1.1 #公网服务器ip
server_port = 7000 #与服务端bind_port一致

#公网通过ssh访问内部服务器
[ssh]
type = tcp #连接协议
local_ip = 127.0.0.1 #内网服务器ip
local_port = 22 #内网ssh服务的端口号
remote_port = 6000 #自定义的访问内部ssh端口号

#公网访问内部web服务器以http方式
[web1]
type = http #访问协议
local_ip = 192.168.1.6 #内网web服务的ip
local_port = 80 #内网web服务的端口号
custom_domains = web1.test.com #所绑定的公网服务器域名

#公网访问内部web服务器以http方式
[web2]
type = http #访问协议
local_ip = 192.168.1.7 #内网web服务的ip
local_port = 8081 #内网web服务的端口号
custom_domains = web2.test.com #所绑定的公网服务器域名

保存后启动客户端

3 访问方式

根据以上配置,则访问映射规则如下

ssh服务

        服务器ip:6000 —> 内网127.0.0.1:22

Web服务

        web1.test.com:8721 —> 内网192.168.1.6:80

        web2.test.com:8721 —> 内网192.168.1.7:8081