How to Use netstat on Linux – How-To Geek

Netstat is a command-line tool available in Linux that allows you to display various network-related information, such as active network connections, routing tables, and network interface statistics. It can be used to troubleshoot network issues, monitor network activities, and gather information about network connections.

Here’s how to use netstat on Linux:

  1. Open a Terminal: To use netstat, you need to open a terminal on your Linux system. You can usually find the terminal application in the Applications or System Tools menu, or you can use the keyboard shortcut Ctrl + Alt + T.
  2. Basic Usage: The basic syntax of the netstat command is as follows:
    netstat [options]
  3. Display All Active Connections: To display a list of all active network connections, including TCP, UDP, and UNIX domain sockets, run the following command:
    netstat -a
  4. Display Listening Ports: To view all listening ports on your system, use the following command:
    netstat -l
  5. Display Network Statistics: To show statistics for each protocol (TCP, UDP, and ICMP), run:
    netstat -s
  6. Display Network Routing Table: To view the kernel’s IP routing table, use the following command:
    netstat -r
  7. Display PID and Program Name: To see which processes (identified by their PIDs) are using the network connections, add the -p option:
    netstat -ap
  8. Continuous Monitoring: If you want netstat to continuously update and display network activities, use the -c option:
    netstat -ac

Remember that netstat is a powerful command with various options. For more detailed information and additional options, you can refer to the netstat man page by typing man netstat in the terminal.

Keep in mind that netstat is being phased out in favor of other commands like ss (Socket Statistics) and ip (IP tool). These newer tools provide more comprehensive and detailed information about network connections. However, for compatibility reasons, netstat is still available on most Linux distributions.

Leave a Reply

Your email address will not be published. Required fields are marked *