netstat (network statistics) is a command line tool for monitoring network connections both incoming and outgoing as well as viewing routing tables, interface statistics etc.
netstat is available on all Unix-like Operating Systems and also available on Windows OS as well. It is very useful in terms of network troubleshooting and performance measurement. 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.
Update: The Linux netstat command is replaced by new ss command, which is capable of displaying more information about network connections and it is much faster than the older netstat command.
This tool is very important and much useful for Linux network administrators as well as system administrators to monitor and troubleshoot their network-related problems and determine network traffic performance. This article shows usages of netstat command with their examples which may be useful in daily operation.
You might also be interested in following article
- 35 Practical Examples of Linux Find Command
1. Listing all the LISTENING Ports of TCP and UDP connections
Listing all ports (both TCP and UDP) using netstat -a option.
2. Listing TCP Ports connections
Listing only TCP (Transmission Control Protocol) port connections using netstat -at.
3. Listing UDP Ports connections
Listing only UDP (User Datagram Protocol ) port connections using netstat -au.
4. Listing all LISTENING Connections
Listing all active listening ports connections with netstat -l.
5. Listing all TCP Listening Ports
Listing all active listening TCP ports by using option netstat -lt.
6. Listing all UDP Listening Ports
Listing all active listening UDP ports by using option netstat -lu.
7. Listing all UNIX Listening Ports
Listing all active UNIX listening ports using netstat -lx.
8. Showing Statistics by Protocol
Displays statistics by protocol. By default, statistics are shown for the TCP, UDP, ICMP, and IP protocols. The -s parameter can be used to specify a set of protocols.
9. Showing Statistics by TCP Protocol
Showing statistics of only TCP protocol by using option netstat -st.
10. Showing Statistics by UDP Protocol
11. Displaying Service name with PID
Displaying service name with their PID number, using option netstat -tp will display “PID/Program Name”.
12. Displaying Promiscuous Mode
Displaying Promiscuous mode with -ac switch, netstat print the selected information or refresh screen every five second. Default screen refresh in every second.
13. Displaying Kernel IP routing
Display Kernel IP routing table with netstat and route command.
14. Showing Network Interface Transactions
Showing network interface packet transactions including both transferring and receiving packets with MTU size.
15. Showing Kernel Interface Table
Showing Kernel interface table, similar to ifconfig command.
16. Displaying IPv4 and IPv6 Information
Displays multicast group membership information for both IPv4 and IPv6.
17. Print Netstat Information Continuously
To get netstat information every few second, then use the following command, it will print netstat information continuously, say every few seconds.
18. Finding non supportive Address
Finding un-configured address families with some useful information.
19. Finding Listening Programs
Find out how many listening programs running on a port.
20. Displaying RAW Network Statistics
That’s it, If you are looking for more information and options about netstat command, refer netstat manual docs or use man netstat command to know all the information. If we’ve missed anything in the list, please inform us using our comment section below. So, we could keep updating this list based on your comments.