CentOS server netstat command to View TCP connection count Information

Source: Internet
Author: User
Tags centos server

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-

  2. Active Internet connections (servers and established)

  3. Proto Recv-Q Send-Q Local Address Foreign Address State

  4. Tcp 0 0 0.0.0.0: 50020 0.0.0.0: * LISTEN

  5. Tcp 0 0 127.0.0.1: 199 0.0.0.0: * LISTEN

  6. Tcp 0 0 127.0.0.1: 9000 0.0.0.0: * LISTEN

  7. Tcp 0 0 127.0.0.1: 41224 0.0.0.0: * LISTEN

  8. Tcp 0 0 127.0.0.1: 21224 0.0.0.0: * LISTEN


The meaning of the stat status in the netstat-an parameter is as follows:


LISTEN: Listen for connection requests from remote TCP ports;
SYN-SENT: Wait for the matching connection request after sending the 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: Waiting for confirmation of the remote TCP connection interruption request or the previous connection interruption request;
FIN-WAIT-2: Waiting for connection interruption requests from remote TCP;
CLOSE-WAIT: Waiting for a connection interruption request from a local user;
CLOSING: Wait for the confirmation of remote TCP connection interruption;
LAST-ACK: Wait for confirmation of the disconnection from the original remote TCP connection;
TIME-WAIT: Wait for enough time to ensure that the remote TCP connection receives the confirmation of the interrupt 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 (a in S) print a, S [a]}'

Parameter description:
CLOSED: No connection activity or ongoing;
LISTEN: The server is waiting to enter the call;
SYN_RECV: A connection request has arrived. wait for confirmation;
SYN_SENT: The application has started. Open a connection;
ESTABLISHED: The normal data transmission status 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 the instance;
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



This article is from the "ant nest" blog, please be sure to keep this source http://feihan21.blog.51cto.com/1364153/1299973

Related Article

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.