frp 内网穿透配置

1、下载

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

解压后

frp目录

服务端对应frps,有公网ip的机子

客户端对应frpc,需要进行穿透的内网机子

2、服务端配置

修改ftps.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
25
[common]
bind_addr = 0.0.0.0
bind_port = 7000
token = aaasda
vhost_http_port = 7001
vhost_https_port = 7002

dashboard_addr = 0.0.0.0
dashboard_port = 7005
dashboard_user = aaa
dashboard_pwd = xxxxaxc

enable_prometheus = false

# 设置日志文件地址
log_file = /var/log/frps.log
# trace, debug, info, warn, error
log_level = info
log_max_days = 3
# disable log colors when log_file is console, default is false
disable_log_color = false
# DetailedErrorsToClient defines whether to send the specific error (with debug info) to frpc. By default, this value is true.
detailed_errors_to_client = true

subdomain_host = silent.m01.space

运行服务端

1
2
3
/apps/frp/frps -c /apps/frp/frps.ini
# 后台启动
nohup /apps/frp/frps -c /apps/frp/frps.ini >/dev/null 2>&1 &

可登录dashboard管理界面
frps-dashboard

3、系统设置服务开机自启

这边使用systemd服务管理,
/usr/lib/systemd/system/目录下创建文件frps.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[Unit]
# 服务描述
Description=Frp Server Service
# frps 将会在 network.service 启动完毕之后再启动
After=network.target

[Service]
# 不论进程是否启动成功,systemctl start 都执行成功
Type=simple
# 设置进程在执行时使用的用户
User=root
# on-failure 表示仅在服务进程异常退出时重启
Restart=on-failure
# 设置在重启服务前暂停多长时间
RestartSec=5s
# 在启动该服务时需要执行的命令行
ExecStart=/apps/frp/frps -c /apps/frp/frps.ini

[Install]
# 用于 systemctl enable 时创建软连接
WantedBy=multi-user.target

创建完后使用service或者systemctl启动,开机自启自行设置

1
2
3
4
5
6
# 查看服务状态
systemctl satus frps
# 服务开机自启
systemctl enable frps
# 服务启动
systemctl start frps

4、客户端配置

配置文件地址/apps/frp/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
25
26
27
28
29
30
31
32
33
34
35
36
# 公用配置
[common]
# frps服务器ip
server_addr=xx.x.xx.xx
# frps.ini的bind_port
server_port=7000
# frps.ini的token
token=aaasda
log_level=info
log_max_days=3
protocol=tcp
log_file=/var/etc/frp/frpc.log
tcp_mux=true
tls_enable=false
login_fail_exit=false

# 需要穿透的服务配置
[wrt(随便命名的)]
# 连接类型http/tcp/udp等
type=http
subdomain=wrt
# 需要穿透的服务ip
local_ip=192.168.7.1
# 需要穿透的服务端口
local_port=80
use_encryption=true
use_compression=true

[ssh-wrt]
type=tcp
# 对应frps服务器的处理端口
remote_port=7221
local_ip=192.168.7.1
local_port=22
use_encryption=true
use_compression=true

启动,和服务端类似

1
2
3
/apps/frp/frpc -c /apps/frp/frpc.ini
# 后台启动
nohup /apps/frp/frpc -c /apps/frp/frpc.ini >/dev/null 2>&1 &