Netstat Command
The netstat (network statistics) command is used to display network connections, routing tables, interface statistics, and open ports. It is useful for troubleshooting network issues, monitoring connections, and checking which ports are in use.
- Displays active network connections (TCP & UDP).
- Shows listening ports and open sockets.
- Provides routing table information.
- Displays interface statistics (packet transmission and errors).
- Supports PID-to-process mapping (
-poption). - Can filter results based on protocol (
-tfor TCP,-ufor UDP). - Works with numeric IP addresses (bypassing DNS resolution).
- Useful for firewall auditing and network security monitoring.
netstat [options]netstat- Displays all active TCP connections by default.
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 192.168.1.10:22 203.0.113.5:54321 ESTABLISHED
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
Proto: Protocol (TCP or UDP)Recv-Q/Send-Q: Receive/send queue sizeLocal Address: IP and port of the local machineForeign Address: IP and port of the remote connectionState: Connection state (e.g., LISTEN, ESTABLISHED)
netstat -a- Displays both active and listening TCP and UDP connections.
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 192.168.1.10:22 203.0.113.5:54321 ESTABLISHED
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
udp 0 0 0.0.0.0:68 0.0.0.0:*
- Includes both TCP and UDP connections.
- Shows listening ports and established connections.
netstat -na- Same as
netstat -abut disables hostname resolution, showing IP addresses instead of domain names.
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 192.168.1.10:22 203.0.113.5:54321 ESTABLISHED
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
- Useful when troubleshooting DNS issues.
- Prevents slow output due to hostname resolution.
netstat -t- Displays only TCP connections (no UDP).
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 192.168.1.10:22 203.0.113.5:54321 ESTABLISHED
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
- Filters output to only show TCP-based services.
netstat -u- Displays only UDP connections.
Proto Recv-Q Send-Q Local Address Foreign Address State
udp 0 0 0.0.0.0:68 0.0.0.0:*
udp 0 0 192.168.1.10:123 0.0.0.0:*
- No connection state since UDP is connectionless.
- Useful for monitoring DNS, DHCP, and NTP services.
netstat -l- Displays only listening ports.
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
udp 0 0 0.0.0.0:53 0.0.0.0:*
- Helps identify which services are running and awaiting connections.
netstat -ltun- Displays listening ports (TCP and UDP) with numeric IPs (no hostname resolution).
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
udp 0 0 0.0.0.0:53 0.0.0.0:*
- Useful for firewall rules and security auditing.
netstat -p- Displays which process (PID) is using each connection.
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 192.168.1.10:22 203.0.113.5:54321 ESTABLISHED 1234/sshd
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 5678/nginx
- Helps in detecting malicious or unauthorized processes using the network.
netstat -nltup- Displays listening ports, numeric IPs, and process IDs.
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1234/sshd
udp 0 0 0.0.0.0:53 0.0.0.0:* 2345/dnsmasq
- Useful for firewall management and security audits.