<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:wfw="http://wellformedweb.org/CommentAPI/">
<channel>
<title>雾非雾 - frp</title>
<link>https://www.941741.xyz/tag/frp/</link>
<atom:link href="https://www.941741.xyz/feed/tag/frp/" rel="self" type="application/rss+xml" />
<language>zh-CN</language>
<description></description>
<lastBuildDate>Thu, 29 Oct 2026 08:59:00 +0800</lastBuildDate>
<pubDate>Thu, 29 Oct 2026 08:59:00 +0800</pubDate>
<item>
<title>用 frp stcp 安全访问内网测试数据库</title>
<link>https://www.941741.xyz/archives/frp-stcp-1.html</link>
<guid>https://www.941741.xyz/archives/frp-stcp-1.html</guid>
<pubDate>Thu, 29 Oct 2026 08:59:00 +0800</pubDate>
<dc:creator>花非花</dc:creator>
<category><![CDATA[应用技巧]]></category>
<description><![CDATA[之前用 frp，主要是为了把 NAS 上的服务映射到公网。最近又多了一个需求：公司内网有一台测试数据库，平时系统工程师升级调试、自己做功能验证时都会用到。如果直接把数据库端口映射到公网，风险太高...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<p>之前用 frp，主要是为了把 NAS 上的服务映射到公网。<br>最近又多了一个需求：公司内网有一台测试数据库，平时系统工程师升级调试、自己做功能验证时都会用到。<br>如果直接把数据库端口映射到公网，风险太高，所以改用 frp 的 stcp 模式。</p><blockquote>stcp 是什么<br>stcp 全称 Secret TCP，可以理解成一种“需要双方都持有密钥才能建立”的内网隧道。<br>和普通 tcp 代理不同的是：<br>普通 tcp 代理会在 frps 上监听一个端口，任何人知道地址和端口都可能尝试连接；<br>stcp 不会在 frps 上直接暴露业务端口；<br>只有配置了相同 secretKey 的访问端，才能通过 frps 与被控端建立连接。<br>简单说，就是 frps 只做中转，不直接对外开放数据库端口。</blockquote><p>基本思路<br>整体链路可以理解为：</p><blockquote>本地访问端 → frps → 内网被控端 → 本地数据库</blockquote><hr><p>内网防火墙侧只需要允许被控主机访问 VPS 上的 frps 端口，其他端口保持关闭。<br>这样即使 VPS IP 被知道，也不会直接暴露数据库服务。</p><p>frps 配置<br>frps 端保持正常配置即可，重点注意几点：<br>不要使用默认端口；<br>auth.token 要使用足够复杂的字符串；<br>如果开启 Dashboard，需要限制访问来源并设置强密码；<br>建议开启 TLS，避免连接过程被窃听。</p><p>在被控主机上部署 frpc，配置文件大致如下：</p><pre><code>serverAddr = &quot;&lt;frps服务器地址&gt;&quot;
serverPort = &lt;frps端口&gt;
auth.token = &quot;&lt;与frps一致的token&gt;&quot;

[transport]
tls.enable = true
tcpMux = true
tls.trustedCaFile = &quot;./ca.crt&quot;

[[proxies]]
name = &quot;internal-db&quot;
type = &quot;stcp&quot;
secretKey = &quot;&lt;独立生成的复杂密钥&gt;&quot;
localIP = &quot;127.0.0.1&quot;
localPort = &lt;数据库端口&gt;</code></pre><p>注意：<br>secretKey 不要和 auth.token 相同；<br>localIP 如果被控端需要代理其他主机，可以改成被控端能访问到的内网 IP；<br>localPort 根据实际数据库端口修改；<br>如果 frps 使用了自签证书，需要在被控端配置 tls.trustedCaFile。</p><p>启动命令：<br><code>frpc.exe -c ./frpc.toml</code></p><hr><p>本地访问端配置<br>访问端同样需要部署 frpc，但节点类型要使用 visitors：</p><pre><code>serverAddr = &quot;&lt;frps服务器地址&gt;&quot;
serverPort = &lt;frps端口&gt;
auth.token = &quot;&lt;与frps一致的token&gt;&quot;

[transport]
tls.enable = true
tcpMux = true
tls.trustedCaFile = &quot;./ca.crt&quot;

[[visitors]]
name = &quot;visit-db&quot;
type = &quot;stcp&quot;
serverName = &quot;internal-db&quot;
secretKey = &quot;&lt;与被控端一致的密钥&gt;&quot;
bindPort = &lt;本地空闲端口&gt;</code></pre><p>启动后，本地访问 127.0.0.1:&lt;本地空闲端口&gt;就可以连接到内网数据库。</p><hr><p>给同事使用时要注意什么<br>如果工程师也需要访问，不建议直接把 frpc.toml 文件通过聊天工具、邮件或网盘发送。因为配置文件里包含 auth.token 和 secretKey，一旦泄露，别人就可能通过你的 frps 建立隧道。<br>更稳妥的做法是：<br>只发送非敏感字段；<br>secretKey 通过单独渠道告知；<br>或者使用加密压缩包分发；<br>不同访问端使用不同的 name，避免同时在线被踢下线。</p><p>安全性说明</p><blockquote>这套组合：<br>frps 不直接暴露数据库端口；<br>使用 token 认证；<br>使用 TLS 加密；<br>stcp 需要双方持有相同密钥；<br>相比直接把数据库端口映射到公网，安全性明显更高。<br>但它并不是绝对安全。如果 token、secretKey、证书或配置文件保管不当，仍然存在被利用的可能。所以关键还是要把敏感配置当作密钥来管理，不要明文外发。</blockquote><p>ps.这是AI脱敏后的文章内容，AI果然失去了温度啊。</p>
]]></content:encoded>
<slash:comments>15</slash:comments>
<comments>https://www.941741.xyz/archives/frp-stcp-1.html#comments</comments>
<wfw:commentRss>https://www.941741.xyz/feed/tag/frp/archives/frp-stcp-1.html</wfw:commentRss>
</item>
<item>
<title>再战 FRP</title>
<link>https://www.941741.xyz/archives/FRP.html</link>
<guid>https://www.941741.xyz/archives/FRP.html</guid>
<pubDate>Wed, 28 Oct 2026 16:33:00 +0800</pubDate>
<dc:creator>花非花</dc:creator>
<category><![CDATA[应用技巧]]></category>
<description><![CDATA[frp 算是我常用的工具，1024 趁着活动，又入了台腾讯的 VPS，国内的，也不想备案，所以拿来做FRP服务器用吧。之前用的都是简洁配置，没太考虑安全性，这次新布置，干脆把其他几台 VPS 也...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<p>frp 算是我常用的工具，1024 趁着活动，又入了台腾讯的 VPS，国内的，也不想备案，所以拿来做FRP服务器用吧。</p><p>之前用的都是简洁配置，没太考虑安全性，这次新布置，干脆把其他几台 VPS 也升级一下，加强一下安全性吧。</p><hr><p>首先是去 Github 下载了最新的版本，然后在宝塔里上传、解压；</p><p>然后去宝塔的终端里先把当前运行的 frp 服务停止，因为用的是 systemd</p><pre><code>停止 frps:
systemctl stop frps</code></pre><p>然后回到宝塔的文件管理里，把 frps 覆盖到原 frps 所在的位置。</p><p>接下来才是这次改造的重点，官方的文档有点难懂，甚至豆包都没能给出正确答案，最后还是靠千问。</p><p>frps.toml 配置</p><pre><code>bindPort = 服务器上开放的监听端口，别忘记防火墙
auth.method = &quot;token&quot;
auth.token = &quot;建议用随机密码生成器生成一组超过64位的强字符串&quot;

transport.tls.force = true
transport.tls.certFile = &quot;/opt/frp/certs/server.crt&quot;
transport.tls.keyFile = &quot;/opt/frp/certs/server.key&quot;

# 日志
log.to = &quot;/opt/frp/frps.log&quot;
log.level = &quot;info&quot;
log.maxDays = 7</code></pre><p>然后用脚本生成自签证书，注意一下 frps 所在的目录，以及服务器的 IP 地址</p><pre><code>cd ~ &amp;&amp; cat &gt; gen_frp_cert.sh &lt;&lt; &#039;EOF&#039;
#!/bin/bash
mkdir -p /opt/frp/certs
cd /opt/frp/certs

# 1. CA 根证书
openssl genrsa -out ca.key 4096
openssl req -x509 -new -nodes -key ca.key -sha256 -days 3650 -out ca.crt -subj &quot;/CN=frp-ca&quot;

# 2. 服务器私钥和包含 IP SAN 的 CSR 和 CRT
openssl genrsa -out server.key 2048
openssl req -new -key server.key -out server.csr \
  -subj &quot;/CN=frp-server&quot; \
  -addext &quot;subjectAltName=IP:你服务器的IP地址&quot;

openssl x509 -req -in server.csr \
  -CA ca.crt -CAkey ca.key -CAcreateserial \
  -out server.crt -days 1825 -sha256 \
  -extfile &lt;(printf &quot;subjectAltName=IP:%s&quot; &quot;你服务器的IP地址&quot;)

chmod 600 *.key
echo &quot;=========================================&quot;
echo &quot;证书生成成功！位置：/opt/frp/certs/&quot;
echo &quot;=========================================&quot;
EOF

chmod +x gen_frp_cert.sh &amp;&amp; bash gen_frp_cert.sh</code></pre><p>在终端里运行上面的脚本，获取到证书后，启动 frps 服务</p><pre><code>启动 frps:
systemctl start frps

重启 frps：
systemctl restart frps</code></pre><p>运行后查看一下状态，看看有没有报错</p><pre><code>查看 frps 状态：
systemctl status frps</code></pre><hr><p>没问题就进入下一步，先在宝塔里把 certs 目录下，刚才脚本生成的证书里的 ca.crt 下载到本本地</p><p>然后上传到 NAS 里，比如位置放在 docker/frp/certs/ca.crt </p><p>然后就是 frpc.toml 的配置</p><pre><code># 1. 基础连接配置（全局放在最顶部，不要加任何段头）
serverAddr = &quot;frps服务器的IP地址&quot;
serverPort = 之前服务器上开放的监听端口

# 登录失败是否直接退出（设为false，方便你调试连接问题）
loginFailExit = false

# 2. 传输与心跳配置（所有 transport 配置合并在这里）
[transport]
protocol = &quot;tcp&quot;
tcpMux = true
tcpMuxKeepaliveInterval = 30
heartbeatTimeout = 90
heartbeatInterval = 30

# TLS 安全配置（合并进上面的 transport 段）
tls.enable = true
tls.trustedCaFile = &quot;/certs/ca.crt&quot;
#之前就是这一步卡了好久

# 3. 身份认证配置
[auth]
method = &quot;token&quot;
token = &quot;从服务器上 frps.toml 里复制过来&quot;

# 4. 端口映射配置（注意是双中括号 [[proxies]]）

[[proxies]]
name = &quot;起个不重的名字&quot;
type = &quot;tcp&quot;
localIP = &quot;你内网服务器的IP，如果是NAS本机就用 127.0.0.1&quot;
localPort = NAS上应用的端口
remotePort = 映射到 VPS 上的端口，别忘记 VPS 的防火墙要开放对应的端口号

[[proxies]]
name = &quot;起个不重的名字&quot;
type = &quot;tcp&quot;
localIP = &quot;你内网服务器的IP，如果是NAS本机就用 127.0.0.1&quot;
localPort = NAS上应用的端口
remotePort = 映射到 VPS 上的端口，别忘记 VPS 的防火墙要开放对应的端口号</code></pre><p>运行 Docker ，网络选择 Host 模式，要留意的是挂载路径，有二个</p><p>本地 frpc.toml 所在的地址，比如 docker/frp/frpc.toml : /ect/frp/frpc.toml<br>本地 ca 证书所在的地址，比如 docker/frp/carts/ca.crt : /certs/ca.crt</p><p>到了这儿，基本上就成功了；<br>之前只用了 Token 认证，现在开了 TLS 加了认证证书，应该要比之前安全些吧。</p>
]]></content:encoded>
<slash:comments>14</slash:comments>
<comments>https://www.941741.xyz/archives/FRP.html#comments</comments>
<wfw:commentRss>https://www.941741.xyz/feed/tag/frp/archives/FRP.html</wfw:commentRss>
</item>
<item>
<title>frp 相关</title>
<link>https://www.941741.xyz/archives/102.html</link>
<guid>https://www.941741.xyz/archives/102.html</guid>
<pubDate>Mon, 31 Oct 2022 10:05:00 +0800</pubDate>
<dc:creator>花非花</dc:creator>
<category><![CDATA[路由存储]]></category>
<description><![CDATA[之前在 CloudCone 上安装、配置好了 frp 的服务端，运行一个月了一直很稳定，但昨天群晖 Docker 上的客户端突然连接不上了；想着 frp 的程序有可能有新版本，索性把配置流程重新...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<p><img src="https://www.941741.xyz/usr/uploads/2022/10/2587092730.png" alt="frps" title="frps"></p><p>之前在 CloudCone 上安装、配置好了 frp 的服务端，运行一个月了一直很稳定，但昨天群晖 Docker 上的客户端突然连接不上了；想着 frp 的程序有可能有新版本，索性把配置流程重新走一次吧。</p><p>之前记得图省事，frp 服务端用的是后台启动的方法：</p><pre><code>nohup ./frps -c frps.ini &gt;/dev/null 2&gt;&amp;1 &amp;</code></pre><p>所以首先想到的是先终止 frps 的进程，用 kill 命令；首先查看 frp 进程 ID</p><pre><code># ps -aux|grep frp| grep -v grep
root      1046  0.0  1.5 727036 15468 ?        Ssl  Oct30   0:24 /home/frp/frp_0.44.0/frps -c /home/frp/frp_0.44.0/frps.ini</code></pre><p>得到了进程号为 1046 后，杀掉进程：</p><pre><code>kill -9 1046</code></pre><p>本来这之后，我在宝塔的图形界面下，上传了当前最新版本的 frp ，并把 frps 想复制粘贴覆盖掉原来的版本，但是，覆盖失败；再次查进程，发现 frps 还在；重复杀了几次，才想起，可能。。。我把 frps 做成了服务？</p><p>按服务的命令查看一下 frp 运行的状态：</p><pre><code>systemctl status frps</code></pre><p>事实证明，frps 果然是以服务的方式启动运行的；所以：</p><pre><code>开机启动frps：
systemctl enable frps
启动frps:
systemctl start frps
停止frps:
systemctl stop frps
重启frps：
systemctl restart frps
查看frps状态：
systemctl status frps</code></pre><p>之后替换掉 frps 重启启动服务即可。</p><p>&lt;!--more--&gt;</p><p>关于安装、配置服务，记录二个网址吧：</p><pre><code>https://gofrp.org/docs/setup/systemd/

https://www.iyuu.cn/archives/286/</code></pre>
]]></content:encoded>
<slash:comments>10</slash:comments>
<comments>https://www.941741.xyz/archives/102.html#comments</comments>
<wfw:commentRss>https://www.941741.xyz/feed/tag/frp/archives/102.html</wfw:commentRss>
</item>
</channel>
</rss>