Linux netstat command

The netstat command in Linux is used to display network statistics and information about network connections, routing tables, and network interfaces on a system. It provides valuable insights into network activities and helps troubleshoot network-related issues.

Here’s an overview of how to use the netstat command:

  1. Displaying Network Connections:
    To display active network connections, use the following syntax:
   netstat -tuln

This command shows all TCP (-t) and UDP (-u) connections with their respective ports (-n) and listening (-l) status.

  1. Displaying Network Interfaces:
    To display information about network interfaces, use the following syntax:
   netstat -i

This command lists all network interfaces along with their associated statistics, such as packets and errors.

  1. Displaying Routing Table:
    To display the routing table, use the following syntax:
   netstat -r

This command shows the routing table, including destination networks, gateways, and interface information.

  1. Displaying Network Statistics:
    To display general network statistics, use the following syntax:
   netstat -s

This command provides detailed statistics about different network protocols, including TCP, UDP, IP, and ICMP.

  1. Filtering Output:
    You can filter the output of netstat using various options. Some commonly used options include:
  • Filtering by Protocol: Use -t for TCP, -u for UDP, and -p followed by the protocol name to filter by a specific protocol.
  • Filtering by Port: Use -p followed by the port number to filter by a specific port.
  • Filtering by IP Address: Use -n to display IP addresses instead of hostnames and use -s followed by the IP address to filter by a specific IP.
  1. Examples:
  • Display all active TCP and UDP connections: netstat -tuln
  • Display network interfaces and their statistics: netstat -i
  • Display the routing table: netstat -r
  • Display network statistics for all protocols: netstat -s
  • Filter output to display TCP connections on a specific port (e.g., port 80): netstat -tuln | grep :80
  • Filter output to display connections associated with a specific IP address (e.g.,
    netstat -tuln | grep

The netstat command is a versatile tool for examining network connections, interfaces, routing tables, and statistics. It helps administrators monitor network activities, identify network-related issues, and analyze network performance.

For more information about the netstat command and its options, you can refer to the manual page by typing man netstat in your terminal.