Quelle est la différence entre les états de port «LISTENING», «TIME_WAIT», «CLOSE_WAIT» et «ESTABLISHED»?


Réponses:


58

La page de manuel de netstata une brève description de chaque état:

   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.

Vous pouvez utiliser les diagrammes de transition d'états (exemples ici , ici et ici ) pour mieux comprendre les états.


Considérons deux programmes essayant une connexion de socket (appelez-les aet b). Les deux mettent en place des sockets et passent à l' LISTENétat. Ensuite, un programme (par exemple a) essaie de se connecter à l’autre ( b). aenvoie une demande et entre dans l' SYN_SENTétat, puis breçoit la demande et entre dans l' SYN_RECVétat. Lorsqu'ils baccèdent à la demande, ils entrent dans l' ESTABLISHEDÉtat et font leurs affaires. Maintenant, plusieurs choses peuvent arriver:

  1. asouhaite fermer la connexion et entre FIN_WAIT1. breçoit la FINdemande, envoie un ACK(puis aentre FIN_WAIT2), entre CLOSE_WAIT, dit aqu'il ferme et entre LAST_ACK. Une fois aque cela reconnaît (et entre TIME_WAIT), bentre CLOSE. aattend un peu pour voir s'il reste quelque chose, puis entre CLOSE.
  2. aet bont fini leurs affaires et décide de fermer la connexion (fermeture simultanée). Quand aest dedans FIN_WAIT, et au lieu de recevoir un ACKde b, il reçoit un FIN(comme bsouhaite le fermer aussi), aentre CLOSING. Mais il y a encore des messages à envoyer (ceux ACKqui asont supposés avoir pour l'original FIN), et une fois que cela ACKarrive, aentre TIME_WAITcomme d'habitude.

Informations supplémentaires à la réponse de muru. Diagramme d'état de Netstat (cité à partir de: http://www4.cs.fau.de/Projects/JX/Projects/TCP/tcpstate.html )! Entrez la description de l'image ici
charkh
En utilisant notre site, vous reconnaissez avoir lu et compris notre politique liée aux cookies et notre politique de confidentialité.
Licensed under cc by-sa 3.0 with attribution required.