netstat – View network system status information in Linux

Netstat is a command-line tool that displays various network-related information such as active network connections, routing tables, and network interface statistics. It is used to monitor network connections and troubleshoot network-related problems.

Overview

The basic syntax of the netstat command is as follows:

netstat [options]

Here are some examples of how to use the netstat command:

  • To display all active TCP connections:
netstat -at
  • To display all active UDP connections:
netstat -au
  • To display all listening TCP ports:
netstat -lt
  • To display all listening UDP ports:
netstat -lu
  • To display statistics for all network interfaces:
netstat -i
  • To display the routing table:
netstat -r

Options

Here is a table of available options for the netstat command:

Option Description
-a Displays all active connections and the TCP and UDP ports on which the computer is listening.
-t Displays all active TCP connections.
-u Displays all active UDP connections.
-l Displays all listening sockets.
-p Displays the process ID and name to which each socket belongs.
-n Displays addresses and port numbers in numerical form.
-r Displays the kernel routing table.
-i Displays a table of all network interfaces.
-s Displays statistics for all protocols.
-c Continuously displays the selected information.

Troubleshooting tips

  • If you are not seeing any output from the netstat command, try running it with sudo privileges.
  • If you are experiencing network connectivity issues, use netstat to check for any active connections or listening ports that may be causing the problem.
  • If you receive an error message stating that the netstat command is not found, try installing the net-tools package using your system’s package manager.

Notes

  • The netstat command is available on most Linux distributions.
  • The output of the netstat command can be quite verbose, so it is often helpful to use additional tools such as grep to filter the results.
  • The netstat command has been deprecated in favor of the ss command on some newer Linux distributions.