CentOS command for viewing TCP connections netstat

Source: Internet
Author: User

CentOS command for viewing TCP connections netstat

The netstat command displays network connection, route table, and network interface information, allowing you to know which network connections are in operation. In our daily work, we usually use two parameters, netstat-an, as shown below:

  1. [root@tiaobanji~]#netstat-anActiveInternetconnections(serversandestablished)ProtoRecv-QSend-QLocalAddressForeignAddressStatetcp000.0.0.0:500200.0.0.0:*LISTENtcp00127.0.0.1:1990.0.0.0:*LISTENtcp00127.0.0.1:90000.0.0.0:*LISTENtcp00127.0.0.1:412240.0.0.0:*LISTENtcp00127.0.0.1:212240.0.0.0:*LISTEN
    The meaning of stat (Status) in the netstat-an parameter is as follows:


LISTEN: listens for connection requests from remote TCP ports;
SYN-SENT: wait for a matched connection request after sending a connection request;
SYN-RECEIVED: Wait for the other party to confirm the connection request after receiving and sending a connection request;
ESTABLISHED: indicates an opened connection. We usually use this as the number of concurrent connections;
FIN-WAIT-1: WAIT for the confirmation of the remote TCP connection interruption request or the previous connection interruption request;
FIN-WAIT-2: waits for connection interruption requests from remote TCP;
CLOSE-WAIT: Waiting for connection interruption requests from local users;
CLOSING: waiting for confirmation of remote TCP connection interruption;
LAST-ACK: waiting for confirmation of the interruption of the original remote TCP connection;
TIME-WAIT: WAIT for enough TIME to ensure that the remote TCP connection receives the confirmation of the interrupted request;
CLOSED: No connection status;

In our daily work, we can use shell commands to view the TCP connection status of the server and summarize them. The command is as follows:

  1. netstat-an|awk'/^tcp/{++S[$NF]}END{for(ainS)printa,S[a]}'

Parameter description:
CLOSED: No connection activity or ongoing;
LISTEN: the server is waiting for the incoming call;
SYN_RECV: a connection request has arrived. wait for confirmation;
SYN_SENT: The application has started. Open a connection;
ESTABLISHED: normal data transmission status. It can also be considered as the number of concurrent requests on the current server;
FIN_WAIT1: The application has been completed;
FIN_WAIT2: the other side agrees to release;
ITMED_WAIT: wait until all groups die;
CLOSING: both sides attempt to close at the same time;
TIME_WAIT: the other side has initialized a release;
LAST_ACK: wait until all groups die;

Count TCP connection count command:

  1. netstat-an|grep'ESTABLISHED'|grep'tcp'|wc-l

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.