netstat
networkingLinux/Unix
The netstat command is one of the most frequently used commands in Linux/Unix-like operating systems. netstat Display network connections, routing tables, interface statistics, masquerade connections, and multicast memberships
Quick Reference
Command Name:
netstat
Category:
networking
Platform:
Linux/Unix
Basic Usage:
netstat [options] [arguments]
Common Use Cases
Syntax
netstat [options]
Options
Option | Description |
---|---|
-a, --all |
Show all sockets (default: connected) |
-A, --protocol=FAMILY |
Show sockets of specified protocol family (e.g., inet, unix) |
-c, --continuous |
Continuous listing |
-C, --cache |
Show routing cache instead of FIB |
-e, --extend |
Show detailed information |
-F, --fib |
Show Forwarding Information Base (default) |
-g, --groups |
Show multicast group memberships |
-i, --interfaces |
Show network interfaces |
-l, --listening |
Show only listening sockets |
-M, --masquerade |
Show masqueraded connections |
-n, --numeric |
Don't resolve names |
-N, --symbolic |
Resolve hardware names |
-o, --timers |
Show timers |
-p, --programs |
Show PID/Program name for sockets |
-r, --route |
Show routing table |
-s, --statistics |
Show networking statistics (like SNMP) |
-t, --tcp |
Show only TCP sockets |
-u, --udp |
Show only UDP sockets |
-v, --verbose |
Be verbose |
-V, --version |
Display version information and exit |
-w, --raw |
Show only RAW sockets |
-x, --unix |
Show only Unix domain sockets |
-Z, --context |
Show SELinux security context for sockets |
Output Symbols in Netstat:
Symbol | Meaning |
---|---|
Proto | Protocol (TCP, UDP, etc.) |
Recv-Q | Data received by the application but not yet read |
Send-Q | Data sent by the application but not yet acknowledged by the remote host |
Local Address | Local address and port number |
Foreign Address | Remote address and port number |
State | The state of the socket (ESTABLISHED, LISTEN, etc.) |
PID/Program name | Process ID and name of the program using the socket |
Common Socket States:
State | Description |
---|---|
ESTABLISHED | The socket has an established connection |
SYN_SENT | The socket is actively attempting to establish a connection |
SYN_RECV | A connection request has been received from the network |
FIN_WAIT1 | The socket is closed, and the connection is shutting down |
FIN_WAIT2 | Connection is closed, and the socket is waiting for a shutdown from the remote end |
TIME_WAIT | The socket is waiting after close to handle packets still in the network |
CLOSE | The socket is not being used |
CLOSE_WAIT | The remote end has shut down, waiting for the socket to close |
LAST_ACK | The remote end has shut down, and the socket is closed. Waiting for acknowledgement |
LISTEN | The socket is listening for incoming connections |
CLOSING | Both sockets are shut down but we still don't have all our data sent |
UNKNOWN | The state of the socket is unknown |
Examples
How to Use These Examples
The examples below show common ways to use the netstat
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
# Basic Examples Basic
netstat