Site icon Voina Blog (a tech warrior's blog)

Bash one liners: Keeping an Eye on Connections: Using tcpdump to Monitor Client-Server Port Activity

Advertisements

In the world of network administration and troubleshooting, there are countless moments when you need to verify connectivity. Is a specific client successfully reaching a server on a designated port? Is the server responding? Or is something silently dropping the packets? For these scenarios, the command-line tool tcpdump is an invaluable asset – powerful, versatile, and readily available on most Unix-like systems.

Let’s break down how to use tcpdump to monitor if a particular client (e.g., 192.168.6.1) is connecting or attempting to connect to a specific server port (e.g., 7210).

The Core Command:

sudo tcpdump -i any -vv -nn tcp port 7210 and host 192.168.6.1

Let’s dissect this command to understand each component:

What to Look For in the Output:

When the client attempts to connect, you’re primarily looking for the TCP three-way handshake:

  1. SYN: The client (192.168.6.1) sends a packet with the SYN (synchronize) flag set to the server’s IP on port 7210.
    • Example: IP 192.168.6.1.54321 > your_server_ip.7210: Flags [S], ...
  2. SYN-ACK: If the server is listening on port 7210 and accepts the connection, it responds with a packet having both SYN and ACK (acknowledgment) flags set.
    • Example: IP your_server_ip.7210 > 192.168.6.1.54321: Flags [S.], ...
  3. ACK: The client acknowledges the server’s response by sending a packet with the ACK flag set.
    • Example: IP 192.168.6.1.54321 > your_server_ip.7210: Flags [.], ...

After this, you’ll see packets with data (Flags [P.] for PSH-ACK) or just acknowledgments (Flags [.]).

Further tcpdump Tips:

Save the output in Wireshark format

sudo tcpdump -i any -vv -nn -w capture.pcap tcp port 7210 and host 192.168.6.1

Exit mobile version