Many times we find that on our server we have a port listening and we do not know which process is executing it.
We are going to see several ways on how to obtain this information.
Netstat:
Bash
netstat -punlt |grep ‘:80’
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2188/apache2- p Shows connections for the specified protocol which can be TCP or UDP
- or List all UDP ports
- t List all TCP ports
- n It shows us the port number
- to Show sockets that are listening.
lsof
text
lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
apache2 2188 root 4u IPv4 8672 TCP *:www (LISTEN)
apache2 7599 www-data 4u IPv4 8672 TCP *:www (LISTEN)
FUSER:
text
fuser -n tcp 80
80/tcp: 2188 11996 12219 17687 25366 31871 3416 3804 4291 5570 5656 5657 7634 10528 10877 10929 10932As we can see, we obtain the PID of the process in all the examples. Using a PS we can see all the processes that are running on that port.
text
ps -fea |grep 2188
root 2188 1 0 Jun28 ? 01:39:49 /usr/sbin/apache2 -k start
www-data 11996 2188 0 22:19 ? 00:00:00 /usr/sbin/apache2 -k startAll the best. rokitoh!
Comments