A basic reference to monitor network connections

Intro

This short article will help you to check if there is indeed a connection established, if a server is still listening or has died, how many connections can be established to a listening server etc
This is very useful for debugging when…


This content originally appeared on DEV Community and was authored by rounakcodes

Intro

This short article will help you to check if there is indeed a connection established, if a server is still listening or has died, how many connections can be established to a listening server etc
This is very useful for debugging when your application communicates with various external services (like a database) and you want to ensure that there is no issue in communicating.
The below commands were executed on a ubuntu machine but similar tools exist on other operating systems.

Read and understand connection related information

Start a server

conn-1

Start a http server on port 80 of localhost

Monitor listening servers

image
127.0.0.1 is the Local address which means only your computer can connect to the server

0.0.0.0:* is the Foreign address column value i.e. The IP address and port number of the remote computer to which the socket is connected. The value 0.0.0.0:* means not connected to any remote computer.

Connect to the server

image

Use telnet to connect to the server
(We just want to connect to a server, use telnet or whatever tool you prefer)

Monitor listening servers and connections

image

  • client port (51580 in my case) is a randomly chosen free port
  • process (server) which is listening has state LISTEN
  • ESTABLISHED indicates that a connection has been established
  • protocol is tcp
  • 60755 is the process id
    • killing the process will kill the connection

Connect and monitor again

image
Start one more connection
image
Observe the new connection info

Close the connections and monitor

image

image

TIME_WAIT indicates that local endpoint has closed the connection. The connection is being kept around so that any delayed packets can be matched to the connection and handled appropriately. The connections will be removed when they time out within four minutes.

Notes

  • TCP/IP is a protocol stack for communication, a socket is an endpoint in a (bidirectional) communication.
  • Connections are identified by the tuple {SRC-IP, SRC-PORT, DEST-IP, DEST-PORT, PROTOCOL}. If any element in the tuple is different, then it is a completely independent connection.
    • In our above examples, though server port (80) is same, client ports are different
  • On a server, a process is listening on a port. Once it gets a connection, it hands it off to another thread. The communication never hogs the listening port.
  • When a client connects to a server, it picks a random, unused high-order source port. This way, a single client can have up to ~64k connections to the server for the same destination port.


This content originally appeared on DEV Community and was authored by rounakcodes


Print Share Comment Cite Upload Translate Updates
APA

rounakcodes | Sciencx (2021-05-22T12:26:22+00:00) A basic reference to monitor network connections. Retrieved from https://www.scien.cx/2021/05/22/a-basic-reference-to-monitor-network-connections/

MLA
" » A basic reference to monitor network connections." rounakcodes | Sciencx - Saturday May 22, 2021, https://www.scien.cx/2021/05/22/a-basic-reference-to-monitor-network-connections/
HARVARD
rounakcodes | Sciencx Saturday May 22, 2021 » A basic reference to monitor network connections., viewed ,<https://www.scien.cx/2021/05/22/a-basic-reference-to-monitor-network-connections/>
VANCOUVER
rounakcodes | Sciencx - » A basic reference to monitor network connections. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/22/a-basic-reference-to-monitor-network-connections/
CHICAGO
" » A basic reference to monitor network connections." rounakcodes | Sciencx - Accessed . https://www.scien.cx/2021/05/22/a-basic-reference-to-monitor-network-connections/
IEEE
" » A basic reference to monitor network connections." rounakcodes | Sciencx [Online]. Available: https://www.scien.cx/2021/05/22/a-basic-reference-to-monitor-network-connections/. [Accessed: ]
rf:citation
» A basic reference to monitor network connections | rounakcodes | Sciencx | https://www.scien.cx/2021/05/22/a-basic-reference-to-monitor-network-connections/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.