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:
- 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 shortcutCtrl + Alt + T
. - Basic Usage: The basic syntax of the
netstat
command is as follows:netstat [options]
- 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
- Display Listening Ports: To view all listening ports on your system, use the following command:
netstat -l
- Display Network Statistics: To show statistics for each protocol (TCP, UDP, and ICMP), run:
netstat -s
- Display Network Routing Table: To view the kernel’s IP routing table, use the following command:
netstat -r
- Display PID and Program Name: To see which processes (identified by their PIDs) are using the network connections, add the
-p
option:netstat -ap
- 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.