使用frp工具实现远程访问本地服务器

使用frp工具实现远程访问本地服务器

概述

本文章通过远程桌面的案例来介绍内网穿透的实现方法

项目准备

想要实现内网穿,首先准备以下工具

目标服务器

目标服务器不具备公网ip,但已经开启需要的服务,如远程桌面;web网页服务;smb网络硬盘服务。

本帖以windows系统下的远程桌面服务(tcp协议)为案例

跳板机

具备公网ip的服务器,用于将目标服务器的服务内容映射在公网上。

本贴以华为云的CentOS系统为例

内网工具

用于将跳板机和目标服务器进行关联中间工具。

本贴以frp工具为例

frp 工具相关

frp为开源项目,

项目地址

https://github.com/fatedier/frp

frp官网

https://gofrp.org/zh-cn/

下载frp工具

→ 进入项目地址

→ release

→ 找到对应的文件进行下载

例:我的目标服务器为windows系统;跳板机为centos系统,最新版本为0.60.0 ,就下载“frp windows amd 0.60.0”和“frp linux amd 0.60.0”
下载.png

工具包阐述

下载的工具包含5个文件

  1. frpc

目标服务器执行文件(目标服务器为客户端,后文目标服务器均以客户端进行命名)

  1. frpc.toml

客户端对应的配置文件,后文进行阐述

  1. frps

跳板机的执行文件(跳板机为服务端,后文目标服务器均以服务端进行命名)

  1. frps.toml

服务对应的配置文件,后文进行阐述

  1. license

许可证 不用管

服务端的配置

1部署及配置frps

→ 通过ssh连接服务端

→ 将frp_linux工具包放在 /usr/local 文件夹内(可以通过xfp软件进行操作)

→ 解包

1
2
3
4
5
# 访问目标文件夹,查看是否存在对应的包
cd /usr/local
ls
#解包
tar -zxvf frp_0.60.0_linux_amd64.tar.gz

→ 配置frpc.toml 文件

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
# 基本设置
bindAddr = "0.0.0.0"

#监听端口
bindPort = 7000
kcpBindPort = 7000

#服务端后台页面配置
webServer.addr = "0.0.0.0"
#后台页面端口
webServer.port = 8000
# 后台页面账号、密码
webServer.user = "admin"
webServer.password = "admin"

# 导出文件
log.to = "/frplog/frps.log"
log.level = "info"
log.maxDays = 3

# 设置token 用于server和client进行特征握手
auth.method = "token"
auth.token = "12345"

# frp开放端口范围 用于远程访问
allowPorts = [
{start = 6000, end = 9000}
]

使用 systemd 来启动frps

→ 安装 systemd

1
yum install systemd

→ 创建 frps.service 文件

1
sudo vim /etc/systemd/system/frps.service

→ 配置 frps.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[Unit]
# 服务名称,可自定义
Description = frp server
After = network.target syslog.target
Wants = network.target

[Service]
Type = simple
# 启动frps的命令,需修改为您的frps的安装路径
ExecStart = /usr/local/frp_0.60.0_linux_amd64/frps -c /usr/local/frp_0.60.0_linux_amd64/frps.toml

Execstop=/bin/kill $MAINPID
Restart = always
RestartSec = 5

[Install]
WantedBy = multi-user.target

→ 使用 systemd 命令管理 frps 服务

1
2
3
4
5
6
7
8
9
# 启动frp
sudo systemctl start frps
# 停止frp
sudo systemctl stop frps
# 重启frp
sudo systemctl restart frps
# 查看frp状态
sudo systemctl status frps

→ 设置 frps 开机自启动

1
sudo systemctl enable frps
1
2
# 启动frps

1
ls

拓展内容

设置客户端frpc 开机自启动

https://blog.csdn.net/qq1170993239/article/details/124421103

使用frp工具实现远程访问本地服务器

http://jenkina.cn/2024/09/12/fuwuqi/frp/

作者

Jenkin Liu

发布时间

2024-09-12

更新时间

2024-09-13

许可协议

评论