Nội dung
In this article, AZDIGI will help you understand more about the 20 Netstat commands that Linux server administrators commonly use.
I. What is Netstat?
Netstat is short for “network statistics” and is a command-line tool used to monitor network connections both incoming and outgoing, as well as view routing tables, interface statistics, and other network-related information…
Netstat is built into all Unix operating systems and is also available on Windows operating systems. It is very useful for troubleshooting network issues and is often used for performance measurement. Netstat is one of the most basic network troubleshooting tools, showing you which ports are open and whether there are any programs using those ports.
This tool is very important and useful for Linux network administrators as well as system administrators to monitor and troubleshoot network-related issues and determine network traffic performance. This article will show you how to use netstat commands with examples that may be useful in your daily operations.
II. 20 useful Netstat commands commonly used
Below are 20 Netstat commands frequently used by administrators as well as a detailed description of each command.
1. List all LISTENING Ports of TCP and UDP connections
List all ports (both TCP and UDP) using the option netstat -a
. You can also use netstat -a | more
for a gradual view.
netstat -a
2. List connections using Port TCP
This command is similar to command 1, but this command only lists TCP (Transmission Control Protocol) Ports using netstat -at
.
netstat -at hoặc netstat -at | more
3. List connections using UDP Port
This command is similar to command 1 but this command only lists UDP (User Datagram Protocol) Ports using netstat -a
u.
netstat -au hoặc netstat -au | more
4. List all connections in the LISTENING state
List all active LISTENING connections with the netstat -l
command.
netstat -l hoặc netstat -l | more
5. List all TCP Listening Ports
List all active TCP Listening Ports using the netstat -lt
option.
netstat -lt hoặc netstat -lt | more
6. List all UDP Listening Ports
List all active UDP Listening Ports using the netstat -l
u option.
netstat -lu hoặc netstat -lu | more
7. List all UNIX Listening Ports
List all active UNIX Port Listening using the netstat -l
x command.
netstat -lx hoặc netstat -lx | more
8. Display statistics by Protocol
Display statistics by Protocol. By default, statistics are displayed for protocols such as TCP, UDP, ICMP and IP. The -s
parameter can be used to specify a set of Protocols.
netstat -s hoặc netstat -s | more
9. Display statistics by TCP protocol
Only TCP statistics are displayed using the netstat -st
option.
netstat -st hoặc netstat -st | more
10. Display statistics by UDP protocol
Display UDP protocol statistics only using thenetstat -s
u option.
netstat -su hoặc netstat -su | more
11. Show service name with PID
To display the service name with PID number, use the netstat -tp
command, it will display PID/Program name
.
netstat -tp hoặc netstat -tp | more
12. Promiscuous mode display
Display Promiscuous mode with the -ac
option, netstat will show the existing information or refresh it every 5 seconds. The default refresh is every second.
netstat -ac 5 | grep tcp
13. Show Kernel IP routing
Show the Kernel IP routing table with the netstat -r
command.
netstat -r
14. Display of online exchanges
Displays the number of packet exchanges on the network including sending and receiving MTU packets.
15. Show Kernel interface panel
Display the Kernel interface panel, similar to the ifconfig
command with the netstat -ie
command.
netstat -ie hoặc netstat -ie | more
16. Display IPv4 and IPv6 information
Display IPv4 and IPv6 Group Memberships information with the netstat -g
command.
netstat -g
17. Show Netstat information continuously
To get the netstat information every few seconds, we will use the following netstat command, which will show the information continuously with the intensity of every few seconds.
netstat -c
18. Find the service and the port that the service is using
This command is very commonly used to find the Port and the application that is using it. To check if the service is running and using the correct port.
netstat -tlpn
19. Find services that are using the same port
Find out how many listeners are running on a port. Here I will search on the http/https port.
netstat -ap | grep http
20. Display network statistics as raw data
Since this data is quite long, please add the more
option after the command to view it slowly.
netstat --statistics --raw | more
III. Summary
Hopefully, with the above 20 commonly used netstat commands, you can find the information you need. Moreover, for deeper understanding, you can use the command man netstat
to know all the information and options available.
Wishing you success! See more useful articles about Linux VPS at the following link:
If you need assistance, you can contact support in the ways below:
- Hotline 247: 028 888 24768 (Ext 0)
- Ticket/Email: You use the email to register for the service and send it directly to: support@azdigi.com .