Linux netstat Command — Legacy Network Monitoring and Troubleshooting¶
The
netstat(Network Statistics) command is a classic Linux networking utility used to display active network connections, listening ports, routing tables, interface statistics, multicast memberships, and protocol statistics. Although modern Linux distributions recommend using thesscommand for socket information and theipcommand for routing and interface management,netstatremains widely used on legacy systems and is still encountered in enterprise environments, documentation, and interview questions. Every Linux administrator, DevOps engineer, Cloud Architect, Platform Engineer, Site Reliability Engineer (SRE), and Network Engineer should understandnetstat.
Learning Path¶
Course Progress
What You'll Learn¶
After completing this lesson, you'll be able to:
- Understand the
netstatcommand - Display active network connections
- View listening ports
- Display routing tables
- Monitor interface statistics
- Compare
netstatwithss - Troubleshoot Linux networking
Prerequisites¶
Complete:
Why Learn netstat?¶
Although newer Linux systems recommend:
many enterprise environments still use:
You'll frequently encounter it in:
- Legacy Linux Servers
- Interview Questions
- Documentation
- Troubleshooting Guides
- Older Automation Scripts
Understanding netstat helps you work confidently across both modern and legacy environments.
What is netstat?¶
netstat stands for:
It displays:
- Active Connections
- Listening Ports
- Routing Tables
- Network Interfaces
- Protocol Statistics
- Process Information
Package¶
On many Linux distributions:
is provided by:
Example installation:
Ubuntu/Debian
RHEL/CentOS
Basic Syntax¶
Examples:
Display Active Connections¶
Shows:
- Transmission Control Protocol (TCP) Connections
- User Datagram Protocol (UDP) Connections
- Unix Sockets
Display TCP Connections¶
Display UDP Connections¶
Display Listening Ports¶
Shows services waiting for incoming connections.
Display TCP Listening Ports¶
Display UDP Listening Ports¶
Display All Listening Ports¶
Meaning:
| Option | Purpose |
|---|---|
-t | TCP |
-u | UDP |
-l | Listening |
-n | Numeric Output |
Example output:
Display Process Information¶
Example:
Display Numeric Addresses¶
Prevents hostname resolution.
Benefits:
- Faster Output
- Easier Troubleshooting
Display Routing Table¶
Equivalent modern command:
Example:
Display Interface Statistics¶
Displays:
- RX Packets
- TX Packets
- Errors
- Dropped Packets
Modern alternative:
Display Protocol Statistics¶
Displays:
- TCP Statistics
- UDP Statistics
- Internet Control Message Protocol (ICMP) Statistics
- Internet Protocol (IP) Statistics
Useful for performance analysis.
Display Multicast Groups¶
Shows multicast memberships.
Display Unix Domain Sockets¶
Used for:
- Docker
- Databases
- Local Inter-Process Communication (IPC)
Common TCP States¶
Typical output includes:
- LISTEN
- ESTABLISHED
- SYN_SENT
- SYN_RECV
- FIN_WAIT_1
- FIN_WAIT_2
- CLOSE_WAIT
- LAST_ACK
- TIME_WAIT
These states help troubleshoot TCP connectivity.
Enterprise Example¶
Production Web Server:
Administrator checks:
Questions answered:
- Is SSH running?
- Is HTTPS listening?
- Which process owns port 443?
- Are required services active?
Cloud Perspective¶
Legacy cloud virtual machines may still use:
to verify:
- Open Ports
- Running Services
- Listening Applications
- Load Balancer Connectivity
Kubernetes Perspective¶
Older Kubernetes worker nodes may use:
to inspect:
- kubelet
- kube-proxy
- Container Runtime
- NodePort Services
Although ss is preferred, many operational guides still reference netstat.
Linux Perspective¶
Display listening ports.
Display process information.
Display routing table.
Display protocol statistics.
netstat vs ss¶
| netstat | ss |
|---|---|
| Older Utility | Modern Utility |
| Part of net-tools | Part of iproute2 |
| Slower | Faster |
| Legacy Systems | Modern Linux |
| Still Widely Known | Recommended for Production |
netstat vs ip¶
| netstat | ip |
|---|---|
| Routing Information | Routing Management |
| Interface Statistics | Interface Configuration |
| Legacy Tool | Modern Tool |
| Limited Configuration | Full Network Management |
Common netstat Commands¶
| Command | Purpose |
|---|---|
netstat | Display connections |
netstat -t | TCP connections |
netstat -u | UDP connections |
netstat -tuln | Listening ports |
netstat -tulnp | Listening ports with processes |
netstat -r | Routing table |
netstat -i | Interface statistics |
netstat -s | Protocol statistics |
netstat -x | Unix sockets |
Hands-on Lab¶
Task 1¶
Display active connections.
Task 2¶
Display listening ports.
Task 3¶
Display process information.
Task 4¶
Display routing table.
Task 5¶
Display protocol statistics.
Task 6¶
Display interface statistics.
Task 7¶
Compare output from:
and
Identify the differences in speed, formatting, and available information.
Task 8¶
Create a troubleshooting checklist using:
netstatssippingtraceroute
Production Troubleshooting¶
Problem:
Step 1
↓
Is the application listening?
↓
Yes
↓
Check:
↓
Correct Route?
↓
Yes
↓
Check:
↓
Check:
This approach helps isolate whether the issue is related to the application, routing, or network connectivity.
Common Mistakes¶
❌ Using netstat on minimal Linux installations without net-tools.
✅ Install net-tools or use ss instead.
❌ Forgetting sudo for process information.
✅ Use elevated privileges when viewing process ownership.
❌ Relying only on netstat for routing changes.
✅ Use the ip command for configuration tasks.
❌ Confusing listening sockets with active connections.
✅ Use appropriate options such as -l and -t.
❌ Ignoring protocol statistics.
✅ Review netstat -s when troubleshooting network performance.
Best Practices¶
- Prefer
ssandipon modern Linux systems. - Learn
netstatbecause it is common in legacy environments. - Always use numeric output during troubleshooting.
- Verify which process owns a listening port.
- Compare routing information using both
netstatandip. - Use protocol statistics to investigate network issues.
- Update legacy automation scripts to use modern tools where practical.
Interview Questions¶
Beginner¶
- What is the
netstatcommand? - How do you display listening ports?
- How do you display the routing table?
- What package provides
netstat?
Intermediate¶
- Compare
netstatandss. - Compare
netstatandip. - How do you display protocol statistics?
- How do you determine which process owns a network port?
Architect Level¶
- Explain how you would troubleshoot a production server using
netstat. - Why has
netstatlargely been replaced byss? - How would you modernize a legacy monitoring environment that relies on
netstat?
Summary¶
In this lesson, you learned:
- The
netstatcommand - Active Network Connections
- Listening Ports
- Routing Tables
- Interface Statistics
- Protocol Statistics
- Unix Domain Sockets
- Legacy Network Diagnostics
Although netstat is considered a legacy networking utility, it remains valuable for understanding older Linux systems, enterprise environments, and historical documentation. Modern Linux distributions recommend using ss for socket information and ip for interface and routing management, but familiarity with netstat remains an important skill for Linux professionals.
Key Takeaways¶
netstatis a legacy network monitoring tool.- Use
netstat -tulnto display listening ports. - Use
sudo netstat -tulnpto identify the owning process. - Use
netstat -rto display routing information. - Use
netstat -sto view protocol statistics. - Modern Linux systems recommend
ssandip, butnetstatremains common on older systems and in documentation.
What's Next?¶
In the next lesson, you'll learn about tcpdump.
You'll explore:
- What
tcpdumpis - Packet Capture
- Network Traffic Analysis
- Packet Filtering
- Protocol Inspection
- Troubleshooting Network Issues
- Production Packet Analysis
By the end of the lesson, you'll understand how to capture, inspect, and analyse network packets at a low level, making tcpdump one of the most valuable tools for Linux network troubleshooting and security investigations.