Home > Bash, Linux > How to figure out which process is listening on a specific port

How to figure out which process is listening on a specific port

This website explained it:

http://analysisandreview.com/troubleshooting/what-process-is-listening-on-a-port/

Let’s say we want to find our what process is tied to port 53.

First, use the following command to find if the port is is use or not

netstat -an | grep 53

#Then, use the following command to find which process is using the port

fuser -n tcp 53

This will return something like ’53/tcp: 5006′.

it shows pid.

After that, we can find the full process information.

ps -ef | grep 9113

If you know shell you can use the below in a shell script to put all these step together

#!/bin/sh
status=`netstat -an |grep $1`
if [ "$status" == "" ]; then
echo “port $1 is free”
exit
fi
ps -ef |grep `fuser -n tcp $1`

Or if you’re running linux download lsof

lsof -i :53

or

lsof -i :1226

Or you and use grep

lsof | grep [process name]
Categories: Bash, Linux Tags:
  1. No comments yet.
  1. No trackbacks yet.