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: netstat is deprecated in modern Linux systems and replaced by the ss command, but it is still widely used for learning.


๐Ÿงพ Syntax

netstat [options]

๐Ÿ”ง 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

netstat -a

2️⃣ Show TCP Connections

netstat -t

3️⃣ Show UDP Connections

netstat -u

4️⃣ Show Listening Ports

netstat -l

5️⃣ Show Numerical Addresses

netstat -n

6️⃣ Show Process Information

sudo netstat -p

7️⃣ Display Routing Table

netstat -r

8️⃣ Display Interface Statistics

netstat -i

9️⃣ Combined Command (Common Use)

netstat -tulnp

๐Ÿ‘‰ Shows:

  • TCP & UDP
  • Listening ports
  • Numeric addresses
  • Process details

๐Ÿ–ฅ️ Sample Output

tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 1234/apache2

๐Ÿ” Output Interpretation

FieldMeaning
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

  1. Display all active connections on your system.
  2. Identify which ports are in listening state.
  3. Find the process using a specific port.
  4. Display routing table and interpret it.
  5. Compare output with ss command.

❓ Viva Questions

  • What is netstat used for?
  • Difference between TCP and UDP?
  • What is a port number?
  • What does LISTEN state mean?
  • Why is netstat being replaced by ss?

⚠️ Precautions

  • Use sudo carefully when viewing process details
  • Large output may be difficult to analyze
  • Prefer ss in 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

Popular posts from this blog

Networks Lab PCCSL507 Semester 5 KTU CS 2024 Scheme - Dr Binu V P

Analysis of HTTP Protocol using Wireshark

Study and Use of ifconfig Command