CentOS command for viewing TCP connections netstat
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-anActiveInternetconnections(serversandestablished)ProtoRecv-QSend-QLocalAddressForeignAddressStatetcp000.0.0.0:500200.0.0.0:*LISTENtcp00127.0.0.1:1990.0.0.0:*LISTENtcp00127.0.0.1:90000.0.0.0:*LISTENtcp00127.0.0.1:412240.0.0.0:*LISTENtcp00127.0.0.1:212240.0.0.0:*LISTEN
The meaning of stat (Status) in the netstat-an parameter is as follows:
LISTEN: listens for connection requests from remote TCP ports;
SYN-SENT: wait for a matched connection request after sending a 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: WAIT for the confirmation of the remote TCP connection interruption request or the previous connection interruption request;
FIN-WAIT-2: waits for connection interruption requests from remote TCP;
CLOSE-WAIT: Waiting for connection interruption requests from local users;
CLOSING: waiting for confirmation of remote TCP connection interruption;
LAST-ACK: waiting for confirmation of the interruption of the original remote TCP connection;
TIME-WAIT: WAIT for enough TIME to ensure that the remote TCP connection receives the confirmation of the interrupted 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(ainS)printa,S[a]}'
Parameter description:
CLOSED: No connection activity or ongoing;
LISTEN: the server is waiting for the incoming call;
SYN_RECV: a connection request has arrived. wait for confirmation;
SYN_SENT: The application has started. Open a connection;
ESTABLISHED: normal data transmission status. It 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;
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