惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Palo Alto Networks Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
CERT Recently Published Vulnerability Notes
C
Cybersecurity and Infrastructure Security Agency CISA
S
Schneier on Security
S
Securelist
酷 壳 – CoolShell
酷 壳 – CoolShell
C
CXSECURITY Database RSS Feed - CXSecurity.com
Cyberwarzone
Cyberwarzone
Apple Machine Learning Research
Apple Machine Learning Research
S
SegmentFault 最新的问题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
GbyAI
GbyAI
Security Latest
Security Latest
Last Week in AI
Last Week in AI
Microsoft Security Blog
Microsoft Security Blog
云风的 BLOG
云风的 BLOG
Recorded Future
Recorded Future
Webroot Blog
Webroot Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
TaoSecurity Blog
TaoSecurity Blog
C
Cisco Blogs
博客园 - 【当耐特】
Blog — PlanetScale
Blog — PlanetScale
Hugging Face - Blog
Hugging Face - Blog
B
Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Attack and Defense Labs
Attack and Defense Labs
The Last Watchdog
The Last Watchdog
U
Unit 42
阮一峰的网络日志
阮一峰的网络日志
Project Zero
Project Zero
WordPress大学
WordPress大学
L
LINUX DO - 最新话题
F
Fortinet All Blogs
L
LINUX DO - 热门话题
PCI Perspectives
PCI Perspectives
Simon Willison's Weblog
Simon Willison's Weblog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
MongoDB | Blog
MongoDB | Blog
Latest news
Latest news
P
Proofpoint News Feed
T
Threat Research - Cisco Blogs
The Hacker News
The Hacker News
爱范儿
爱范儿
O
OpenAI News
J
Java Code Geeks
T
The Exploit Database - CXSecurity.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - LungGiyo

nginx 跨域解决 001 局域网其他电脑也能访问wsl服务 001 nvm 管理不同版本的 node 与 npm 关于IP送中的影响和解决办法 Antigravity google ai 接入高德MCP 1.3.2 git使用ssh密钥 连接远程仓库 dynadot域名 托管到cloudflare , 使用cloudflare 的CDN功能 003 二进制日志-binlog Django 项目开发整体步骤(0 开始)+进阶 磊科N60Pro刷机 uni的页面解析 前端技术知识扫盲篇 使用 Lucky 为群晖 / 极空间 NAS 全服务启用 HTTPS 安全访问 00 docker 命令总结 001 Python 基础 麒麟系统升级openssh至openssh-10.0p1 零信任访问控制系统aTrust 蓝屏 Python PyInstaller 打包、Pyarmor加密等 001 安装wsl 2 && 开启 WSL2 Oxidized的model
frp 教程
LungGiyo · 2026-07-09 · via 博客园 - LungGiyo

很多人第一次接触内网穿透,都是因为遇到了一个很现实的问题:

公司内网有一台服务器,网站只能在内网访问,MySQL 也只监听本机端口。人在外地的时候,想连回去看页面、查数据库、远程 SSH,都变得很麻烦。

一开始我用的是 `ssh -R` 反向端口转发:

ssh -fN -R 10081:localhost:81 root@公网服务器
ssh -fN -R 13306:localhost:3306 root@公网服务器
ssh -fN -R 10022:localhost:22 root@公网服务器

能用是能用,但问题也很明显:每个端口都要单独写一条命令,断线了不好维护,端口多了之后根本记不住。

所以这篇文章不讲那些虚的概念,直接从一个真实场景开始:如何用 frp 把内网服务器上的网站、SSH、MySQL 统一暴露到一台公网代理服务器上,实现外网访问内网服务。

下载

公网代理服务器 A(120.25.1.238) 安装 frps

cd /opt

wget -O frp.tar.gz https://github.com/fatedier/frp/releases/download/v0.69.1/frp_0.69.1_linux_amd64.tar.gz

tar -zxvf frp_xxx

mv frp_xxxx  frp

mkdir -p /etc/frp

cp /opt/frp/frps /usr/local/bin/frps

chmod +x /usr/local/bin/frps

创建服务端配置,端口说明:

7000    = frpc 连接 frps 的通信端口

10022   = 内网服务器 B 的 SSH

10081   = 内网服务器 B 的网站 81

13306   = 内网服务器 B 的 MySQL 3306

vim /etc/frp/frps.toml

bindAddr = "0.0.0.0"
bindPort = 7000

auth.method = "token"
auth.token = "这里改成一个很长的随机密码"

allowPorts = [
  { start = 10020, end = 10099 },
  { start = 13306, end = 13306 }
]

先手动测试启动:

frps -c /etc/frp/frps.toml

如果没有报错,按 Ctrl + C 停止,然后配置 systemd。

用 systemd 管理 frp

vim /etc/systemd/system/frps.service

[Unit]
Description=frp server
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/frps -c /etc/frp/frps.toml
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

启动:

systemctl daemon-reload
systemctl enable frps
systemctl start frps
systemctl status frps

确认监听:

你应该看到:

宝塔、安全组端口放行:

7000/tcp

10022/tcp 到 10099/tcp

13306/tcp

内网服务器 B 安装 frpc

cd /opt

wget -O frp.tar.gz https://github.com/fatedier/frp/releases/download/v0.69.1/frp_0.69.1_linux_amd64.tar.gz

tar -zxvf frp_xxx

mv frp_xxxx  frp

mkdir -p /etc/frp

cp /opt/frp/frpc /usr/local/bin/frpc

chmod +x /usr/local/bin/frpc

创建客户端配置:

vim /etc/frp/frpc.toml

serverAddr = "120.25.1.238,这里ip就是公网代理服务器 A的ip"
serverPort = 7000

auth.method = "token"
auth.token = "这里要和A服务器frps.toml里面的一样"

[[proxies]]
name = "b-web-81"
type = "tcp"
localIP = "127.0.0.1"
localPort = 81
remotePort = 10081

[[proxies]]
name = "b-ssh-22"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22
remotePort = 10022

[[proxies]]
name = "b-mysql-3306"
type = "tcp"
localIP = "127.0.0.1"
localPort = 3306
remotePort = 13306

这个配置等价于:

120.25.1.238:10081  →  B服务器 127.0.0.1:81

120.25.1.238:10022  →  B服务器 127.0.0.1:22

120.25.1.238:13306  →  B服务器 127.0.0.1:3306

手动测试 frpc,在 B 上执行:

frpc -c /etc/frp/frpc.toml

如果成功,你会看到类似:

login to server success

start proxy success

然后不要关闭这个窗口,先从任意主机 C 测试(主机 C 不需要安装 frp)。

浏览器打开:

http://120.25.1.238:10081/

B 配置 frpc 开机自启

确认手动测试没问题后,在 B 上创建 systemd 服务:

vim /etc/systemd/system/frpc.service

[Unit]
Description=frp client
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/frpc -c /etc/frp/frpc.toml
Restart=always
RestartSec=5


[Install]
WantedBy=multi-user.target

启动:

systemctl daemon-reload

systemctl enable frpc

systemctl start frpc

systemctl status frpc

查看日志:

journalctl -u frpc -f

    location / {
        proxy_pass http://127.0.0.1:10081;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
    }