Allowing ping for httpd CGI scripts

— door Evert Mouw


I use thttpd to run CGI scripts. One script uses the ping command to check the availability of another host.

Diagram showing how CGI handles web requests. By Pluke (2012). Public Domain. Source: Wikimedia Commons.

Unfortunately, SELinux does not allow raw ip packets to be created from a CGI script. Such scripts run in the httpd_sys_script_t security context.

You can see this when sending the output of the ping command to the remote host, e.g. from another box:

(Or use curl or whatever you like instead of elinks.)

Then you will see something like ping: recvmsg: Permission denied. Basically, the ping answer (echo message) is blocked by SELinux.

After creating custom modules, the audit.log file shows no denied actions, so it is not clear how to solve this.

Tried without avail

I have tried a few things that would make sense.

You can see the denied stuff using, e.g.:

Even after using audit2allow to create and install custom policy modules, and getting rid of all denied lines from the audit.log, SELinux still gets in the way. The ping: recvmsg: Permission denied error still shows up.

So, all this just allows to use the ping command. The return packets are still blocked.


As a workaround, you can use a permissive domain, so SELinux is set to the permissive mode just for the httpd_sys_script_t security context.

Command to execute:

If you still get an error like this:

then you might try to wait for a while before trying again… Somehow after a night’s sleep, it suddenly worked for me