Linux Terminal Command: netstat

The netstat command is an essential tool in Network Utilities. In this tutorial, we will explore what netstat does, look at everyday examples, and cover advanced options to supercharge your command-line workflow.


Concept & Explanation

The netstat command displays active TCP/UDP connections, routing tables, and interface statistics. It is legacy and replaced by ss on modern systems.


Common Options & Syntax

netstat [options] [arguments]

Here are the most common flags used with netstat:


1. Interactive Example (Simple)

Here is how most people run the command:

# Example
netstat -a

What it does: Lists all active network sockets and listening ports.


2. Power-User Example (Advanced)

For scripting and advanced diagnostics, use this configuration:

# Advanced
sudo netstat -tulpn

What it does: Lists active TCP (-t) and UDP (-u) listening ports (-l) with PIDs (-p) and numeric addresses (-n).


⚙️ Warning & Common Pitfalls

[!WARNING] netstat is slow because it reads /proc/net/ tables directly. Use ss on modern Linux servers.


Here are some related posts on cli_tty1 you might want to check out: