[Feedback on issues] 啥意思?ping都无法正常工作?
Tofloor
poster avatar
137******41
deepin
2025-09-08 21:48
Author

今天偶然访问github不畅,想看看网络可达性,结果发现ping命令居然不能用!?

ping www.baidu.com
ping: socktype: SOCK_RAW
ping: socket: 不允许的操作
ping: => missing cap_net_raw+p capability or setuid?

Reply Favorite View the author
All Replies
执著的灵魂
deepin
2025-09-08 21:55
#1

这个是BUG,要在命令前面加上sudo

Reply View the author
LiuYongzhang
deepin
2025-09-08 22:02
#2

图片.png

Reply View the author
昨夜的星辰
deepin
2025-09-08 22:27
#3

是不是搞错用户组了,怎么ping也要用sudo了……

Reply View the author
治国平天下
deepin
2025-09-09 11:05
#4

切换成root是可以正常PING通的

Reply View the author
xuqi
deepin testing team
2025-09-09 13:49
#5
  • 感谢反馈,该问题研发已经解决修复,稍后会推送更新 ~
Reply View the author
Boggle5923
deepin
2025-09-12 14:02
#6

又搜索了一下,还有更好的方法(最新版本的发行版里面应该都应用了这个,虽然deepin25没有):

有一个控制哪个组的用户可以ping的sysctl:

net.ipv4.ping_group_range

如果这个被设置为“1 0”,就会禁止所有用户创建 SOCK_DGRAM(除非用户为root或者ping拥有 CAP_NET_RAW 的capability)。可以把这个改成“0 2147483647”来允许绝大多数用户发送ping。在 /etc/sysctl.conf里添加这行就可以了:

net.ipv4.ping_group_range = 0	2147483647

给ping设置SUID当然是超过需要地授予权限,不利于系统安全性,但如果只是需要ping的话,CAP_NET_RAW 给的权限也是太大的。所以现在通用的办法一般是“允许这些用户ping”。

参考:

依云的博客 https://blog.lilydjwg.me/2013/10/29/non-privileged-icmp-ping.41390.html

AskUbuntu问题 https://askubuntu.com/questions/1537785/can-no-longer-ping-operation-not-permitted

sysctl配置 https://www.kernel.org/doc/html/latest/networking/ip-sysctl.html#ip-variables

ping_group_range - 2 INTEGERS
Restrict ICMP_PROTO datagram sockets to users in the group range. The default is “1 0”, meaning, that nobody (not even root) may create ping sockets. Setting it to “100 100” would grant permissions to the single group. “0 4294967294” would enable it for the world, “100 4294967294” would enable it for the users, but not daemons.


原回答,仅供参考:


ping需要一个叫 CAP_NET_RAW 的linux capability来使用底层socket(报错里的 SOCK_RAW )。如果ping没有被设置为 CAP_NET_RAW ,它也可以使用 root 权限。

需要修复这个问题,可以登录root用户(或者sudo)执行 setcap cap_net_raw+p /usr/bin/ping

但是一般的linux不都是安装的时候就已经设置了这个capability的吗?这可能是个bug?


怎么deepin论坛的行内代码功能还吞代码的。。。我一个CAP_NET_RAW发出去变成CAP了shocked

Reply View the author