- About netstat : To print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships
- It comes from: “net-tools-1.60” package.
- Configuration Files:
/etc/services — The services translation file
/proc/net/dev — device information
/proc/net/raw — raw socket information
/proc/net/tcp — TCP socket information
/proc/net/udp — UDP socket information
/proc/net/igmp — IGMP multicast information
/proc/net/unix — Unix domain socket information
/proc/net/route — IP routing information
/proc/net/snmp — Statistics - Path: /bin/netstat
Examples:
1. To display the kernel routing table
$ netstat -r $ netstat –route |
2. To display multicast group membership information
$ netstat -g $ netstat –groups |
3. To display the kernel interface table
$ netstat -i $ netstat –interfaces $ netstat –interfaces=eth0 |
4. To display a list of masqueraded connections
$ netstat -M $ netstat –masquerade |
5. To display summary statistics of each protocol
$ netstat -s $ netstat –statistics |
6. To set to verbose
$ netstat -v $ netstat –verbose |
7. To show numerical addresses instead of trying to determine symbolic host
$ netstat -n $ netstat –numeric |
8. To numerical host addresses but does not affect the resolution
$ netstat –numeric-hosts |
9. To numerical port numbers but does not affect the resolution
$ netstat –numeric-ports |
10. To show numerical user IDs but does not affect the resolution
$ netstat –numeric-users |
11. To print the selected information every second continuously
$ netstat -c $ netstat –continuous |
12. To display the additional information
$ netstat -e $ netstat –extend |
13. To include information related to networking timers
$ netstat -o $ netstat –timers |
14. To show the PID and name of the program to which each socket belongs
$ netstat -p $ netstat –program |
15. To show only listening sockets
$ netstat -l $ netstat –listening |
16. To show both listening and non-listening sockets
$ netstat -a $ netstat –all |
17. To print routing information from the FIB
$ netstat -F |
18. To print routing information from the route cache
$ netstat -C |
19. To print SELinux context
$ netstat -Z $ netstat –context |
20. To stop trimming long addresses
$ netstat -T $ netstat –notrim |
21. To set delay
$ netstat delay 2 |
22. To get the help
$ netstat -h $ netstat –help |
23. To get the version
$ netstat –version |
Cocktail Examples
24. To see the currently active routing table
$ netstat -rnv |
25. To see all the socket information
$ netstat -anp |
26. To see all the listening ports
$ netstat -anp | grep LISTEN |
27. To see all the process/services running and listening on ports
$ netstat -lnptu |
28. To see the protocol specific statistics (e.g. for TCP)
$ netstat -pt |
29. To see the interface activity stats
$ netstat -i -t 2 $ netstat -it 2 |
30. To see the summary stat for a particular port
$ netstat -st (For TCP) $ netstat -su (For UDP) |
Related Commands: ss, ip
One thought on “how to use netstat command and its examples”
Lots of netstat options you have listed. Thanks for sharing this helpful information here. This will list number of different connection types
netstat -ant | awk '{print $6}' | sort | uniq -c | sort -n
Some interesting outputs of Netstat learned from here. Hope its helps