frp使用

  • 什么是内网穿透?简单来讲,就像给内网设备装了一扇外网设备可以进的门。
  • 家用设备,比如NAS、电脑,通常都躲在路由器分配的内网IP(如192.168.x.x)里,外网根本进不来。而内网穿透的原理就是用一台具备公网IP的服务器作为中转站,让外部设备通过它访问你的内网设备。

相关工具下载链接:

1
2
3
4
5
6
7
8
9
10
https://github.com/fatedier/frp/releases/

## linux运行版本:
https://github.com/fatedier/frp/releases/download/v0.61.1/frp_0.61.1_linux_arm64.tar.gz

## mac运行版本:
https://github.com/fatedier/frp/releases/download/v0.61.1/frp_0.61.1_darwin_amd64.tar.gz

## windows运行版本:
https://github.com/fatedier/frp/releases/download/v0.61.1/frp_0.61.1_windows_amd64.zip

docker compose方式启动,配置文件【可选】:

docker-compose.yml

1
2
3
4
5
6
7
8
9
10
11
version: '3'
services:
frps:
image: snowdreamtech/frps
container_name: frps
restart: always
network_mode: host
volumes:
- ./frps.toml:/etc/frp/frps.toml
environment:
- FRP_CONFIG_FILE=/etc/frp/frps.toml

systemd方式启动,配置文件【可选】:

服务端:

1
2
3
4
5
6
7
8
9
10
11
12
## cat /etc/systemd/system/frps.service
[Unit]
Description=FRPS Script Service
After=network.target

[Service]
User=root
ExecStartPre=/bin/sleep 10
ExecStart=/usr/local/frp/frps -c /usr/local/frp/frps.toml

[Install]
WantedBy=multi-user.target

客户端:

1
2
3
4
5
6
7
8
9
10
11
12
## cat /etc/systemd/system/frpc.service
[Unit]
Description=FRPC Script Service
After=network.target

[Service]
User=root
ExecStartPre=/bin/sleep 10
ExecStart=/usr/local/frp/frpc -c /usr/local/frp/frpc.toml

[Install]
WantedBy=multi-user.target

服务端配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
##  创建 frps.toml 文件,内容如下

# 基本配置
bindPort = 7000 # frps 监听的端口,用于接收 frpc 的连接

# 认证配置
[auth]
method = "token" # 认证方法,这里使用 token
token = "token1234xyz" # 用于验证 frpc 的 token,请使用安全的随机字符串

# Web 管理界面配置(如果不需要 Web 管理界面,可以删除这部分)
[webServer]
addr = "0.0.0.0" # Web 界面监听的地址,0.0.0.0 表示所有地址
port = 7500 # Web 界面的端口
user = "user" # Web 界面的登录用户名
password = "passwordxxx" # Web 界面的登录密码

# 日志配置
[log]
to = "console" # 日志输出位置,console 表示输出到控制台
level = "info" # 日志级别:debug, info, warn, error

客户端配置文件:

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
# frpc.toml

# 服务器配置
serverAddr = "39.98.38.171" # 公网服务器的IP
serverPort = 7000

# 认证配置
auth.method = "token"
auth.token = "token1234xyz"

# 日志配置
log.to = "console"
log.level = "info"

# -----从这里开始都是,程序的信息-----
# SSH 服务配置
[[proxies]]
name = "mac-ssh"
type = "tcp"
localIP = "host.docker.internal"
localPort = 22
remotePort = 10022

# VNC 服务配置
[[proxies]]
name = "mac-vnc"
type = "tcp"
localIP = "host.docker.internal"
localPort = 5900
remotePort = 15900