How can I use the ping command in a chroot environment?

$ ping 8.8.8.8
ping: icmp open socket: Operation not permitted

Currently I am using CentOs, but ideally there must be a solution that works in all chrooted environments.

link|improve this question

What happens when you try? – Gilles May 16 '11 at 20:06
i get: "ping: icmp open socket: Operation not permitted" – kamal May 16 '11 at 21:10
feedback

migrated from stackoverflow.com May 16 '11 at 19:45

This question came from our site for professional and enthusiast programmers.

2 Answers

up vote 1 down vote accepted

Under Linux, ping needs to run as root (because it needs to bind a raw IP socket; ordinary users can only do UDP and TCP). It's designed to be setuid root. It looks like your copy in the chroot isn't setuid root. Fix the permissions:

chown root:root /bin/ping; chmod u+srwx,go=rx /bin/ping

Note that there may be other commands in the chroot that need to be setuid (or setgid), in particular su and sudo.

Note that this answers assumes a chroot, not something with more restrictions like a jail.

link|improve this answer
feedback

There shouldn't be a problem using ping or any other part of the gnu tool chain within a chroot, so long as these binaries are present in your path. If these commands cannot be accessed, perhaps you should check your environment variables.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.