Unveiling netstat: A Comprehensive Guide to Network Statistics and Commands

netstat is a network utility tool used to display network statistics and connection information. This tool provides information about various network connections, ports, protocols, and network interfaces. The netstat command is commonly found on Linux, Unix, and Windows operating systems and can be used with various options.

The basic syntax for using netstat is as follows:

netstat [options]

Here are some commonly used options with netstat:

  • -a (all): Display all connections and listening ports.
  • -t (tcp): List TCP connections.
  • -u (udp): List UDP connections.
  • -n (numeric): Show numerical addresses and ports.
  • -p (process): Show the process using the connection (works only on some systems).
  • -r (route): Display the routing table.

For example, to view all TCP connections and ports:

netstat -t

or to view all connections and ports in numerical format:

netstat -an

The netstat command is often used to diagnose network issues, identify used ports, or observe network traffic.

Here’s a cheat sheet for using netstat, a tool for displaying network connections, routing tables, interface statistics, masquerade connections, and multicast memberships:

Basic Usage:

  1. Display All Connections:
    netstat -a
  2. List All Listening Ports:
    netstat -l
  3. Show Detailed Information (including PID):
    netstat -p

Displaying Specific Protocol Connections:

  1. Show TCP Connections:
    netstat -t
  2. Show UDP Connections:
    netstat -u
  3. Display Only IPv4 Connections:
    netstat -4
  4. Display Only IPv6 Connections:
    netstat -6

Routing Table:

  1. Show Routing Table:
    netstat -r

Interface Statistics:

  1. Show Interface Statistics:
    netstat -i

Advanced:

  1. Display Network Services and Ports (Linux):
    netstat -tulpn
  2. Display Network Services and Ports (Windows):
    netstat -ano
  3. Show Kernel Routing Information (Linux):
    netstat -r -n
  4. Display Network Statistics Since Boot:
    netstat -s

Filtering and Formatting:

  1. Show Numerical Addresses:
    netstat -n
  2. Display Continuous Output (Linux):
    watch -n 1 netstat -an
  3. Display Continuous Output (Windows):
    netstat -an 1

These commands cover some common use cases for netstat. For more detailed information, you can refer to the netstat manual (man netstat on Linux).

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.