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.
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.
1. Listing all the LISTENING Ports of TCP and UDP connections
Listing all ports (both TCP and UDP) using netstat -a option.
1 | # netstat -a | more |
2. Listing TCP Ports connections
Listing only TCP (Transmission Control Protocol) port connections using netstat -at.
1 | # netstat -at |
3. Listing UDP Ports connections
Listing only UDP (User Datagram Protocol ) port connections using netstat -au.
1 | # netstat -au |
4. Listing all LISTENING Connections
Listing all active listening ports connections with netstat -l.
1 | # netstat -l |
5. Listing all TCP Listening Ports
Listing all active listening TCP ports by using option netstat -lt.
1 | # netstat -lt |
6. Listing all UDP Listening Ports
Listing all active listening UDP ports by using option netstat -lu.
1 | # netstat -lu |
7. Listing all UNIX Listening Ports
Listing all active UNIX listening ports using netstat -lx.
1 | # 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.
1 | # netstat -s |
9. Showing Statistics by TCP Protocol
Showing statistics of only TCP protocol by using option netstat -st.
1 | # netstat -st |
10. Showing Statistics by UDP Protocol
1 | # netstat -su |
11. Displaying Service name with PID
Displaying service name with their PID number, using option netstat -tp will display “PID/Program Name”.
1 | # netstat -tp |
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.
1 | # netstat -ac 5 | grep tcp |
13. Displaying Kernel IP routing
Display Kernel IP routing table with netstat and route command.
1 | # netstat -r |
14. Showing Network Interface Transactions
Showing network interface packet transactions including both transferring and receiving packets with MTU size.
1 | # netstat -i |
15. Showing Kernel Interface Table
Showing Kernel interface table, similar to ifconfig command.
1 | # netstat -ie |
16. Displaying IPv4 and IPv6 Information
Displays multicast group membership information for both IPv4 and IPv6.
1 | # netstat -g |
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.
1 | # netstat -c |
18. Finding non supportive Address
Finding un-configured address families with some useful information.
1 | # netstat --verbose |
19. Finding Listening Programs
Find out how many listening programs running on a port.
1 | # netstat -ap | grep http |
20. Displaying RAW Network Statistics
1 | # netstat --statistics --raw |
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.