TCP: connection and data

Establish a TCP connection and send a message.

Network

Scroll sideways to exploreOpen full diagram
PC1 at 192.168.1.1/24 is directly linked to PC2 at 192.168.1.100/24.
PC1 is the client; PC2 is the server on TCP port 5555.
Open a console

1. Test the closed port

PC1

ping -n -c 3 -W 1 192.168.1.100
nc -v -N -w 3 192.168.1.100 5555

The ping succeeds, but the TCP connection is refused.

2. Start the server and send a message

PC2

nc -l -k 5555 >> /tmp/lab-tcp.txt &
listener_pid=$!

PC1

timeout 120 tcpdump -U --immediate-mode -i eth0 -w /tmp/lab-tcp.pcap "tcp port 5555" &
capture_pid=$!
sleep 1

PC1

printf 'tcp-handshake-lab\n' | nc -N -w 5 192.168.1.100 5555

3. Check the handshake and data

PC1

sleep 2
kill -INT "$capture_pid"
wait "$capture_pid" || true
tcpdump -nn -e -r /tmp/lab-tcp.pcap

Find SYN, SYN+ACK, ACK, followed by data packets.

PC2

cat /tmp/lab-tcp.txt
kill "$listener_pid"

The file should contain tcp-handshake-lab.

Validation

Click "Check". Once all steps pass, click "End".