Study of netstat Command
Experiment
Study of netstat Command
๐ฏ Aim
To study and analyze network connections, routing tables, and interface statistics using the netstat command.
๐ Objective
By the end of this experiment, students will be able to:
- View active network connections
- Identify listening ports and services
- Display routing tables
- Analyze network statistics
๐ Theory
The netstat (network statistics) command is used to:
- Display active TCP/UDP connections
- Show listening ports
- View routing tables
- Display interface statistics
๐ It is useful for:
- Network monitoring
- Troubleshooting
- Security analysis
⚠️ Note:
netstatis deprecated in modern Linux systems and replaced by thesscommand, but it is still widely used for learning.
๐งพ Syntax
๐ง Common Options
-
-a→ Show all connections (listening + non-listening) -
-t→ Show TCP connections -
-u→ Show UDP connections -
-l→ Show listening ports -
-n→ Show numerical addresses (no DNS resolution) -
-p→ Show process ID and program name -
-r→ Show routing table -
-i→ Show interface statistics
๐งฐ Prerequisites
- Linux system
- Root/sudo privileges (for some options)
๐ฌ Procedure & Commands
1️⃣ Display All Connections
2️⃣ Show TCP Connections
3️⃣ Show UDP Connections
4️⃣ Show Listening Ports
5️⃣ Show Numerical Addresses
6️⃣ Show Process Information
7️⃣ Display Routing Table
8️⃣ Display Interface Statistics
9️⃣ Combined Command (Common Use)
๐ Shows:
- TCP & UDP
- Listening ports
- Numeric addresses
- Process details
๐ฅ️ Sample Output
๐ Output Interpretation
| Field | Meaning |
|---|---|
| Proto | Protocol (TCP/UDP) |
| Local Address | Local IP and port |
| Foreign Address | Remote IP and port |
| State | Connection state (LISTEN, ESTABLISHED) |
| PID/Program | Process using the port |
๐ Common States
-
LISTEN→ Waiting for connection -
ESTABLISHED→ Active connection -
TIME_WAIT→ Connection closing -
CLOSE_WAIT→ Waiting to close
๐ Exercises for Students
- Display all active connections on your system.
- Identify which ports are in listening state.
- Find the process using a specific port.
- Display routing table and interpret it.
-
Compare output with
sscommand.
❓ Viva Questions
-
What is
netstatused for? - Difference between TCP and UDP?
- What is a port number?
- What does LISTEN state mean?
-
Why is
netstatbeing replaced byss?
⚠️ Precautions
-
Use
sudocarefully when viewing process details - Large output may be difficult to analyze
-
Prefer
ssin modern systems for performance
✅ Result
The netstat command is a powerful tool for analyzing network connections and system activity, widely used for troubleshooting and monitoring.
Comments
Post a Comment