[GH-ISSUE #1493] frp的frps.service配置的User=nobody绑定不了某些端口 #1179

Closed
opened 2026-05-05 12:45:25 -06:00 by gitea-mirror · 14 comments
Owner

Originally created by @ju0594 on GitHub (Nov 2, 2019).
Original GitHub issue: https://github.com/fatedier/frp/issues/1493

Issue is only used for submiting bug report and documents typo. If there are same issues or answers can be found in documents, we will close it directly.
(为了节约时间,提高处理问题的效率,不按照格式填写的 issue 将会直接关闭。)
(请不要在 issue 评论中出现无意义的 加1我也是 等内容,将会被直接删除。)
(由于个人精力有限,和系统环境,网络环境等相关的求助问题请转至其他论坛或社交平台。)

Use the commands below to provide key information from your environment:
You do NOT have to include this information if this is a FEATURE REQUEST

What version of frp are you using (./frpc -v or ./frps -v)?
0.29.0

What operating system and processor architecture are you using (go env)?

Configures you used:

Steps to reproduce the issue:
1.复制frps.service到/etc/systemd/system
2.在/etc/frp/frps.ini 填写比如 vhost_https_port = 443
3.使用systemctl start frps启动 发现启动失败

Describe the results you received:
使用 systemctl status frps -l 显示

● frps.service - Frp Server Service
   Loaded: loaded (/etc/systemd/system/frps.service; disabled)
   Active: activating (auto-restart) (Result: exit-code) since Fri 2019-11-01 23:58:02 EDT; 2s ago
  Process: 2085 ExecStart=/usr/bin/frps -c /etc/frp/frps.ini (code=exited, status=1/FAILURE)
 Main PID: 2085 (code=exited, status=1/FAILURE)

Describe the results you expected:

Additional information you deem important (e.g. issue happens only occasionally):

Can you point out what caused this issue (optional)
使用User=nobody的时候,只能绑定一些高位端口,443之类的端口都不能绑定,netstat -ntulp |grep 443发现并没有被别的软件占用。
但是把User=nobody注释掉使用root用户就没问题了,很奇怪,不知道为啥。

Originally created by @ju0594 on GitHub (Nov 2, 2019). Original GitHub issue: https://github.com/fatedier/frp/issues/1493 Issue is only used for submiting bug report and documents typo. If there are same issues or answers can be found in documents, we will close it directly. (为了节约时间,提高处理问题的效率,不按照格式填写的 issue 将会直接关闭。) (请不要在 issue 评论中出现无意义的 **加1**,**我也是** 等内容,将会被直接删除。) (由于个人精力有限,和系统环境,网络环境等相关的求助问题请转至其他论坛或社交平台。) Use the commands below to provide key information from your environment: You do NOT have to include this information if this is a FEATURE REQUEST **What version of frp are you using (./frpc -v or ./frps -v)?** 0.29.0 **What operating system and processor architecture are you using (`go env`)?** **Configures you used:** **Steps to reproduce the issue:** 1.复制frps.service到/etc/systemd/system 2.在/etc/frp/frps.ini 填写比如 vhost_https_port = 443 3.使用`systemctl start frps`启动 发现启动失败 **Describe the results you received:** 使用 `systemctl status frps -l` 显示 ``` ● frps.service - Frp Server Service Loaded: loaded (/etc/systemd/system/frps.service; disabled) Active: activating (auto-restart) (Result: exit-code) since Fri 2019-11-01 23:58:02 EDT; 2s ago Process: 2085 ExecStart=/usr/bin/frps -c /etc/frp/frps.ini (code=exited, status=1/FAILURE) Main PID: 2085 (code=exited, status=1/FAILURE) ``` **Describe the results you expected:** **Additional information you deem important (e.g. issue happens only occasionally):** **Can you point out what caused this issue (optional)** 使用User=nobody的时候,只能绑定一些高位端口,443之类的端口都不能绑定,`netstat -ntulp |grep 443`发现并没有被别的软件占用。 但是把User=nobody注释掉使用root用户就没问题了,很奇怪,不知道为啥。
Author
Owner

@deadlineOvO commented on GitHub (Nov 2, 2019):

正常现象

<!-- gh-comment-id:549009110 --> @deadlineOvO commented on GitHub (Nov 2, 2019): 正常现象
Author
Owner

@xqzr commented on GitHub (Nov 2, 2019):

这是系统限制

<!-- gh-comment-id:549012178 --> @xqzr commented on GitHub (Nov 2, 2019): 这是系统限制
Author
Owner

@ysc3839 commented on GitHub (Nov 2, 2019):

许多 Unix 系统会限制只有 root 用户才能绑定一些端口。而且这种限制很可能是写死的,也就是说没办法设置“允许某用户组绑定端口”。这种情况下只能先以 root 用户启动,绑定端口后再用 setuid 来 “drop root”。

<!-- gh-comment-id:549017040 --> @ysc3839 commented on GitHub (Nov 2, 2019): 许多 Unix 系统会限制只有 root 用户才能绑定一些端口。而且这种限制很可能是写死的,也就是说没办法设置“允许某用户组绑定端口”。这种情况下只能先以 root 用户启动,绑定端口后再用 setuid 来 “drop root”。
Author
Owner

@fatedier commented on GitHub (Nov 2, 2019):

你可以认为这只是一个示例配置,可以根据自己的需要进行修改。

<!-- gh-comment-id:549042456 --> @fatedier commented on GitHub (Nov 2, 2019): 你可以认为这只是一个示例配置,可以根据自己的需要进行修改。
Author
Owner

@Xeath commented on GitHub (Nov 3, 2019):

……
部分系统限制了非 root 账户不能绑定 1024 以下的端口。

<!-- gh-comment-id:549147531 --> @Xeath commented on GitHub (Nov 3, 2019): …… 部分系统限制了非 root 账户不能绑定 1024 以下的端口。
Author
Owner

@deadlineOvO commented on GitHub (Nov 5, 2019):

额外一提:假设不使用 root 来进行绑定 1024 一下端口的话,可以使用 setcap 或者是增加 systemd 单元文件的 cap 相关选项来达成目的

<!-- gh-comment-id:549665979 --> @deadlineOvO commented on GitHub (Nov 5, 2019): 额外一提:假设不使用 root 来进行绑定 1024 一下端口的话,可以使用 setcap 或者是增加 systemd 单元文件的 cap 相关选项来达成目的
Author
Owner

@deadlineOvO commented on GitHub (Nov 5, 2019):

详细看了下,使用 systemd 的发行版可以使用 CapabilityBoundingSet = 来设置这个服务的一些能力

<!-- gh-comment-id:549667696 --> @deadlineOvO commented on GitHub (Nov 5, 2019): 详细看了下,使用 systemd 的发行版可以使用 `CapabilityBoundingSet =` 来设置这个服务的一些能力
Author
Owner

@iBug commented on GitHub (Nov 17, 2019):

详细看了下,使用 systemd 的发行版可以使用 CapabilityBoundingSet = 来设置这个服务的一些能力

这里有点错误,CapabilityBoundingSet 是限制该服务拥有的 cap,也就是不在这个列表里的 cap 都会被去掉。要想添加一个 cap,正确的做法是

AmbientCapabilities=CAP_NET_BIND_SERVICE

这样你的 frps 就可以绑定 1~1023 这些端口 (Privileged Ports) 了

<!-- gh-comment-id:554716532 --> @iBug commented on GitHub (Nov 17, 2019): > 详细看了下,使用 systemd 的发行版可以使用 `CapabilityBoundingSet =` 来设置这个服务的一些能力 这里有点错误,`CapabilityBoundingSet` 是限制该服务拥有的 cap,也就是不在这个列表里的 cap 都会被去掉。要想添加一个 cap,正确的做法是 ``` AmbientCapabilities=CAP_NET_BIND_SERVICE ``` 这样你的 frps 就可以绑定 1~1023 这些端口 (Privileged Ports) 了
Author
Owner

@deadlineOvO commented on GitHub (Nov 17, 2019):

详细看了下,使用 systemd 的发行版可以使用 CapabilityBoundingSet = 来设置这个服务的一些能力

这里有点错误,CapabilityBoundingSet 是限制该服务拥有的 cap,也就是不在这个列表里的 cap 都会被去掉。要想添加一个 cap,正确的做法是

AmbientCapabilities=CAP_NET_BIND_SERVICE

这样你的 frps 就可以绑定 1~1023 这些端口 (Privileged Ports) 了

是这个样子的啊

<!-- gh-comment-id:554747659 --> @deadlineOvO commented on GitHub (Nov 17, 2019): > > 详细看了下,使用 systemd 的发行版可以使用 `CapabilityBoundingSet =` 来设置这个服务的一些能力 > > 这里有点错误,`CapabilityBoundingSet` 是限制该服务拥有的 cap,也就是不在这个列表里的 cap 都会被去掉。要想添加一个 cap,正确的做法是 > > ``` > AmbientCapabilities=CAP_NET_BIND_SERVICE > ``` > > 这样你的 frps 就可以绑定 1~1023 这些端口 (Privileged Ports) 了 是这个样子的啊
Author
Owner

@LHANDRH commented on GitHub (Dec 6, 2019):

详细看了下,使用 systemd 的发行版可以使用 CapabilityBoundingSet = 来设置这个服务的一些能力

这里有点错误,CapabilityBoundingSet 是限制该服务拥有的 cap,也就是不在这个列表里的 cap 都会被去掉。要想添加一个 cap,正确的做法是

AmbientCapabilities=CAP_NET_BIND_SERVICE

这样你的 frps 就可以绑定 1~1023 这些端口 (Privileged Ports) 了

是这个样子的啊

放在 [Service] 段下。
我粘个完整的方便后面的人看:

[Unit]
Description=Frp Server Service
After=network.target

[Service]
Type=simple
User=nobody
Restart=on-failure
RestartSec=5s
ExecStart=/usr/bin/frps -c /etc/frp/frps.ini
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target
<!-- gh-comment-id:562502621 --> @LHANDRH commented on GitHub (Dec 6, 2019): > > > 详细看了下,使用 systemd 的发行版可以使用 `CapabilityBoundingSet =` 来设置这个服务的一些能力 > > > > > > 这里有点错误,`CapabilityBoundingSet` 是限制该服务拥有的 cap,也就是不在这个列表里的 cap 都会被去掉。要想添加一个 cap,正确的做法是 > > ``` > > AmbientCapabilities=CAP_NET_BIND_SERVICE > > ``` > > > > > > 这样你的 frps 就可以绑定 1~1023 这些端口 (Privileged Ports) 了 > > 是这个样子的啊 放在 [Service] 段下。 我粘个完整的方便后面的人看: ``` [Unit] Description=Frp Server Service After=network.target [Service] Type=simple User=nobody Restart=on-failure RestartSec=5s ExecStart=/usr/bin/frps -c /etc/frp/frps.ini AmbientCapabilities=CAP_NET_BIND_SERVICE [Install] WantedBy=multi-user.target ```
Author
Owner

@deadlineOvO commented on GitHub (Dec 6, 2019):

详细看了下,使用 systemd 的发行版可以使用 CapabilityBoundingSet = 来设置这个服务的一些能力

这里有点错误,CapabilityBoundingSet 是限制该服务拥有的 cap,也就是不在这个列表里的 cap 都会被去掉。要想添加一个 cap,正确的做法是

AmbientCapabilities=CAP_NET_BIND_SERVICE

这样你的 frps 就可以绑定 1~1023 这些端口 (Privileged Ports) 了

是这个样子的啊

放在 [Service] 段下。
我粘个完整的方便后面的人看:

[Unit]
Description=Frp Server Service
After=network.target

[Service]
Type=simple
User=nobody
Restart=on-failure
RestartSec=5s
ExecStart=/usr/bin/frps -c /etc/frp/frps.ini
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

不过那个 5s 究竟是为了什么?

<!-- gh-comment-id:562513564 --> @deadlineOvO commented on GitHub (Dec 6, 2019): > > > > 详细看了下,使用 systemd 的发行版可以使用 `CapabilityBoundingSet =` 来设置这个服务的一些能力 > > > > > > > > > 这里有点错误,`CapabilityBoundingSet` 是限制该服务拥有的 cap,也就是不在这个列表里的 cap 都会被去掉。要想添加一个 cap,正确的做法是 > > > ``` > > > AmbientCapabilities=CAP_NET_BIND_SERVICE > > > ``` > > > > > > > > > 这样你的 frps 就可以绑定 1~1023 这些端口 (Privileged Ports) 了 > > > > > > 是这个样子的啊 > > 放在 [Service] 段下。 > 我粘个完整的方便后面的人看: > > ``` > [Unit] > Description=Frp Server Service > After=network.target > > [Service] > Type=simple > User=nobody > Restart=on-failure > RestartSec=5s > ExecStart=/usr/bin/frps -c /etc/frp/frps.ini > AmbientCapabilities=CAP_NET_BIND_SERVICE > > [Install] > WantedBy=multi-user.target > ``` 不过那个 5s 究竟是为了什么?
Author
Owner

@deadlineOvO commented on GitHub (Dec 7, 2019):

详细看了下,使用 systemd 的发行版可以使用 CapabilityBoundingSet = 来设置这个服务的一些能力

这里有点错误,CapabilityBoundingSet 是限制该服务拥有的 cap,也就是不在这个列表里的 cap 都会被去掉。要想添加一个 cap,正确的做法是

AmbientCapabilities=CAP_NET_BIND_SERVICE

这样你的 frps 就可以绑定 1~1023 这些端口 (Privileged Ports) 了

看了下 文档 ,事实上使用 CapabilityBoundingSet 也可以增加 cap ,不过 CapabilityBoundingSet 也可以做到删减 cap

<!-- gh-comment-id:562839735 --> @deadlineOvO commented on GitHub (Dec 7, 2019): > > 详细看了下,使用 systemd 的发行版可以使用 `CapabilityBoundingSet =` 来设置这个服务的一些能力 > > 这里有点错误,`CapabilityBoundingSet` 是限制该服务拥有的 cap,也就是不在这个列表里的 cap 都会被去掉。要想添加一个 cap,正确的做法是 > > ``` > AmbientCapabilities=CAP_NET_BIND_SERVICE > ``` > > 这样你的 frps 就可以绑定 1~1023 这些端口 (Privileged Ports) 了 看了下 [文档](https://www.freedesktop.org/software/systemd/man/systemd.exec.html#CapabilityBoundingSet=) ,事实上使用 `CapabilityBoundingSet` 也可以增加 cap ,不过 `CapabilityBoundingSet` 也可以做到删减 cap
Author
Owner

@668168 commented on GitHub (Dec 14, 2020):

详细看了下,使用 systemd 的发行版可以使用 CapabilityBoundingSet = 来设置这个服务的一些能力

这里有点错误,CapabilityBoundingSet 是限制该服务拥有的 cap,也就是不在这个列表里的 cap 都会被去掉。要想添加一个 cap,正确的做法是

AmbientCapabilities=CAP_NET_BIND_SERVICE

这样你的 frps 就可以绑定 1~1023 这些端口 (Privileged Ports) 了

是这个样子的啊

放在 [Service] 段下。
我粘个完整的方便后面的人看:

[Unit]
Description=Frp Server Service
After=network.target

[Service]
Type=simple
User=nobody
Restart=on-failure
RestartSec=5s
ExecStart=/usr/bin/frps -c /etc/frp/frps.ini
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

特意登陆表示感谢。
首先您提供了root cause的关键解法。
我还在困惑这句应该放在哪里生效,
AmbientCapabilities=CAP_NET_BIND_SERVICE
您又贴了完整code。

希望我这个无用的感谢信息没有给大家造成困扰。

<!-- gh-comment-id:744357737 --> @668168 commented on GitHub (Dec 14, 2020): > > > > 详细看了下,使用 systemd 的发行版可以使用 `CapabilityBoundingSet =` 来设置这个服务的一些能力 > > > > > > > > > 这里有点错误,`CapabilityBoundingSet` 是限制该服务拥有的 cap,也就是不在这个列表里的 cap 都会被去掉。要想添加一个 cap,正确的做法是 > > > ``` > > > AmbientCapabilities=CAP_NET_BIND_SERVICE > > > ``` > > > > > > > > > 这样你的 frps 就可以绑定 1~1023 这些端口 (Privileged Ports) 了 > > > > > > 是这个样子的啊 > > 放在 [Service] 段下。 > 我粘个完整的方便后面的人看: > > ``` > [Unit] > Description=Frp Server Service > After=network.target > > [Service] > Type=simple > User=nobody > Restart=on-failure > RestartSec=5s > ExecStart=/usr/bin/frps -c /etc/frp/frps.ini > AmbientCapabilities=CAP_NET_BIND_SERVICE > > [Install] > WantedBy=multi-user.target > ``` 特意登陆表示感谢。 首先您提供了root cause的关键解法。 我还在困惑这句应该放在哪里生效, AmbientCapabilities=CAP_NET_BIND_SERVICE 您又贴了完整code。 希望我这个无用的感谢信息没有给大家造成困扰。
Author
Owner

@buptzyf commented on GitHub (Sep 24, 2021):

详细看了下,使用 systemd 的发行版可以使用 CapabilityBoundingSet = 来设置这个服务的一些能力

这里有点错误,CapabilityBoundingSet 是限制该服务拥有的 cap,也就是不在这个列表里的 cap 都会被去掉。要想添加一个 cap,正确的做法是

AmbientCapabilities=CAP_NET_BIND_SERVICE

这样你的 frps 就可以绑定 1~1023 这些端口 (Privileged Ports) 了

是这个样子的啊

放在 [Service] 段下。
我粘个完整的方便后面的人看:

[Unit]
Description=Frp Server Service
After=network.target

[Service]
Type=simple
User=nobody
Restart=on-failure
RestartSec=5s
ExecStart=/usr/bin/frps -c /etc/frp/frps.ini
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

树莓派 ubuntu16 下,以非root用户登录,未解决问题

更新
成功了,解决问题了
ExecStart=/usr/bin/frps -c /etc/frp/frps.ini,这里frpc的路径不能放在某个用户目录下,比如 /home/user3/frpc/

<!-- gh-comment-id:926280152 --> @buptzyf commented on GitHub (Sep 24, 2021): > > > > 详细看了下,使用 systemd 的发行版可以使用 `CapabilityBoundingSet =` 来设置这个服务的一些能力 > > > > > > > > > 这里有点错误,`CapabilityBoundingSet` 是限制该服务拥有的 cap,也就是不在这个列表里的 cap 都会被去掉。要想添加一个 cap,正确的做法是 > > > ``` > > > AmbientCapabilities=CAP_NET_BIND_SERVICE > > > ``` > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > 这样你的 frps 就可以绑定 1~1023 这些端口 (Privileged Ports) 了 > > > > > > 是这个样子的啊 > > 放在 [Service] 段下。 > 我粘个完整的方便后面的人看: > > ``` > [Unit] > Description=Frp Server Service > After=network.target > > [Service] > Type=simple > User=nobody > Restart=on-failure > RestartSec=5s > ExecStart=/usr/bin/frps -c /etc/frp/frps.ini > AmbientCapabilities=CAP_NET_BIND_SERVICE > > [Install] > WantedBy=multi-user.target > ``` 树莓派 ubuntu16 下,以非root用户登录,未解决问题 **更新** 成功了,解决问题了 ExecStart=/usr/bin/frps -c /etc/frp/frps.ini,这里frpc的路径**不能**放在某个用户目录下,比如 /home/user3/frpc/
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/frp#1179
No description provided.