execute the following command: #netstat-N | awk '/^tcp/{++state[$NF]} END { for(KeyinchState) Print key."\ t". State[key]} ' will get a result similar to the following, the exact number will be different: fin_wait_1286fin_wait_2960syn_sent3Last_ack +CLOSING1CLOSED $SYN_RCVD144time_wait2520established352#差不多等于连接的并发数这条命令可以把当前系统的网络连接状态分类汇总. This statement was seen at the feast, and it was said to have been obtained from Wang Lu, the technical director of the Sina Interactive Community division, very well. The description of the return parameter is as follows: SYN_RECV indicates the number of requests that are waiting to be processed, established indicates normal data transfer status, time_wait indicates the number of requests that have been processed, waiting for the end of the timeout. ------------------------------------------------------------------Let's take a look at awk:/^tcp/filter out the beginning of the TCP record, blocking UDP, socket and other unrelated records. State[] equivalent to the definition of an array named State NF represents the number of fields recorded, such as the record shown above, NF equals 6$nf represents a field value, such as the record shown above, $NF that is6That represents the value of the 6th field, time_waitstate[$NF] The number of connections that represent the value of the array element, as shown above, the state[time_wait] state++state[$NF] means adding a number to a record, as shown above, is the number of connections to the state[time_wait] state and an end represents the command to be executed in the final stage for(KeyinchState ) to traverse the array print key,"\ t", State[key] Print array of keys and values, in the middle with a \ t tab split, beautify a bit.
CentOS netstat + awk View TCP's network connection status