The netstat command displays network connection, route table, and network interface information, allowing you to know which network connections are in operation. In our daily work, we usually use two parameters, netstat-an, as shown below:
[Root @ tiaobanji ~] # Netstat-
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
Tcp 0 0 0.0.0.0: 50020 0.0.0.0: * LISTEN
Tcp 0 0 127.0.0.1: 199 0.0.0.0: * LISTEN
Tcp 0 0 127.0.0.1: 9000 0.0.0.0: * LISTEN
Tcp 0 0 127.0.0.1: 41224 0.0.0.0: * LISTEN
Tcp 0 0 127.0.0.1: 21224 0.0.0.0: * LISTEN
The meaning of the stat status in the netstat-an parameter is as follows:
LISTEN: Listen for connection requests from remote TCP ports;
SYN-SENT: Wait for the matching connection request after sending the connection request;
SYN-RECEIVED: Wait for the other party to confirm the connection request after receiving and sending a connection request;
ESTABLISHED: Indicates an opened connection. We usually use this as the number of concurrent connections;
FIN-WAIT-1: Waiting for confirmation of the remote TCP connection interruption request or the previous connection interruption request;
FIN-WAIT-2: Waiting for connection interruption requests from remote TCP;
CLOSE-WAIT: Waiting for a connection interruption request from a local user;
CLOSING: Wait for the confirmation of remote TCP connection interruption;
LAST-ACK: Wait for confirmation of the disconnection from the original remote TCP connection;
TIME-WAIT: Wait for enough time to ensure that the remote TCP connection receives the confirmation of the interrupt request;
CLOSED: No connection status;
In our daily work, we can use shell commands to view the TCP connection status of the server and summarize them. The command is as follows:
Netstat-an | awk '/^ tcp/{++ S [$ NF]} END {for (a in S) print a, S [a]}'
Parameter description:
CLOSED: No connection activity or ongoing;
LISTEN: The server is waiting to enter the call;
SYN_RECV: A connection request has arrived. wait for confirmation;
SYN_SENT: The application has started. Open a connection;
ESTABLISHED: The normal data transmission status can also be considered as the number of concurrent requests on the current server;
FIN_WAIT1: The application has been completed;
FIN_WAIT2: The other side agrees to release the instance;
ITMED_WAIT: Wait until all groups die;
CLOSING: Both sides attempt to close at the same time;
TIME_WAIT: The other side has initialized a release;
LAST_ACK: Wait until all groups die;
Count TCP connection count command:
Netstat-an | grep 'established' | grep 'tcp '| wc-l
This article is from the "ant nest" blog, please be sure to keep this source http://feihan21.blog.51cto.com/1364153/1299973