How to Use Netstat for Network Troubleshooting

By: Morpheus Data

When debugging networks problems on a Linux server, ping and traceroute are often helpful, but you may need to have further network details on hand to help track down an issue and get it fixed. One such command is netstat, which can offer you details on the networks sockets as well as other helpful information. As with ping and traceroute, you can simply use netstat from the command line and get results quickly.

What is Netstat?

The netstat command in Linux is a very useful tool when dealing with networking issues.

Source: IBM developerWorks

Netstat, short for the phrase ‘network statistics’, is a tool Linux (as well as other operating systems such as Windows and OS X) can make use of in order to display incoming and outgoing network connections. In addition to this, it can be used to get information on network statistics, protocol statistics, and routing tables.

You can use netstat to find network problems and measure the amount of network traffic, so it can be a really useful tool to help you gather the information you need to solve any outage, slow down, or bottleneck issues on your network.

Basic Netstat

For a basic listing of all the current connections, you would simply call netstat with the -a option.

This provides some basic information on connections from different types of protocols like TCP and UDP, as well as active Unix domain sockets. However, netstat allows you to get more specific information that can be more helpful in debugging.

Filter by Connection Type

Sometimes filtering the results based on the connection type can be useful when trying to find the information you need. For example, if you want to see only the TCP connections, you can add the ‘t’ option in addition to the ‘a’ option, as shown below:

Similarly, by using netstat -au, you can list only the UDP connections.

Filter by Listening Connections

If you want to only see the connections that are listening, you can do so by using the ‘l’ option and remove the ‘a’ option. Here is an example of this:

As with the ‘a’ option, you can use netstat -lt and netstat -lu in order to further filter and to get only the listening TCP or UDP connections. In this way, you can easily see if a particular port is open and listening and determine whether a website or app is able to be up and running as expected.

See Network Statistics

As you can see, this offers some statistics that may be useful to you while debugging, such as total, incoming, and outgoing packets as well as ICMP messages that were received, sent, and failed.