Using The Netstat Command To Identify Which Ports A Process Uses
Using The Netstat Command To Identify Which Ports A Process Uses
Topic
You can use the netstat command to view programs that are running on specific ports though the following
methods:
Identify the port protocol control block and the corresponding process.
Identify the PID of the process's connection.
1. Find the kernel address of the protocol control blocks associated with each connection, by using the
netstat command with the -A option.
For example, to view the control blocks that are used for programs listening on the loopback address
127.0.0.1, you would type the following command:
The first column of the output contains the protocol control block identifier.
2. Find the process that owns that protocol control block, by using the fstat command and filtering for
specified protocol control block identifier.
For example:
In this example, slapd, the OpenLDAP daemon, is the process is listening on 127.0.0.1 port 389 tcp.
For example:
In this example, there are several SSH connections to this system. Each connection is connected to the same
local port, port 22 TCP
To view the instances of sshd that are running, type the following command:
The output would appear similar to the following, where PID 15217 is the root process and the rest are the
child processes.
To view which processes are responsible for the connection between 192.0.2.203 port 22 and 192.0.2.39
port 1447 first identify the control block structure, by typing the following command:
You can use this to trace the block back to the PID, by typing the following command:
This indicates that PID 9332 is the connection between 192.0.2.203 port 22 and 192.0.2.39 port 1447.
Note: If this example had contained multiple connections between 192.0.2.203 and 192.0.2.39, the example
grep filter would have also had to contain the port number in addition to the address.