Skip to content

ping: socket: Operation not permitted #1012

Closed
@ghost

Description

@ghost

ADMIN EDIT

Solution

echo 'net.ipv4.ping_group_range = 0 2147483647' > /etc/sysctl.d/99-ping.conf
sysctl -p /etc/sysctl.d/99-ping.conf

Read more


Hi there,

It seems for some reason DietPi is set up in a way where a normal user cannot perform a ping operation?

dietpi@DietPi:~$ ping 192.168.88.14
ping: socket: Operation not permitted
dietpi@DietPi:~$ sudo ping 192.168.88.14
PING 192.168.88.14 (192.168.88.14) 56(84) bytes of data.
64 bytes from 192.168.88.14: icmp_seq=1 ttl=64 time=1.05 ms

Is there a special reason for this or is this a bug?

Activity

Fourdee

Fourdee commented on Jun 12, 2017

@Fourdee
Collaborator

@xanview

normal user cannot perform a ping operation

Seems permissions need to be set on the ping binary for underpriv users to run this:
https://www.raspberrypi.org/forums/viewtopic.php?p=874479&sid=679670d4747d3e00e7885a18ac71e7f4#p874479

Fourdee

Fourdee commented on Jun 17, 2017

@Fourdee
Collaborator

Marking as resolved, please reopen if required.

gade-raghav

gade-raghav commented on Aug 18, 2018

@gade-raghav

use the following command.
sudo ping "your ip addr or host name"

Jewsh-S

Jewsh-S commented on Sep 18, 2019

@Jewsh-S

Find the location of the ping binary in case it's not normal using "type ping". Then give it privileges to use as non root user "chmod +s /bin/ping" or "chmod +s /location/of/ping"

MichaIng

MichaIng commented on Sep 19, 2019

@MichaIng
Owner

Or use this one-liner:

sudo chmod 755 $(which ping)

This should be actually the default permissions, however we observed much stranger setups in cases 😄.
EDIT: The binary is world-executable, hence this is not the issue. The missing capabilities for the binary itself when being executes with unprivileged user is, see possible solution below 👍.

jerinisready

jerinisready commented on Dec 26, 2019

@jerinisready

This seems to be working here

sudo setcap 'cap_net_admin,cap_net_raw+ep' $(which ping)
MikeHigginbottom

MikeHigginbottom commented on Jan 13, 2020

@MikeHigginbottom
sudo setcap 'cap_net_admin,cap_net_raw+ep' $(which ping)

This is probably the correct answer.

Doing a sudo ping <host> is probably what the kernel developers intended you to do since it's not really supposed to be run by normal users but it's pretty much considered an everyday tool these days and sudoing every time is a bit of a pain.

Adding the 'setuid' bit with chmod +s /bin/ping is what most Linux distros seem to do but it's a bit of a security concern because it grants ALL the rights of a super user.

The setcap approach grants much more restricted rights by only allowing it the specific capabilities it needs.

MichaIng

MichaIng commented on Jan 13, 2020

@MichaIng
Owner

@MikeHigginbottom
Thanks for explaining this a bid. Yes granting only the specifically required capabilities.

I just checked what is default on Debian:

root@VM-Building:~# getcap /bin/ping
/bin/ping = cap_net_raw+ep

This seems to be sufficient, since I can ping which any unprivileged user. Of course the iputils-ping ships several more feature than performing simple ping, probably for one of those cap_net_admin is required.

MikeHigginbottom

MikeHigginbottom commented on Jan 13, 2020

@MikeHigginbottom

Mmm. Suspect you're right about cap_net_admin. I can ping localhost from my sandbox iputils build on Ubuntu without it.

OT but... Interestingly Ubuntu does the setuid thing rather than using capabilities which is weird considering what you're seeing on Debian. Maybe the Ubuntu devs made a conscious decision to override the Debian choice and use setuid for some reason?

MichaIng

MichaIng commented on Jan 14, 2020

@MichaIng
Owner

@MikeHigginbottom
No idea why Ubuntu handles it differently. Perhaps it is simply a failsafe step to assure that it can do all it needs for all features/options it has. In the end, if you trust the ping binary, and everyone can check the source code, then you can grant it super user permissions. I am just conservative here, also to prevent from bugs, human errors, very unlucky file corruptions or whichever thinkable thing 😉.

datdinhquoc

datdinhquoc commented on May 28, 2020

@datdinhquoc

use the following command.
sudo ping "your ip addr or host name"

using sudo works, but my user is already in 'wheel' group ('sudo' group); i just can't guess out why i need sudo, any ideas?

MichaIng

MichaIng commented on May 29, 2020

@MichaIng
Owner

The sudo/wheel group only allows you to call sudo, but it does not replace the sudo call. Either you need to use sudo or you need to grant the binary itself the capabilities as mentioned here: #1012 (comment)

datdinhquoc

datdinhquoc commented on May 29, 2020

@datdinhquoc

The sudo/wheel group only allows you to call sudo, but it does not replace the sudo call. Either you need to use sudo or you need to grant the binary itself the capabilities as mentioned here: #1012 (comment)

i can ping without sudo now (suggested by Jewsh-S above):
sudo chmod +s /usr/bin/ping
ping google.com

13 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @MikeHigginbottom@Fourdee@gade-raghav@jerinisready@MichaIng

        Issue actions

          ping: socket: Operation not permitted · Issue #1012 · MichaIng/DietPi