Cent OS Server netstat ordered to view TCP connection number information

Source: Internet
Author: User

The function of the netstat command is to display information about network connections, routing tables, and network interfaces, allowing users to know which network connections are in operation. In our daily work, we most commonly use two parameters, namely Netstat–an, as follows:

[Email Protected]_moban nginx]# Netstat-an

Active Internet connections (servers and established)

Proto recv-q send-q Local address Foreign address state

TCP 0 0 0.0.0.0:80 0.0.0.0:* LISTEN

TCP 0 0 0.0.0.0:22 0.0.0.0:* LISTEN

TCP 0 0 127.0.0.1:25 0.0.0.0:* LISTEN


The meaning of stat (status) in the Netstat-an parameter is as follows:


LISTEN: Listening for connection requests from a remote TCP port;

Syn-sent: Waits for a matching connection request after the connection request is sent;

Syn-received: Waits for the other party to confirm the connection request after receiving and sending a connection request;

Established: Represents an open connection, which we often use as the number of concurrent connections;

Fin-wait-1: Waiting for a remote TCP connection to interrupt the request, or the acknowledgement of a previous connection interruption request;

Fin-wait-2: Waiting for connection interruption request from remote TCP;

Close-wait: Waiting for a connection interruption request from a local user;

CLOSING: Wait for the remote TCP to confirm the connection interruption;

Last-ack: Wait for the acknowledgement of the connection interruption that originally sent to the remote TCP;

Time-wait: Wait enough time to ensure that the remote TCP connection receives an acknowledgement of the interrupt request;

CLOSED: no connection status;

In our daily work, we can use the shell Combination command to view the server's TCP connection status and summarize the command as follows:

Netstat-an|awk '/^tcp/{++s[$NF]}end{for (A in S) print A,s[a]} '

Parameter description:

CLOSED: No connection activity or in progress;

LISTEN: The server is waiting for incoming calls;

SYN_RECV: A connection request has arrived, waiting for confirmation;

Syn_sent: Application has started, open a connection;

Established: Normal data transmission status, can also be approximated as the current server concurrency;

FIN_WAIT1: The application has been completed;

Fin_wait2: The other side agrees to release;

Itmed_wait: Wait for all packets to die;

CLOSING: Both sides try to close simultaneously;

Time_wait: The other side has initialized a release;

Last_ack: Wait for all packets to die;

Count TCP connections Command:

Netstat-an |grep ' established ' |grep ' TCP ' |wc-l


This article from the "Smurf Linux operation and Maintenance" blog, reproduced please contact the author!

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.