Skip to content

netstat Linux Command Guide

The netstat command in Linux is used to display various network-related information such as network connections, routing tables, interface statistics, masquerade connections, multicast memberships, and more. It provides valuable insights into the networking activities of the system, helping users diagnose network-related issues and monitor network performance. By utilizing different options and flags, users can customize the output to focus on specific information of interest. Overall, netstat is a powerful command-line tool for network troubleshooting and analysis in Linux systems.

netstat Syntax:

Terminal window
netstat [option] [parameter]

Options:

OptionDescription
-aShow both listening and non-listening sockets.
-tDisplay TCP connections.
-uDisplay UDP connections.
-nShow numerical addresses instead of resolving hostnames.
-pShow the PID and name of the program to which each socket belongs.
-lShow only listening sockets.
-rDisplay the routing table.
-cDisplay the netstat information continuously.
-hDisplay help information.

Parameters:

ParameterDescription
addressDisplay information for the specified address.
interfaceDisplay information for the specified network interface.
networkDisplay information for the specified network type.

netstat Command Samples:

Display All Listening Ports

Terminal window
netstat -tuln

This command displays all listening TCP and UDP ports with numeric addresses.

Display Kernel Routing Information

Terminal window
netstat -r

Displays the kernel routing table, which includes information about network interfaces and routes.

Display All Established Connections

Terminal window
netstat -atn

Shows all established TCP connections with numeric addresses.

Display Network Statistics

Terminal window
netstat -s

Displays network statistics for different protocols like TCP, UDP, ICMP, and more.

Display PID and Program Name for Network Connections

Terminal window
netstat -tulnp

Shows the PID (Process ID) and program name along with TCP and UDP listening ports.

Display Summary of Network Statistics

Terminal window
netstat -s

Provides a summary of various network statistics, including errors, packet drops, and more.

Display All Listening IPv4 and IPv6 Ports

Terminal window
netstat -tuln -4 -6

Displays all listening IPv4 and IPv6 ports with numeric addresses.

How do I use netstat to display all listening ports in Linux?

To display all listening ports with netstat in Linux, use the following command:

Terminal window
netstat -tuln

How can I show all established connections with netstat in Linux?

To show all established connections using netstat in Linux, run the following command:

Terminal window
netstat -tan

How do I use netstat to display both listening and non-listening sockets?

To display both listening and non-listening sockets with netstat in Linux, you can use the following command:

Terminal window
netstat -a

What is the netstat command to show the process ID of the program using a specific port?

To show the process ID of the program using a specific port with netstat in Linux, execute the following command:

Terminal window
netstat -tulpn

How can I use netstat to continuously monitor network connections?

To continuously monitor network connections using netstat in Linux, you can utilize the following command:

Terminal window
netstat -c

How do I display the routing table with netstat in Linux?

To display the routing table with netstat in Linux, simply run the following command:

Terminal window
netstat -r

Applications of the netstat command

  • Display network connections
  • Display routing table information
  • Display interface statistics
  • Display multicast group information
  • Display network protocol statistics