Skip to content
Advertisement

Network interface: you don’t have permission to capture on that device (socket: Operation not permitted)

Currently I’m writing a small project that views the local bandwidth. I installed the package and implemented the code that’s available on the pcap4j site just to try it out like so:

JavaScript

Once run I get this error:

JavaScript

It makes sense that I can sniff any packets since I’m running it as a non-root user. I tried to fix this by using a solution like this but ultimately it didn’t work. I know this should be possible, since programs like Wireshark also need you to log in as a root user in order to look at all the packets. Does anybody know what can fix this? Obviously I could run my IDE as root but that just seems unnecessary. I’m running this on Manjaro Linux.

Advertisement

Answer

I fixed it. After further investigation I figured out that the file I was trying to add permissions to was within my java-8-openjdk folder, but my project uses java-11-openjdk. So I set the permissions for the correct executable and it now works. Changing the permissions can be done by logging in as root in a terminal and executing: setcap cap_net_raw,cap_net_admin=eip /path/to/java

Advertisement