(1). 概述

(2). 机器准备

ip 角色
47.113.186.199 frp server(外网)
172.30.50.20 frp client(内网)

(3). frp server安装

[root@frp-server ~]# wget https://github.com/fatedier/frp/releases/download/v0.39.1/frp_0.39.1_linux_amd64.tar.gz
[root@frp-server ~]# tar -zxvf frp_0.39.1_linux_amd64.tar.gz
[root@frp-server ~]# mkdir -p /etc/frp
[root@frp-server ~]# cp frp_0.39.1_linux_amd64/frps.ini /etc/frp/
[root@frp-server ~]# cp frp_0.39.1_linux_amd64/frps     /usr/bin/
[root@frp-server ~]# cp frp_0.39.1_linux_amd64/systemd/frps.service /usr/lib/systemd/system/
[root@frp-server ~]# systemctl enable frps

(4). frp server配置并启动

# 配置:frp/frpc.ini
[root@frp-server ~]# cat >>  /etc/frp/frps.ini << EOF
[common]
server_addr = 47.113.186.199
server_port = 7000
token = hello_world

dashboard_port = 7500
dashboard_user = admin
dashboard_pwd = admin
enable_prometheus = true


log_file = /var/log/frps.log
log_level = info
log_max_days = 3

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

# 2. 启动frps
[root@frp-server ~]# systemctl start frps

# 3. 查看监听端口信息
[root@frp-server ~]# netstat -tlnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp6       0      0 :::7500                 :::*                    LISTEN      1686/frps
tcp6       0      0 :::7000                 :::*                    LISTEN      1686/frps

(5). 访问frp server dashboard

"frp server dashboard"

(6). frp client安装

[root@nfs-server ~]# wget https://github.com/fatedier/frp/releases/download/v0.39.1/frp_0.39.1_linux_amd64.tar.gz
[root@nfs-server ~]# tar -zxvf frp_0.39.1_linux_amd64.tar.gz
[root@nfs-server ~]# mv frp_0.39.1_linux_amd64 frp

# 配置frp client
[root@nfs-server ~]# mkdir -p /etc/frp
[root@nfs-server ~]# cp frp/frpc.ini  /etc/frp/
[root@nfs-server ~]# cp frp/frpc /usr/bin/
[root@nfs-server ~]# cp frp/systemd/frpc.service /usr/lib/systemd/system/

(7). frp client配置

# 配置frp client
[root@nfs-server ~]# cat >>  /etc/frp/frpc.ini << EOF
[common]
tls_enable = true
server_addr = 47.113.186.199
server_port = 7000
token = hello_world

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

# 启动frp
[root@nfs-server ~]# systemctl enable frpc
[root@nfs-server ~]# systemctl start frpc

# 或者手工启动
[root@nfs-server ~]# /usr/bin/frpc -c /etc/frp/frpc.ini
2022/02/19 15:06:56 [I] [service.go:327] [ea9143fa3c23855d] login to server success, get run id [ea9143fa3c23855d], server udp port [0]
2022/02/19 15:06:56 [I] [proxy_manager.go:144] [ea9143fa3c23855d] proxy added: [ssh]
2022/02/19 15:06:56 [I] [control.go:181] [ea9143fa3c23855d] [ssh] start proxy success

(8). frp server查看端口是否绑定成功

[root@frp-server ~]# netstat -tlnp |grep 6000
tcp6       0      0 :::6000                 :::*                    LISTEN      1374/frps

(9). 测试连接(frps server)能否连接到ssh

lixin-macbook:Downloads lixin$ ssh -p 6000 app@47.113.186.199
The authenticity of host '[47.113.186.199]:6000 ([47.113.186.199]:6000)' can't be established.
ECDSA key fingerprint is SHA256:f9rzf8hJyeI/I46XaWAZw3Ga/RgaTLgtZOiY0w7+9iA.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[47.113.186.199]:6000' (ECDSA) to the list of known hosts.
app@47.113.186.199's password:
Last login: Sat Feb 19 14:55:49 2022 from 172.30.51.218

(10). frp server dashboard查看

"frp server dashboard"