Skip to content

Usage of Netstat Command in Linux

TL;DR

netstat -ntlp displays the listening ports of TCP.
netstat -ntlp displays the listening ports of TCP and UDP.
netstat -r displays the routing table.
netstat -rn displays the routing table without name resolution (faster).
netstat -an displays local connections.

Introduction

Netstat command is a powerful tool used in Linux operating system to display information about the network connections, routing tables and network statistics. It is a command-line utility that helps to identify the active and inactive network connections on a computer. In this blog post, we will discuss the usage of netstat command and its various options.

Displaying Active Network Connections

One of the primary uses of netstat command is to display the active network connections on a Linux machine. This can be done by running the following command:

netstat -a

This command will display all the active network connections and their corresponding IP addresses, ports, and the state of the connection. It is a useful tool for identifying any suspicious network activity on a computer.

Displaying Network Statistics

Netstat command can also be used to display various network statistics on a Linux machine. This includes the number of packets sent and received, the number of errors encountered, and the number of packets dropped. This information can be obtained by running the following command:

netstat -s

This command will display the network statistics in detail, which can be useful for troubleshooting network issues on a computer.

Displaying Routing Tables

Netstat command can also be used to display the routing tables on a Linux machine. This information is useful for identifying the routing path taken by network packets from the source to the destination. The routing table can be displayed by running the following command:

netstat -r

This command will display the routing table, which includes the destination IP addresses, the gateway addresses, and the network interface used for communication.

Conclusion

Netstat command is a powerful tool that can be used to identify active network connections, display network statistics, and view routing tables on a Linux machine. It is a useful utility for network administrators and developers who need to troubleshoot network issues. By understanding the various options available in netstat command, one can easily monitor and manage the network connections on a Linux machine.

Feedback