0

If I have the following netstat output:

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:3306          127.0.0.1:21950         ESTABLISHED 2129/mysqld
tcp        0      0 127.0.0.1:38766         127.0.0.1:10033         TIME_WAIT   -

If both ends of the socket are on the local machine, can the server and the client appear in either column?

1

No, the local address is always the end of the connection that was opened by the process being described. In this case, the MySQL server process listens on port 3306, so that’s its local address in any established connection. The queues are also specific to the connection direction described.

For an established connection, you should see the symmetric connection elsewhere in netstat or ss’s output.

TIME_WAIT connections are a special case. TIME_WAIT is used to ensure a new connection doesn’t receive stray packets; only the end of the connection which initiates its termination ever reaches that state (because the other end knows that its correspondent won’t send anything more). The connection is preserved by the operating system, so it’s no longer associated with a process; the local address is the end which closed the connection.

  • Thanks. What if the socket is in the TIME_WAIT state, like in my edit? Does that mean the information about who opened the connection is lost? – Mihai Mar 9 '18 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.