Executing a network connectivity test in the Linux terminal by running ping 8.8.8.8 or ping google.com only to be immediately met with repetitive error lines reading: “ping: sendmsg: Operation not permitted” prevents network diagnostics. In Linux networking architecture, sending ICMP (Internet Control Message Protocol) ECHO_REQUEST packets requires opening raw network sockets (SOCK_RAW). Under POSIX security models, opening raw sockets is restricted to the root superuser or binaries possessing the CAP_NET_RAW capability. Furthermore, local firewall packet filtering engines (such as iptables, nftables, or ufw) inspect outgoing packets at the OUTPUT chain. If firewall rules reject ICMP packets, or if container virtualization (Docker / LXC) drops network capabilities, the Linux kernel’s sendmsg() system call fails with the EPERM (Operation not permitted) error code. This guide outlines how to configure firewall rules and socket capabilities to restore the ping utility.
What Causes ‘ping: sendmsg: Operation not permitted’?
The Linux kernel rejects ICMP socket transmission under several permission and firewall conditions:
- Local Firewall Output Chain Blocking ICMP: An
iptables,nftables, orufwrule configured with a defaultOUTPUT DROPpolicy dropping outbound ICMP traffic. - Missing CAP_NET_RAW Capability or SUID Bit: The
pingbinary lacking the POSIX capability bits required for unprivileged user execution. - Docker / Container Capability Restrictions: Docker containers running without the
--cap-add=NET_RAWsecurity argument. - SELinux or AppArmor Security Enforcements: Security profiles forbidding specific user groups from binding raw network sockets.
- Kernel sysctl Restrictions on Ping Sockets: The
net.ipv4.ping_group_rangesysctl parameter excluding your user account’s group ID (GID).
Method 1: Check and Flush iptables Outgoing Filter Rules
The primary culprit is an outgoing firewall rule blocking ICMP packet transmission.
- Inspect your current
iptablesrules targeting the OUTPUT chain:sudo iptables -L OUTPUT -v -n --line-numbers - Look for rules where the
targetis set to DROP or REJECT matchingprot icmp. - Explicitly allow outbound ICMP ECHO requests by inserting a top-priority rule:
sudo iptables -I OUTPUT 1 -p icmp --icmp-type echo-request -j ACCEPT - Also allow established incoming response packets on the INPUT chain:
sudo iptables -I INPUT 1 -p icmp --icmp-type echo-reply -j ACCEPT sudo iptables -I INPUT 2 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT - Test pinging an external IP:
ping -c 4 1.1.1.1
Method 2: Verify UFW (Uncomplicated Firewall) Configuration
If your system utilizes UFW, ensure default outgoing policies are not set to deny.
- Check UFW status:
sudo ufw status verbose - If the output indicates
Default: deny (outgoing), allow outgoing traffic:sudo ufw default allow outgoing - Verify that UFW rules are not dropping ICMP packets in
/etc/ufw/before.rules:sudo ufw reload
Method 3: Restore CAP_NET_RAW Capabilities on the Ping Binary
Modern Linux distributions use file capabilities instead of legacy SUID root binaries to grant raw socket access.
- Inspect the current capabilities assigned to the
pingbinary:getcap $(which ping) - If the output returns blank, regular users cannot open raw sockets. Assign the required capability:
sudo setcap cap_net_raw+ep $(which ping) - Alternatively, if your system does not support file capabilities, set the SUID bit:
sudo chmod u+s $(which ping) - Test the command as a regular non-root user:
ping -c 4 8.8.8.8
Method 4: Configure Kernel ping_group_range (Sysctl)
Linux allows non-root users to send ping requests without raw socket capabilities via the ping_group_range setting.
- Inspect the current kernel group range:
sysctl net.ipv4.ping_group_range - If it outputs
1 0(disabled), update the range to include all user groups (from GID 0 to 2147483647):sudo sysctl -w net.ipv4.ping_group_range="0 2147483647" - To make this change permanent across reboots, add the line to
/etc/sysctl.conf:echo 'net.ipv4.ping_group_range = 0 2147483647' | sudo tee -a /etc/sysctl.conf sudo sysctl -p
Linux Ping sendmsg Error Diagnostic Matrix
| Environment | Underlying Cause | Target Terminal Fix |
|---|---|---|
| Standard Ubuntu / Debian Desktop | Local firewall dropping outbound ICMP | sudo iptables -I OUTPUT 1 -p icmp -j ACCEPT |
| Non-root user in fresh minimal OS | Missing CAP_NET_RAW capability on binary | sudo setcap cap_net_raw+ep $(which ping) |
| Docker / Kubernetes Container | Container dropped raw network capability | Run container with: –cap-add=NET_RAW |
| Root user works, normal user fails | Restricted net.ipv4.ping_group_range | sudo sysctl -w net.ipv4.ping_group_range=”0 2147483647″ |
Adjusting firewall output policies and restoring socket capabilities permanently resolves ‘sendmsg: Operation not permitted’ in Linux.