Practice: TCP, UDP, and Ports
On this page
A report says “the server is unavailable” because one connection failed and one datagram received no answer. Check that report with a working page request, a refused connection, and a datagram that gets no answer.
Before you start
Section titled “Before you start”Finish How a home router shares one address (NAT basics). Confirm NAT is off at the VM prompt. Stop listeners and leave machine shells before changing modes. Run netlab reset if settings changed, then netlab mode dns on for the silent-datagram test. This mode enables the lookup service, as in UDP datagrams. It does not enable NAT.
Have a terminal on web for its listener list and two on laptop for recording traffic. Every command belongs inside the supplied lab. Do not run these tests against your real router or another person’s service.
Explain each result in your report
Section titled “Explain each result in your report”Meet these five goals.
- List web’s listening TCP ports and match each distinct number to the lab cast. Read which program owns each socket and say what its name cannot prove.
- Save a successful page exchange from laptop. Identify its client address and port, server address and port, opening, data and close. Explain one acknowledgment using the preceding data range.
- Record a TCP attempt to a closed port. Name the machine and port that sent the reset, and mark that row.
- Record a UDP datagram to the open lookup service that receives no reply. Explain why no reply does not prove that the port is closed.
- Compare your client pair with the outside pair in the preceding NAT lesson. Explain which address web sees with translation off and why ports were needed to separate clients with translation on.
Keep the listener list and your saved capture. Mark the client and server pairs, then group the opening, data and closing rows. Write what each test tells you. Include where you listened, the filter, and the command that sent traffic. Say whether you read each result in the sender’s terminal or in the capture.
Save first, then read the same evidence
Section titled “Save first, then read the same evidence”On web run ss -tln, then sudo ss -tlnp for the program check. On laptop’s first terminal run sudo tcpdump -n -i eth0 -w transports.pcap tcp or udp or icmp. The option -w writes frames to the named file instead of printing each one live. Supply your Ubuntu password if asked.
Predict: will a silent UDP test have the same shape as the refused TCP test?
In laptop’s second terminal run curl -sS http://10.77.20.80/index.html, then curl -sS http://10.77.20.80:81/, then echo hi > /dev/udp/10.77.20.53/53. Let each command return before the next. The Bash datagram command prints nothing; that is not evidence of a received reply.
Return to terminal 1 and press Ctrl+C. Read the saved file with tcpdump -n -r transports.pcap. This read needs no sudo in the captured lab. Compare the file’s rows with your predictions. Keep the file after finishing.
Mistakes to recognize
Section titled “Mistakes to recognize”“Both failures prove the server is down.” Web sent a reset for one test and no answer for the other. Those are different results. The page request also worked, so the machine was running.
“The server port alone identifies my connection.” Use both endpoint pairs. Write your client port beside the server port, even when you recognize the server number.
Good to know
Section titled “Good to know”Your number will differ for client ports, sequence numbers and timestamps. Copy your own values without changing the saved evidence. The file records what reached laptop’s interface, not all traffic handled by either switch. A capture filter can also omit traffic; keep it with the report.
Try it yourself
Section titled “Try it yourself”Run the tests above and compare your annotations with all five goals before opening the solution.
Hint
Find SYN and the reversed endpoint pairs first. Then separate positive data lengths, FIN flags and the reset. The final datagram is not part of the TCP conversation, even though it appears in the same file.
Solution
learner@web:~$ ss -tlnState Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 5 *:443 *:*
LISTEN 0 5 *:8080 *:* learner@web:~$ sudo ss -tlnp[sudo] password for learner: State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=113,fd=4))
LISTEN 0 5 *:80 *:* users:(("python3",pid=106,fd=3))
LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=113,fd=3))
LISTEN 0 5 *:443 *:* users:(("python3",pid=108,fd=3))
LISTEN 0 5 *:8080 *:* users:(("python3",pid=107,fd=3)) learner@web:~$ Steps (9)
- Type
ss -tln - Press Enter
- Output:
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 5 *:80 *:* LISTEN 0 128 [::]:22 [::]:* LISTEN 0 5 *:443 *:* LISTEN 0 5 *:8080 *:* - Type
sudo ss -tlnp - Press Enter
- Output:
[sudo] password for learner: - Type the password (the terminal shows nothing)
- Press Enter
- Output:
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=113,fd=4)) LISTEN 0 5 *:80 *:* users:(("python3",pid=106,fd=3)) LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=113,fd=3)) LISTEN 0 5 *:443 *:* users:(("python3",pid=108,fd=3)) LISTEN 0 5 *:8080 *:* users:(("python3",pid=107,fd=3))
learner@laptop:~$ sudo tcpdump -n -i eth0 -w transports.pcap tcp or udp or icmp[sudo] password for learner: tcpdump: listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes^C15 packets captured
15 packets received by filter
0 packets dropped by kernellearner@laptop:~$ tcpdump -n -r transports.pcapreading from file transports.pcap, link-type EN10MB (Ethernet), snapshot length 262144
08:35:51.929538 IP 10.77.10.10.35836 > 10.77.20.80.80: Flags [S], seq 1764050050, win 64240, options [mss 1460,sackOK,TS val 3673116623 ecr 0,nop,wscale 10], length 0
08:35:51.929592 IP 10.77.20.80.80 > 10.77.10.10.35836: Flags [S.], seq 1517128715, ack 1764050051, win 65160, options [mss 1460,sackOK,TS val 2129027938 ecr 3673116623,nop,wscale 10], length 0
08:35:51.929609 IP 10.77.10.10.35836 > 10.77.20.80.80: Flags [.], ack 1, win 63, options [nop,nop,TS val 3673116623 ecr 2129027938], length 0
08:35:51.929653 IP 10.77.10.10.35836 > 10.77.20.80.80: Flags [P.], seq 1:85, ack 1, win 63, options [nop,nop,TS val 3673116623 ecr 2129027938], length 84: HTTP: GET /index.html HTTP/1.1
08:35:51.929669 IP 10.77.20.80.80 > 10.77.10.10.35836: Flags [.], ack 85, win 64, options [nop,nop,TS val 2129027938 ecr 3673116623], length 0
08:35:51.931623 IP 10.77.20.80.80 > 10.77.10.10.35836: Flags [P.], seq 1:173, ack 85, win 64, options [nop,nop,TS val 2129027940 ecr 3673116623], length 172: HTTP: HTTP/1.0 200 OK
08:35:51.931655 IP 10.77.10.10.35836 > 10.77.20.80.80: Flags [.], ack 173, win 63, options [nop,nop,TS val 3673116625 ecr 2129027940], length 0
08:35:51.931681 IP 10.77.20.80.80 > 10.77.10.10.35836: Flags [P.], seq 173:444, ack 85, win 64, options [nop,nop,TS val 2129027940 ecr 3673116625], length 271: HTTP
08:35:51.931683 IP 10.77.10.10.35836 > 10.77.20.80.80: Flags [.], ack 444, win 63, options [nop,nop,TS val 3673116625 ecr 2129027940], length 0
08:35:51.931710 IP 10.77.20.80.80 > 10.77.10.10.35836: Flags [F.], seq 444, ack 85, win 64, options [nop,nop,TS val 2129027940 ecr 3673116625], length 0
08:35:51.931762 IP 10.77.10.10.35836 > 10.77.20.80.80: Flags [F.], seq 85, ack 445, win 63, options [nop,nop,TS val 3673116625 ecr 2129027940], length 0
08:35:51.931818 IP 10.77.20.80.80 > 10.77.10.10.35836: Flags [.], ack 86, win 64, options [nop,nop,TS val 2129027940 ecr 3673116625], length 0
08:35:52.438021 IP 10.77.10.10.54652 > 10.77.20.80.81: Flags [S], seq 2616277940, win 64240, options [mss 1460,sackOK,TS val 2600819127 ecr 0,nop,wscale 10], length 0
08:35:52.438074 IP 10.77.20.80.81 > 10.77.10.10.54652: Flags [R.], seq 0, ack 2616277941, win 0, length 0
08:35:52.941029 IP 10.77.10.10.46192 > 10.77.20.53.53: domain [length 3 < 12] (invalid)learner@laptop:~$ Steps (12)
- Type
sudo tcpdump -n -i eth0 -w transports.pcap tcp or udp or icmp - Press Enter
- Output:
[sudo] password for learner: - Type the password (the terminal shows nothing)
- Press Enter
- Output:
tcpdump: listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes - The second terminal finished. Return here and press Ctrl+C to stop listening.
- Press Ctrl + C
- Output:
15 packets captured 15 packets received by filter 0 packets dropped by kernel - Type
tcpdump -n -r transports.pcap - Press Enter
- Output:
reading from file transports.pcap, link-type EN10MB (Ethernet), snapshot length 262144 08:35:51.929538 IP 10.77.10.10.35836 > 10.77.20.80.80: Flags [S], seq 1764050050, win 64240, options [mss 1460,sackOK,TS val 3673116623 ecr 0,nop,wscale 10], length 0 08:35:51.929592 IP 10.77.20.80.80 > 10.77.10.10.35836: Flags [S.], seq 1517128715, ack 1764050051, win 65160, options [mss 1460,sackOK,TS val 2129027938 ecr 3673116623,nop,wscale 10], length 0 08:35:51.929609 IP 10.77.10.10.35836 > 10.77.20.80.80: Flags [.], ack 1, win 63, options [nop,nop,TS val 3673116623 ecr 2129027938], length 0 08:35:51.929653 IP 10.77.10.10.35836 > 10.77.20.80.80: Flags [P.], seq 1:85, ack 1, win 63, options [nop,nop,TS val 3673116623 ecr 2129027938], length 84: HTTP: GET /index.html HTTP/1.1 08:35:51.929669 IP 10.77.20.80.80 > 10.77.10.10.35836: Flags [.], ack 85, win 64, options [nop,nop,TS val 2129027938 ecr 3673116623], length 0 08:35:51.931623 IP 10.77.20.80.80 > 10.77.10.10.35836: Flags [P.], seq 1:173, ack 85, win 64, options [nop,nop,TS val 2129027940 ecr 3673116623], length 172: HTTP: HTTP/1.0 200 OK 08:35:51.931655 IP 10.77.10.10.35836 > 10.77.20.80.80: Flags [.], ack 173, win 63, options [nop,nop,TS val 3673116625 ecr 2129027940], length 0 08:35:51.931681 IP 10.77.20.80.80 > 10.77.10.10.35836: Flags [P.], seq 173:444, ack 85, win 64, options [nop,nop,TS val 2129027940 ecr 3673116625], length 271: HTTP 08:35:51.931683 IP 10.77.10.10.35836 > 10.77.20.80.80: Flags [.], ack 444, win 63, options [nop,nop,TS val 3673116625 ecr 2129027940], length 0 08:35:51.931710 IP 10.77.20.80.80 > 10.77.10.10.35836: Flags [F.], seq 444, ack 85, win 64, options [nop,nop,TS val 2129027940 ecr 3673116625], length 0 08:35:51.931762 IP 10.77.10.10.35836 > 10.77.20.80.80: Flags [F.], seq 85, ack 445, win 63, options [nop,nop,TS val 3673116625 ecr 2129027940], length 0 08:35:51.931818 IP 10.77.20.80.80 > 10.77.10.10.35836: Flags [.], ack 86, win 64, options [nop,nop,TS val 2129027940 ecr 3673116625], length 0 08:35:52.438021 IP 10.77.10.10.54652 > 10.77.20.80.81: Flags [S], seq 2616277940, win 64240, options [mss 1460,sackOK,TS val 2600819127 ecr 0,nop,wscale 10], length 0 08:35:52.438074 IP 10.77.20.80.81 > 10.77.10.10.54652: Flags [R.], seq 0, ack 2616277941, win 0, length 0 08:35:52.941029 IP 10.77.10.10.46192 > 10.77.20.53.53: domain [length 3 < 12] (invalid)
learner@laptop:~$ curl -sS http://10.77.20.80/index.html<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>web.lab.test</title>
</head>
<body>
<h1>web.lab.test</h1>
<p>This page comes from the lab machine web.</p>
<p><a href="hello.txt">hello.txt</a> · <a href="signin.html">Sign in</a></p>
</body>
</html>learner@laptop:~$ curl -sS http://10.77.20.80:81/curl: (7) Failed to connect to 10.77.20.80 port 81 after 0 ms: Couldn't connect to serverlearner@laptop:~$ echo hi > /dev/udp/10.77.20.53/53learner@laptop:~$ Steps (8)
- Type
curl -sS http://10.77.20.80/index.html - Press Enter
- Output:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>web.lab.test</title> </head> <body> <h1>web.lab.test</h1> <p>This page comes from the lab machine web.</p> <p><a href="hello.txt">hello.txt</a> · <a href="signin.html">Sign in</a></p> </body> </html> - Type
curl -sS http://10.77.20.80:81/ - Press Enter
- Output:
curl: (7) Failed to connect to 10.77.20.80 port 81 after 0 ms: Couldn't connect to server - Type
echo hi > /dev/udp/10.77.20.53/53 - Press Enter
The page exchange opens with SYN, SYN and ACK, then ACK. Rows with data lengths above zero carry the request and answer. FIN flags show that each end has finished sending. The closed port answers with a reset instead of completing an opening. The UDP test has one outgoing datagram and no returning message in this recording.
With NAT off, the TCP rows keep laptop’s original IP address through the exchange. In the previous lesson’s site-side capture, web instead receives router’s address and a translated client pair. Your capture has NAT off. The previous capture has NAT on, so router changes the address there.
After recording, stop listeners and leave shells. Run netlab mode dns off, then netlab status from the VM as shown in UDP datagrams. The next module expects NAT off and enables only the mode it needs.
Recall check
Section titled “Recall check”Does receiving no UDP reply prove that a port is closed?
Answer
No. An open service can ignore input it does not understand, and traffic can be lost or filtered. You know only that your listener saw no reply there while it was running.
- Save a capture before marking its conversations.
- Use both endpoint pairs and the transport’s behavior.
- Keep refusals, silence and successful service evidence separate.
Next, Getting Network Settings Automatically follows the source of a device’s settings.