A página de manual de netstat tem uma breve descrição de cada estado:
ESTABLISHED
The socket has an established connection.
SYN_SENT
The socket is actively attempting to establish a connection.
SYN_RECV
A connection request has been received from the network.
FIN_WAIT1
The socket is closed, and the connection is shutting down.
FIN_WAIT2
Connection is closed, and the socket is waiting for a shutdown
from the remote end.
TIME_WAIT
The socket is waiting after close to handle packets still in the
network.
CLOSE The socket is not being used.
CLOSE_WAIT
The remote end has shut down, waiting for the socket to close.
LAST_ACK
The remote end has shut down, and the socket is closed. Waiting
for acknowledgement.
LISTEN The socket is listening for incoming connections. Such sockets
are not included in the output unless you specify the
--listening (-l) or --all (-a) option.
CLOSING
Both sockets are shut down but we still don't have all our data
sent.
UNKNOWN
The state of the socket is unknown.
Você pode usar os diagramas de transição de estado (exemplos aqui , aqui e aqui ) para entender melhor os estados.
Considere dois programas tentando uma conexão de soquete (chame-os de a e b ). Ambos configuram sockets e fazem a transição para o estado LISTEN . Então, um programa (digamos, a ) tenta se conectar ao outro ( b ). a envia uma solicitação e digita o estado SYN_SENT , e b recebe a solicitação e insere o estado SYN_RECV . Quando b confirma a solicitação, eles entram no estado ESTABLISHED e fazem seus negócios. Agora, algumas coisas podem acontecer:
-
adeseja fechar a conexão e insereFIN_WAIT1.brecebe a solicitaçãoFIN, enviaACK(entãoainsereFIN_WAIT2), insereCLOSE_WAIT, informaaque está fechando e insereLAST_ACK. Quandoareconhecer isso (e inserirTIME_WAIT),binsereCLOSE.aespera um pouco para ver se alguma coisa é deixada e, em seguida, insereCLOSE. -
aebterminaram seus negócios e decidem fechar a conexão (fechamento simultâneo). Quandoaestá emFIN_WAITe, em vez de receber umACKdeb, recebe umFIN(comobdeseja fechar também),ainsereCLOSING. Mas ainda há algumas mensagens para enviar (oACKqueadeve obter para seu% originalFIN) e, assim que esseACKchegar,ainsereTIME_WAITcomo de costume.