unixubuntuport

Can't listen on port 80 with my server


Very new on this kind of issue, i am trying to launch a server on the port 80 (it's important to me to use this specific port).

It's fails, but it works on other ports (even < 1024 when i am root, but still fail on the port 80).

I probably have something running on the port 80, i would like to identify it in order to change its listening port.

I saw this cmd can help to see the state of a specific port: netstat -ano|grep 80|grep LISTEN but i am not sure tu understand well the result.

Here is what i get:

tcp        0      0 127.0.0.1:28017         0.0.0.0:*               LISTEN      off (0.00/0/0)
tcp6       0      0 :::80                   :::*                    LISTEN      off (0.00/0/0)
unix  2      [ ACC ]     STREAM     LISTENING     8805     /tmp/mongodb-27017.sock
unix  2      [ ACC ]     STREAM     LISTENING     13112    /home/me/.pulse/04d802bb34ddb9da49b1f9060000000b-runtime/native

I read on the line 2 that the port 80 seems to be not listening, but don't understand further.

UPDATE:

sudo lsof -i :80

COMMAND    PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
apache2   1107     root    4u  IPv6   7630      0t0  TCP *:http (LISTEN)
apache2   1131 www-data    4u  IPv6   7630      0t0  TCP *:http (LISTEN)
apache2   1132 www-data    4u  IPv6   7630      0t0  TCP *:http (LISTEN)
apache2   1133 www-data    4u  IPv6   7630      0t0  TCP *:http (LISTEN)
apache2   1134 www-data    4u  IPv6   7630      0t0  TCP *:http (LISTEN)
apache2   1136 www-data    4u  IPv6   7630      0t0  TCP *:http (LISTEN)
ubuntu-ge 2095     me    7u  IPv4  82145      0t0  TCP me-Ubuntu.local:43345->mulberry.canonical.com:http (CLOSE_WAIT)

Thanks (i am using ubuntu) !


Solution

  • If this is Linux (and perhaps some other UNIXes as well, though not MacOS), try running the following:

    sudo netstat -lnp
    

    You'll get output similar to the following:

    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name   
    ...
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN     26156/apache2       
    ...
    

    I'll list the interesting parts:

    You basically want to to make sure the program mentioned above isn't running (e.g., in my case, I'd have to shutdown the apache2 daemon, and configure the OS to not automatically start it up on next boot).

    On the other hand, if you just want to get this fixed quickly, you can kill the process:

    kill -9 <pid>
    

    In my example:

    kill -9 26156
    

    The problem will of course return the next time you reboot, or someone starts up that service.