用netstat对TCP状态分析

本文详细介绍了如何使用netstat命令对TCP状态进行分析,包括各种参数的作用、各列的含义以及状态的解释。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

用netstat对TCP状态分析


   --numeric , -n
       Show numerical addresses
instead of trying to determine symbolic host, port or user names.


   -o, --timers
       Include information related to networking timers.



   -p, --program
       Show the PID and name of the program to which each socket belongs.



   -l, --listening
       Show only listening sockets.  (These are omitted by default.)



   -a, --all
       Show both listening and non-listening
(for TCP this means established connections) sockets.  With the --interfaces option, show interfaces that are
       not marked



       The protocol (tcp, udp, raw) used by the socket.


   Recv-Q  数据已经在read buffer,但是应用程序还没有调用recv().
   单位是字节    The count of bytes not copied by the user program connected to this socket.


   Send-Q 在write buffer中, 表示对端没有收到的数据或者说没有发Ack来确认的数据

   单位是字节       The count of bytes not acknowledged by the remote host.



   Local Address
       Address  and  port  number  of  the  local end of the socket.  Unless the --numeric (-n) option is specified, the socket address is resolved to its
       canonical host name (FQDN), and the port number is translated into the corresponding service name.


   Foreign Address
       Address and port number of the remote end of the socket.  Analogous to "Local Address."


   State
       The state of the socket. Since there are no states in raw mode and usually no states used in UDP, this column may be left blank. Normally this  can
       be one of several values:


       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  

      此状态是:“主动关闭方” 主动发送了 FIN 给对端后的状态

              The socket is closed, and the connection is shutting down.


       FIN_WAIT2 

    此状态是: “主动关闭方”  主动发送了 FIN 给对端, 并接收到对端的回应的ACK 后的状态

              Connection is closed, and the socket is waiting for a shutdown from the remote end.


       TIME_WAIT 

此状态是: “主动关闭方”  主动发送了 FIN 给对端,并接收到对端的回应的ACK,然后接收到对端 发送的FIN后的状态

              The socket is waiting after close to handle packets still in the network.




       CLOSED The socket is not being used.

 此状态是: “被动关闭方” 接收到了对端先发来的FIN,并发送了ACK ,然后发送FIN后的状态,并接收到了对端的ACK回复的状态



       CLOSE_WAIT :              The remote end has shut down, waiting for the socket to close.

此状态是: “被动关闭方”接收到了对端先发来的FIN

状态变成CLOSE_WAIT,   此时 要调用close()关闭连接,不然就会有CLOSE_WAIT状态

{::recv()的返回值: 

n:These calls return the number of bytes received, 

-1:or -1 if an error occurred.  

0:The return value will be 0 when the peer  has  performed  an  orderly  shutdown. }




       LAST_ACK

  此状态是: “被动关闭方” 接收到了对端先发来的FIN,并发送了Ack ,然后发送FIN后的状态

              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.


   User
       The username or the user id (UID) of the owner of the socket.


   PID/Program name
       Slash-separated pair of the process id (PID) and process name of the process that owns the socket.  --program causes this column  to  be  included.
       You will also need superuser privileges to see this information on sockets you don’t own.  This identification information is not yet available for
       IPX sockets.


   Timer
       (this needs to be written)


   Active UNIX domain Sockets
   Proto
       The protocol (usually unix) used by the socket.


   RefCnt
       The reference count (i.e. attached processes via this socket).


   Flags
       The flags displayed is SO_ACCEPTON (displayed as ACC), SO_WAITDATA (W) or SO_NOSPACE (N).  SO_ACCECPTON is used on  unconnected  sockets  if  their
       corresponding processes are waiting for a connect request. The other flags are not of normal interest.


   Type
       There are several types of socket access:


       SOCK_DGRAM
              The socket is used in Datagram (connectionless) mode.


       SOCK_STREAM
              This is a stream (connection) socket.


       SOCK_RAW
              The socket is used as a raw socket.


       SOCK_RDM
              This one serves reliably-delivered messages.


       SOCK_SEQPACKET
              This is a sequential packet socket.


       SOCK_PACKET
              Raw interface access socket.


       UNKNOWN
              Who ever knows what the future will bring us - just fill in here :-)


   State
       This field will contain one of the following Keywords:


       FREE   The socket is not allocated


       LISTENING
              The socket is listening for a connection request.  Such sockets are only included in the output if you specify the --listening (-l) or --all
              (-a) option.


       CONNECTING
              The socket is about to establish a connection.


       CONNECTED
              The socket is connected.


       DISCONNECTING
              The socket is disconnecting.


       (empty)
              The socket is not connected to another one.


       UNKNOWN
              This state should never happen.


   PID/Program name
       Process ID (PID) and process name of the process that has the socket open.  More info available in  Active  Internet  connections  section  written
       above.






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值