Skip to content

UDP datagrams

Module
TCP, UDP, and Ports
Difficulty
Easy
Updated
Tested on
Ubuntu 24.04.5 LTS, netlab 1.0, GNU Bash 5.2.21, tcpdump 4.99.4
On this page

Some exchanges need one question and one answer. Opening and closing a connection could add more messages than the useful exchange itself. You will watch one question and answer, then see what UDP does for the program and what the program must do itself.

Finish Opening and closing TCP connections. Leave machine shells and run netlab reset from the VM if needed. This experiment temporarily enables the lab’s lookup service. You need not understand the lookup’s contents yet. How DNS Finds Services teaches what the question and answer mean.

At the VM prompt run netlab mode dns on, answering sudo’s password question. The mode command rebuilds the running lab itself, so leave all machine shells before using it. Check netlab status, then open two terminals on laptop. The replay labels the status check with a comment after #; Bash ignores that comment.

Turn dns on and check the lab
learner@rootvolt:~$ netlab mode dns on[sudo] password for learner: Mode dns is on: dns and ns run; lab machines use 10.77.20.53.learner@rootvolt:~$ netlab status # dns is onLab is up. Modes on: dns. Fault: none.

MACHINE  NETWORK     ADDRESS                      DEFAULT ROUTE  COMPARED WITH THE START
laptop   home        10.77.10.10/24               10.77.10.1     same
phone    home        10.77.10.11/24               10.77.10.1     same
router   home, site  10.77.10.1/24 10.77.20.1/24  -              same
web      site        10.77.20.80/24               10.77.20.1     same
dns      site        10.77.20.53/24               10.77.20.1     same
ns       site        10.77.20.54/24               10.77.20.1     same

Switch sw-home (home): laptop, phone, router
Switch sw-site (site): dns, ns, router, web
Services: web http 80, web https 443, web http 8080, web ssh 22, dns dns 53, ns dns 53learner@rootvolt:~$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, networking lab (netlab 1.0), GNU Bash 5.2.21. From the VM, enable the lookup service and check that its mode is on.
Steps (9)
  1. Type netlab mode dns on
  2. Press Enter
  3. Output: [sudo] password for learner:
  4. Type the password (the terminal shows nothing)
  5. Press Enter
  6. Output: Mode dns is on: dns and ns run; lab machines use 10.77.20.53.
  7. Type netlab status # dns is on
  8. Press Enter
  9. Output: Lab is up. Modes on: dns. Fault: none. MACHINE NETWORK ADDRESS DEFAULT ROUTE COMPARED WITH THE START laptop home 10.77.10.10/24 10.77.10.1 same phone home 10.77.10.11/24 10.77.10.1 same router home, site 10.77.10.1/24 10.77.20.1/24 - same web site 10.77.20.80/24 10.77.20.1 same dns site 10.77.20.53/24 10.77.20.1 same ns site 10.77.20.54/24 10.77.20.1 same Switch sw-home (home): laptop, phone, router Switch sw-site (site): dns, ns, router, web Services: web http 80, web https 443, web http 8080, web ssh 22, dns dns 53, ns dns 53

In terminal 1 run sudo tcpdump -n -i eth0 udp port 53. The filter selects UDP traffic involving port 53. In terminal 2 run dig +short web.lab.test. Here dig sends a lookup, and +short asks for brief printed output. Return to terminal 1 and stop with Ctrl+C.

Predict: how many captured rows will this exchange have compared with the page request’s twelve TCP rows?

One lookup over UDP — listener
learner@laptop:~$ sudo tcpdump -n -i eth0 udp port 53[sudo] password for learner: tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes08:26:51.000870 IP 10.77.10.10.42569 > 10.77.20.53.53: 50716+ [1au] A? web.lab.test. (53)
08:26:51.001345 IP 10.77.20.53.53 > 10.77.10.10.42569: 50716* 1/1/1 A 10.77.20.80 (90)^C2 packets captured
2 packets received by filter
0 packets dropped by kernellearner@laptop:~$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, networking lab (netlab 1.0), GNU Bash 5.2.21. Laptop records one outgoing UDP message and one incoming UDP message, with no transport opening or close.
Steps (10)
  1. Type sudo tcpdump -n -i eth0 udp port 53
  2. Press Enter
  3. Output: [sudo] password for learner:
  4. Type the password (the terminal shows nothing)
  5. Press Enter
  6. Output: tcpdump: verbose output suppressed, use -v[v]... for full protocol decode listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
  7. The second terminal finished. Return here and press Ctrl+C to stop listening.
  8. Output: 08:26:51.000870 IP 10.77.10.10.42569 > 10.77.20.53.53: 50716+ [1au] A? web.lab.test. (53) 08:26:51.001345 IP 10.77.20.53.53 > 10.77.10.10.42569: 50716* 1/1/1 A 10.77.20.80 (90)
  9. Press Ctrl + C
  10. Output: 2 packets captured 2 packets received by filter 0 packets dropped by kernel
