WSL2 Unable to ping: Operation not permitted
I love Windows Subsystem for Linux, it gives me all the clean comfort of a bash command line without losing the inconvenience of Windows. At some point, I'm not sure when, I stopped being able to ping things from WSL when not running as root:
ping: socket: Operation not permitted
ping: => missing cap_net_raw+p capability or setuid?
Fortunately, the answer to this is provided by the error, the capability to use raw sockets isn't available to ping running as a normal user. How do we fix this? We use the setcap command. This is commonly found in the 'libcap-progs' package (but things can vary by distribution). The specifics are detailed in the error, so we simply run:
setcap 'cap_net_raw+p' /bin/ping
This will allow the ping program to use this capability as a non-root user. Note, that the command path needs to be an actual path and not a symbolic link, so for me I had to use /usr/bin/ping - where things are will differ by distribution.