Which utility can be used to view a list of open TCP connections on Linux or Windows systems netstat?

Introduction

The netstat command is a CLI tool for network statistics. It gives an overview of network activities and displays which ports are open or have established connections. The netstat tool is essential for discovering network problems.

This article shows 28 netstat commands for displaying port and internet statistics data on Linux.

Which utility can be used to view a list of open TCP connections on Linux or Windows systems netstat?

Prerequisites

  • Access to the terminal
  • Installed net-tools software package

Note: Though still widely used, netstat command is considered obsolete. Instead, the ss command is recommended as a faster and simpler tool. Learn more about the Linux ss command.

How to Use netstat Command in Linux

The primary usage of netstat is without any parameters:

netstat

Which utility can be used to view a list of open TCP connections on Linux or Windows systems netstat?

The first list in the output displays active established internet connections on the computer. The following details are in the columns:

  • Proto – Protocol of the connection (TCP, UDP).
  • Recv-Q – Receive queue  of bytes received or ready to be received.
  • Send-Q – Send queue of bytes ready to be sent.
  • Local address – Address details and port of the local connection. An asterisk (*) in the host indicates that the server is listening and if a port is not yet established.
  • Foreign address– Address details and port of the remote end of the connection. An asterisk (*) appears if a port is not yet established.
  • State – State of the local socket, most commonly ESTABLISHED, LISTENING, CLOSED or blank.

The second list shows all the active "Unix Domain" open sockets with the following details:

  • Proto – Protocol used by the socket (always unix).
  • RefCnt – Reference count of the number of attached processes to this socket.
  • Flags – Usually ACC or blank.
  • Type – The socket type.
  • State – State of the socket, most often CONNECTED, LISTENING or blank.
  • I-Node – File system inode (index node) associated with this socket.
  • Path – System path to the socket.

For advanced usage, expand the netstat command with options:

netstat [options]

Or list the options one by one:

netstat [option 1] [option 2] [option 3]

The netstat options enable filtering of network information.

List All Ports and Connections

To list all ports and connections regardless of their state or protocol, use:

netstat -a

Which utility can be used to view a list of open TCP connections on Linux or Windows systems netstat?


The output lists established connections along with servers which are open or listening.

List All TCP Ports

List all TCP ports by running:

netstat -at

Which utility can be used to view a list of open TCP connections on Linux or Windows systems netstat?

List All UDP Ports

List all UDP ports with:

netstat -au

Which utility can be used to view a list of open TCP connections on Linux or Windows systems netstat?

List Only Listening Ports

To return a list of only listening ports for all protocols, use:

netstat -l

Which utility can be used to view a list of open TCP connections on Linux or Windows systems netstat?


List TCP Listening Ports

List all listening TCP ports with:

netstat -lt

Which utility can be used to view a list of open TCP connections on Linux or Windows systems netstat?


List UDP Listening Ports

Return only listening UDP ports by running:

netstat -lu

Which utility can be used to view a list of open TCP connections on Linux or Windows systems netstat?


List UNIX Listening Ports

To list UNIX listening ports, use:

netstat -lx

Which utility can be used to view a list of open TCP connections on Linux or Windows systems netstat?

Display Statistics by Protocol

Display statistics for all ports regardless of the protocol with:

netstat -s

Which utility can be used to view a list of open TCP connections on Linux or Windows systems netstat?

Statistics are also filterable by protocol.

List Statistics for TCP Ports

List statistics for TCP ports only with:

netstat -st

Which utility can be used to view a list of open TCP connections on Linux or Windows systems netstat?

List Statistics for UDP Ports

To list statistics for UDP ports only, use:

netstat -su

Which utility can be used to view a list of open TCP connections on Linux or Windows systems netstat?

List Network Interface Transactions

To see transactions of MTU, receiving and transferring packets in the kernel interface table, use:

netstat -i

Which utility can be used to view a list of open TCP connections on Linux or Windows systems netstat?

Display Extended Kernel Interface Table

Add the option -e to netstat -i to extend the details of the kernel interface table:

netstat -ie

Which utility can be used to view a list of open TCP connections on Linux or Windows systems netstat?

Display Masqueraded Connections

For displaying masqueraded connections, use:

netstat -M

Display PID

Display the PID/Program name related to a specific connection by adding the -p option to netstat. For example, to view the TCP connections with the PID/Program name listed, use:

netstat -tp

Which utility can be used to view a list of open TCP connections on Linux or Windows systems netstat?

Find Listening Programs

Find all listening programs with:

netstat -lp

Which utility can be used to view a list of open TCP connections on Linux or Windows systems netstat?

Display Kernel IP Routing Table

Display the kernel IP routing table with:

netstat -r

Which utility can be used to view a list of open TCP connections on Linux or Windows systems netstat?

Display IPv4 and IPv6 Group Membership

Display group membership for IPv6/IPv4 with:

netstat -g

Which utility can be used to view a list of open TCP connections on Linux or Windows systems netstat?

Add the -c option to the netstat command to print information every second:

netstat -c

For example, to print the kernel interface table continuously, run:

netstat -ic

Which utility can be used to view a list of open TCP connections on Linux or Windows systems netstat?

Find Unconfigured Address Families

List addresses without support on the system with:

netstat --verbose

The information is found at the end of the output:

Which utility can be used to view a list of open TCP connections on Linux or Windows systems netstat?

Display Numerical Addresses, Host Addresses, Port Numbers, and User IDs

By default, addresses, port numbers, and user IDs are resolved into human-readable names when possible. Knowing the unresolved port number is important for tasks such as SSH port forwarding.

Display Numerical Addresses
Show numerical addresses with:

netstat -n

Display Numerical Host Addresses
To show only host addresses as numerical, run:

netstat --numeric-hosts

Display Numerical Port Numbers
Show only ports as numerical with:

netstat --numeric-ports

Display Numerical User Ids
To display numerical user IDs, use:

netstat --numeric-users

Find a Process That Is Using a Particular Port

Make use of the grep command to filter the data from netstat. To find a process that is using a particular port number, run:

netstat -an | grep ':[port number]'

For example:

netstat -an | grep ':80'

Which utility can be used to view a list of open TCP connections on Linux or Windows systems netstat?

List All netstat Commands

There are many netstat options available. Access the list of all the available commands and a short description using:

netstat -h

Which utility can be used to view a list of open TCP connections on Linux or Windows systems netstat?

Conclusion

Netstat is an essential tool for network engineers, system administrators, and developers. Troubleshooting network problems and having an overview of all the network activities and port availability are just some use cases of this tool.

For further reading, find out about the best network security tools.

Which utility can be used to view a list of open TCP connections on Linux or Windows systems tracert?

The netstat command will show a list of TCP connections, the IP address of your computer, the IP address of the device the connection goes to (the foreign IP address), the port numbers of both, and the TCP state.

Which utility can be used to view a list of open TCP connections on Linux or Windows systems ping netstat tracert ipconfig navigation bar?

Which utility can be used to view a list of open TCP connections on Linux or Windows systems? Explanation: Netstat is a utility that is available for both Linux and Windows systems.

How do I see TCP connections in Linux?

Check TCP Connection Status in Linux To display listeners and connections on Linux we can use the netstat or ss command. While older Linux boxes only support netstat, newer Linux distributions use netstat and ss in parallel.

Which utility displays the open connections on a Linux computer?

netstat is one of the most basic network service debugging tools, telling you what ports are open and whether any programs are listening on ports.