linux/netstat

Display Network Statistics

Show network connections, routing tables, interface statistics, and listening ports.

network
monitoring
ports
connections
linux

Command

netstat

Explanation

The `netstat` (network statistics) command is used for monitoring network connections and performance. It can show which ports are listening, what processes are using them, and the current routing table. Modern systems use `ss` as its replacement due to faster performance and better formatting.

Common Use Cases

  • Identify which ports are in use
  • Monitor open TCP/UDP connections
  • Check network routing tables

Best Practices

  • Use `ss -tulnp` for faster and modern output
  • Combine with `grep` to filter specific ports or IPs

Common Mistakes to Avoid

  • Forgetting `sudo` when showing process details
  • Using `netstat` on systems without net-tools

Troubleshooting

Problem: netstat command not found

Solution: Install net-tools: `sudo apt install net-tools`.

Problem: Cannot see process info

Solution: Run with `sudo` to show PID and program names.

Examples

Show active listening ports with process info

netstat -tulnp

Display routing table

netstat -r