java.net.BindException: Permission denied as root

12,805

I managed to fix the problem. I had Hands Off! installed on my system, but disabled all rules from the menu bar. The KnockKnockServer still couldn't open the port. Now I have uninstalled Hands Off! completely, and can open ports as usual.

It is still a bit surprising, because I was always able to open the same socket port with nc -l 4444 and with a C program, but not from Java. But at the same time, Hands Off didn't ask me if I want to allow my KnockKnockServer to open a port.

I will follow up with the Hands Off support, maybe they can help.

Thanks, Regards Benedikt

Share:
12,805
Benedikt Köppel
Author by

Benedikt Köppel

I'm the Founder and CTO of Locatee. We help large organizations optimize their workspace with big data technology. Learn more here https://www.locatee.ch/video. We are hiring! If you are skilled in Java, Spring, Hibernate, Data Science, JavaScript or AngularJS, please shoot me a line.

Updated on June 04, 2022

Comments

  • Benedikt Köppel
    Benedikt Köppel almost 2 years

    I'm following Oracle's ServerSide Socket tutorial at http://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html. I use the source as they provide it:

    However, when I try to run the KnockKnockServer, I get an IOException and then the server prints

    Could not listen on port: 4444.
    

    I added a e.printStackTrace() in the IOException catch block, and get:

    [beni@mackerel:~]$ \sudo java KnockKnockServer
    Creating socket
    Could not listen on port: 4444.
    java.net.BindException: Permission denied
        at java.net.PlainSocketImpl.socketBind(Native Method)
        at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:383)
        at java.net.ServerSocket.bind(ServerSocket.java:328)
        at java.net.ServerSocket.<init>(ServerSocket.java:194)
        at java.net.ServerSocket.<init>(ServerSocket.java:106)
        at KnockKnockServer.main(KnockKnockServer.java:41)
    

    Notice, I'm running it as root and try to open port 4444. Why do I still get a Permission denied error?

  • Benedikt Köppel
    Benedikt Köppel over 11 years
    No, the port is not in use. netstat -a | grep 4444 returns nothing.
  • Benedikt Köppel
    Benedikt Köppel over 11 years
    I run this on Mac OS X 10.7.4. I am not aware that there is SELinux here.
  • user207421
    user207421 over 11 years
    If the port was in use you would get a different exception message.