netstat
is a command-line networking tool, which can be used to show the statistics of networking connections. It’s a must tool for finding the performance problems in Unix/Linux networking.
In this post, I will list the typical usages and most used options of netstat
.
List all the sockets
Use -a
option to list all the sockets, including those in listen
state and also not in listen
state.
Use -l
option to list the sockets in listen
status.
|
List only TCP sockets
Use -t
option to list only the TCP sockets.
|
Find the related process
Use -p
option to show the program name and pid with sockets.
|
Suppose we want to find which process is binding a specific socket.
|
Use pipeline for statistics of networking
With the pipeline, we could combine netstat with other command utilities, like awk
, sort.
Let’s find all the counts for different networking status.
Note:
awk '{print $6}'
: use just the 6th column from output.
tail -n + 2
: remove the first line from output (since it’s header)
Join my Email List for more insights, It's Free!😋