TCP connection Status and netstat command

Source: Internet
Author: User
Tags ack

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/74/ED/wKioL1Yu6VvTnAZHAAG4aoSDtLY657.jpg "title=" hvrn3[ juy1]}k% $H $f_0k{7.png "alt=" Wkiol1yu6vvtnazhaag4aosdtly657.jpg "/>

TCP is a reliable data transmission protocol, UDP-based communication speed is faster than UDP, but there is no guarantee of the integrity of data, and more importantly, UDP does not guarantee that the data arrives at the destination side.

TCP connection established by TCP protocol is stateful, called TCP finite state machine

syn_sent: Initiates a connection establishment request, that is, Syn=1, when the synchronization bit is emitted, the state transition bit syn_sent

SYN_RCVD: The server received a client-sent synchronization message, according to the TCP protocol, the reply ACK message simultaneously SYN bit to 1, when the state of the server is converted to SYN_RCVD

established: When the client receives a SYN acknowledgement from the server, the client transfers to the connection establishment State (established) and sends the acknowledgement message back to the server.

The state is established, the two sides can send data to communicate, but TCP also has so-called long connection and short connection, generally in the case that the application is not enabled keepalived, the TCP connection after the establishment of a data request to get results after the disconnection, A long connection is not immediately disconnected after a data request, but waits for the application-defined timeout to be met and then disconnects (or receives the other's Fin)


When TCP establishes a connection, it is said that W is a three-time handshake, which is typically initiated by the client to the server-side first connection request

When TCP disconnects, it is called a four-time wave, and it is possible that the client initiated the connection or the server-initiated first.


In this case, the client initiates a disconnect request (but both sides send fin)

fin_wait1: The active party initiates a disconnect request and waits for confirmation, transferring its status to Fin-wait1

close-wait: The passive side receives the fin message, replies to the ACK, and turns the status to Close_wait

In TCP connection, you can no longer send data after you issue the fin bit, but it is readable, so after the passive side replied to the active fin, as long as they have not sent the fin bit, you can send the data has not been sent out

fin_wait2: The active party receives the ACK from the other side and transfers the status to Fin_wait2

last_ack: The passive side sends the FIN and turns its TCP connection status to Last_ack, meaning that the connection can be closed after waiting for the last acknowledgment message

time_wait: The active side receives the passive side fin, the TCP connection status to Time_wait, where the active side will wait 2MSL time after the transfer to closed

closed: When the passive party receives the confirmation message, it closes the connection


In Linxu, such as the maintenance tuning process for Web services, we often need to focus on the server's connectivity to maximize server performance

The netstat command is the most commonly used command in Linux to display the network subsystem, which can display routing tables, connections established on an address, status of TCP connections, and so on.

Netstat

--route,-r Display routing table

--groups Display multicast group related information

-T: Show TCP connection related

-U: Show UDP connection related

-P: Show process name

-N: Digitally replace the display port and other information

-L: Displays the listening state of the

-A: Displays the socket information for all listening and non-listening status

To view the listening services that are turned on on the server:

NETSTAT-TUNLP (digitally shows which processes are listening on some ports of TCP or UDP)

Count 80 Port connections

Netstat-nat | Grep-i "80" | Wc-l

View HTTP concurrent connection requests and TCP status

Netstat-nat | Grep-i "80"

To view the number of HTTP connections already established

Netstat-nat | grep ". *80.*established"

View the number of processes related to httpd

PS aux | grep httpd |wc-l or Ps-ef | grep httpd | Wc-l

This article is from the "Zxcvbnm Xuan ye" blog, please be sure to keep this source http://10764546.blog.51cto.com/10754546/1706702

TCP connection Status and netstat command

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.