Debian - Port 80 is blocked, but I don't know by what

I can't make lighttpd listen to port 80.

~# /etc/init.d/lighttpd start
Starting web server: lighttpd2013-03-16 23:15:02: (network.c.379) can't bind to port:  80 Address already in use
 failed!

Actually I have apache2 installed on my server, too (listening to port 80) but it is not active.

I used netstat / netstat -npl but it wasn't helpful

How can I figure out what is using the port?


Solution 1:

In depsite of people got used to netstat for such kind of operations, it's good to know, that Linux has another great (and, actually superior) networking tool — ss. For e. g., to find out which process has opened port 80 you run it so:

sudo ss -pt state listening 'sport = :80'

so there's no need to pipe through external filters. Surely it has lots more useful knobs, so get yourself familiar with it.

For completeness sake and since recently I came across man fuser, I can also mention:

  • sudo fuser 80/tcp — this one also saves you from tinkering at cut/grep/awk… keep in mind this notation is a short-cut, in case there's an ambiguity, you should use one of namespaces allowed with -n …, like sudo fuser -n tcp 80

  • sudo lsof -n -sTCP:LISTEN -i:80 — was pointed out by @wallenborn. Meanwhile -n is not strictly required it's strongly advised since otherwise it uses DNS resolving which usualy slows down output terribly.

Solution 2:

Address already in use means that another process is already listening on port 80. Only one process can listen on a given port at a time.

To find the process, run as root:

netstat -tnlp | grep -w 80

The offending process will be listed.

Solution 3:

Another option with fewer keystrokes is lsof:

lsof -i :80