Count the number of Linux server connections
Security code: it is impossible to have inner peace without a considerable degree of loneliness.
By understanding the state of TCP, it is very helpful to troubleshoot and locate network or system problems. Check the number of connections to the server through the netstat command.
Netstat-an | awk'/ tcp/ {print $6}'| sort | uniq-c 28 CLOSE_WAIT 2 CLOSING 116 ESTABLISHED 28 FIN_WAIT1 12 FIN_WAIT2 4 LAST_ACK 5 LISTEN 72 SYN_RECV 295 TIME_WAIT
Status description CLOSED does not have any connection LISTENING listens for connection requests from remote TCP ports SYN-SENT application has started, open a connection SYN-RECEIVED a connection request has arrived, waiting for confirmation that ESTABLISHED represents an open connection FIN-WAIT-1 waiting for a remote TCP connection break request Or confirmation of a previous connection break request FIN-WAIT-2 from the remote TCP waiting for a connection break request CLOSE-WAIT waiting for a connection break request sent from a local user CLOSING waiting for a remote TCP confirmation of a connection break LAST-ACK waiting for the original confirmation of a connection break request sent to the remote TCP wait enough time to ensure that the remote TCP receives an acknowledgement of the connection break request
1. The status of the client can be represented by the following process:
CLOSED- > SYN_SENT- > ESTABLISHED- > FIN_WAIT_1- > FIN_WAIT_2- > TIME_WAIT- > CLOSED
2. The status of the server can be represented by the following process:
CLOSED- > LISTEN- > SYN_RECEIVED- > ESTABLISHED- > CLOSE_WAIT- > LAST_ACK- > CLOSED