One lookup over UDP — send
learner@laptop:~$ dig +short web.lab.test10.77.20.80learner@laptop:~$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, networking lab (netlab 1.0), GNU Bash 5.2.21. The second terminal sends the lookup and prints its short result.
Steps (3)
  1. Type dig +short web.lab.test
  2. Press Enter
  3. Output: 10.77.20.80
Check your answer

There are two rows: one to 10.77.20.53 on port 53 and one back. The previous lesson’s recorded TCP request has twelve rows. These counts describe these runs, not a fixed count for all lookups or page requests.

UDP, the User Datagram Protocol, sends separate messages without TCP’s connection opening. A datagram is one such message, kept separate from other messages. UDP still has source and destination ports. The answer swaps the address-and-port pairs, so it goes back to the program that asked.

Read both captured rows, even though dig prints only one short result. Dig prints the answer for you. Tcpdump shows the messages sent between laptop and the lookup service.

UDP adds no transport sequence numbering or acknowledgments. The receiving program gets separate datagrams. UDP does not put them back in the order they were sent.

If a datagram is lost, UDP does not retransmit it. The program must decide whether an answer is missing and whether another attempt is useful. An application reply is still possible, as the captured answer shows. The application chooses to send that reply. UDP itself sends no acknowledgment.

No datagram is lost in this recording, so it does not show what happens after a loss. It shows an exchange without a transport handshake. The table lists what TCP and UDP do. This capture does not test every item in the table.

Attribute TCP UDP
Connection Agrees to talk first No transport handshake
Ordering Delivers bytes in order Does not put datagrams in order
Loss handling Resends missing bytes Program must handle loss
Typical uses File transfer, many web exchanges Lookups, calls, game updates

Choose based on the application’s needs. A file needs every byte in order. An old game update may no longer help after a later update arrives. The program must still handle missing, repeated or late messages when they matter.

“UDP is unreliable, so it is bad.” UDP leaves more decisions to the program. That can suit a program built to handle them. The captured lookup succeeds without TCP’s opening.

“UDP is always faster.” Two rows instead of twelve do not prove UDP is always faster. The network, message size and program all affect how long an exchange takes.

Some application protocols can use either transport. This lookup uses UDP. That does not mean every lookup does. Likewise, a port number alone does not identify an application. The next lesson tests that assumption directly.

Your client port and the lookup’s identifier vary; your number will differ. Compare the reversed pairs and row kinds instead of copying the sample’s temporary values.

Before running again, predict which pairs reverse in the answer and whether a FIN row will appear. Run the two-terminal lookup experiment again. Compare your own rows with the prediction, and say whether two successful rows promise that the next datagram will arrive.

Solution

The address-and-port pairs reverse. There is no TCP FIN because this is a UDP exchange. A successful answer does not promise every later datagram will arrive. Use the two replays as a check on direction, not a promise about temporary client ports.

Stop listeners, leave machine shells, and run netlab mode dns off from the VM. Check netlab status; this cleanup replay shows Modes on: none. Later experiments tell you when to enable the lookup service again.

Turn dns off and check the lab
learner@rootvolt:~$ netlab mode dns offMode dns is off.learner@rootvolt:~$ netlab status # dns is offLab is up. Modes on: none. Fault: none.

MACHINE  NETWORK     ADDRESS                      DEFAULT ROUTE  COMPARED WITH THE START
laptop   home        10.77.10.10/24               10.77.10.1     same
phone    home        10.77.10.11/24               10.77.10.1     same
router   home, site  10.77.10.1/24 10.77.20.1/24  -              same
web      site        10.77.20.80/24               10.77.20.1     same

Switch sw-home (home): laptop, phone, router
Switch sw-site (site): router, web
Services: web http 80, web https 443, web http 8080, web ssh 22learner@rootvolt:~$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, networking lab (netlab 1.0), GNU Bash 5.2.21. After the lookup experiment, turn the mode off and check the lab.
Steps (6)
  1. Type netlab mode dns off
  2. Press Enter
  3. Output: Mode dns is off.
  4. Type netlab status # dns is off
  5. Press Enter
  6. Output: Lab is up. Modes on: none. Fault: none. MACHINE NETWORK ADDRESS DEFAULT ROUTE COMPARED WITH THE START laptop home 10.77.10.10/24 10.77.10.1 same phone home 10.77.10.11/24 10.77.10.1 same router home, site 10.77.10.1/24 10.77.20.1/24 - same web site 10.77.20.80/24 10.77.20.1 same Switch sw-home (home): laptop, phone, router Switch sw-site (site): router, web Services: web http 80, web https 443, web http 8080, web ssh 22
  • Recognize a datagram exchange without a transport opening.
  • Separate application answers from transport acknowledgments.
  • Choose delivery services based on the program’s needs.

Next, Choosing and recognizing transports compares service evidence with port-number guesses.