FRP 内网穿透

外网访问vpsIP:8080转发到本地:80

一、服务端配置(Ubuntu 云服务器)

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
37
38
39
40
41
# 下载 FRP
wget https://github.com/fatedier/frp/releases/download/v0.61.2/frp_0.61.2_linux_amd64.tar.gz
tar -zxvf frp_0.61.2_linux_amd64.tar.gz
mv frp_0.61.2_linux_amd64 /opt/frp
cd /opt/frp

# 配置服务端
cat > frps.toml << 'EOF'
bindPort = 7000
auth.method = "token"
auth.token = "dsjahdjkahkk"
vhostHTTPPort = 8080
log.to = "console"
log.level = "info"
EOF

# 放行防火墙
sudo ufw allow 7000/tcp
sudo ufw allow 8080/tcp

# 创建 systemd 服务
cat > /etc/systemd/system/frps.service << 'EOF'
[Unit]
Description=Frp Server Service
After=network.target

[Service]
Type=simple
Restart=always
RestartSec=5
ExecStart=/opt/frp/frps -c /opt/frp/frps.toml

[Install]
WantedBy=multi-user.target
EOF

# 启动服务端
sudo systemctl daemon-reload
sudo systemctl start frps
sudo systemctl enable frps
sudo systemctl status frps

二、客户端配置(Anolis 本地机器)

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
37
38
39
40
41
42
43
44
45
# 下载 FRP
wget https://github.com/fatedier/frp/releases/download/v0.61.2/frp_0.61.2_linux_amd64.tar.gz
tar -zxvf frp_0.61.2_linux_amd64.tar.gz
mv frp_0.61.2_linux_amd64 /opt/frp
cd /opt/frp

# 配置客户端
cat > frpc.toml << 'EOF'
serverAddr = "12.34.56.78"
serverPort = 7000
auth.token = "dsjahdjkahkk"

[[proxies]]
name = "web"
type = "http"
localPort = 80
customDomains = ["12.34.56.78"]
httpUser = "username"
httpPassword = "password"
EOF

# 测试连接
./frpc -c frpc.toml

# 创建 systemd 服务
cat > /etc/systemd/system/frpc.service << 'EOF'
[Unit]
Description=Frp Client Service
After=network.target

[Service]
Type=simple
Restart=always
RestartSec=5
ExecStart=/opt/frp/frpc -c /opt/frp/frpc.toml

[Install]
WantedBy=multi-user.target
EOF

# 启动客户端
sudo systemctl daemon-reload
sudo systemctl start frpc
sudo systemctl enable frpc
sudo systemctl status frpc

三、云服务商安全组配置

登录云控制台,添加入方向规则:

协议 端口 来源
TCP 7000 0.0.0.0/0
TCP 8080 0.0.0.0/0

四、验证访问

1
2
3
4
5
6
7
# 检查服务状态
sudo systemctl status frps # 服务端
sudo systemctl status frpc # 客户端

# 查看日志
sudo journalctl -u frps -f
sudo journalctl -u frpc -f

浏览器访问:http://68.64.178.45:8080(输入 HTTP Basic Auth 用户名密码)

五、常用管理命令

1
2
3
4
5
6
7
8
9
10
11
12
# 服务管理
sudo systemctl start frps/frpc
sudo systemctl stop frps/frpc
sudo systemctl restart frps/frpc
sudo systemctl status frps/frpc

# 查看日志
sudo journalctl -u frps/frpc -f
sudo journalctl -u frps/frpc -n 50

# 重新加载配置
sudo systemctl restart frps/frpc