Chapter 8 · Transport LayerThe student-friendly guide + hands-on Kali labs

Chapter 8 · The student-friendly guide

The Transport Layer

The layer that turns “host-to-host” into “app-to-app.” It tracks every conversation with port numbers, and offers two ways to deliver: TCP (reliable) and UDP (fast).

Ports & socketsTCP — reliable 3-way handshakeUDP — best-effort

Use ← → arrow keys, the dots below, or the ☰ menu to navigate. Switch to the Lab Guide up top.

The big picture

What the transport layer does

💡
Think of it like… a building’s post room. The network layer gets mail to the right building (IP address); the transport layer gets it to the right person / office inside (port number) — and decides whether to send it recorded-delivery (TCP) or normal post (UDP).
🔀
1

Multiplex

Track many conversations at once with ports & sockets.

📦
2

Segment

Break the data stream into segments; reassemble at the far end.

🔒
3

TCP

Reliable, ordered, flow-controlled delivery.

4

UDP

Fast, connectionless, best-effort delivery.

Part 1 · Transporting data

Logical communication between applications

App-to-app, not just host-to-host

The transport layer is responsible for logical communication between applications running on different hosts.

The bridge

It’s the link between the application layer above and the lower layers that handle actual network transmission.

App on Host A
transport layer = logical app-to-app link
App on Host B

Part 1 · Transporting data

Transport-layer responsibilities

🗂️

Track conversations

Keep each app’s conversation separate.

✂️

Segment & reassemble

Split the stream into segments, rebuild in order.

🏷️

Add a header

Ports, sequence numbers, checksums, flags.

🔀

Multiplex

Interleave many conversations on one link.

📌
Why segment? IP moves packets but says nothing about reliable or ordered delivery. The transport layer adds that — chopping data into trackable pieces and managing each conversation’s reliability.

Part 1 · Transporting data

Two transport protocols

IP doesn’t specify how packets are delivered — the transport layer does, with two very different tools:

TCP — Transmission Control Protocol

Connection-oriented, reliable, ordered, flow-controlled. More overhead, guaranteed delivery.

UDP — User Datagram Protocol

Connectionless, best-effort, minimal overhead. Fast, but no guarantees.

💡
Think of it like… TCP = a phone call (connect first, confirm you heard everything). UDP = shouting across a room (fast, but you don’t know if they caught every word).

Part 2 · Ports & sockets

Port numbers: many conversations at once

Source port

Identifies the originating application on the local host (often a dynamic/ephemeral number).

Destination port

Identifies the service on the remote host (usually a well-known number, e.g. 443 for HTTPS).

Laptop
:51000 (source)
segment carries both ports
Web server
:443 (dest)

Part 2 · Ports & sockets

Sockets: IP + port together

A socket

192.168.1.5:51000

= IP address + port number. The source and destination sockets together form a socket pair that uniquely names one connection.

Why it matters

Sockets let multiple processes on one client stay distinct, and let a server tell many connections apart — even to the same service.

🧠
Memory hook: a connection is uniquely identified by 4 things: source IP, source port, dest IP, dest port — the socket pair.

Part 2 · Ports & sockets

Three ranges of port numbers

GroupRangeUsed for
Well-known0 – 1023Reserved for common services (web, email, SSH). Lets clients easily find the service.
Registered1024 – 49151Assigned by IANA to specific apps (e.g. Cisco RADIUS = 1812).
Dynamic / private49152 – 65535Ephemeral ports the OS picks for the client side of a connection.
📌
16-bit field → ports run 0 to 65535. The client end is usually ephemeral; the server end is usually well-known.

Part 2 · Ports & sockets

Well-known ports to memorise

PortProtoService
20 / 21TCPFTP (data / control)
22TCPSSH
23TCPTelnet
25TCPSMTP (mail send)
53UDP/TCPDNS
67 / 68UDPDHCP (server / client)
PortProtoService
69UDPTFTP
80TCPHTTP
110TCPPOP3
143TCPIMAP
161UDPSNMP
443TCPHTTPS

Self-Test #1

Ports & sockets

Tap a green answer to reveal it.

Q What four values uniquely identify a single connection?
A Source IP + source port + destination IP + destination port (the socket pair).
Q Which port range does a client’s OS pick from for the source port?
A The dynamic / ephemeral range, 49152–65535.
Q Name the well-known ports for SSH, HTTPS and DNS.
A SSH 22, HTTPS 443, DNS 53.
Q Why do transport protocols use port numbers at all?
A To multiplex — track many simultaneous conversations and deliver each to the right application.

Part 3 · TCP

TCP: reliable, in order, flow-controlled

🤝

Establishes a session

Connection-oriented — negotiates a session before sending data.

Reliable delivery

Every segment sent is acknowledged; lost ones are re-sent.

🔢

Same-order delivery

Sequence numbers reorder segments that arrive out of order.

🚦

Flow control

Slows the sender when the receiver is overwhelmed.

📌
Stateful: TCP tracks the state of the session — what it has sent, and what has been acknowledged.

Part 3 · TCP

Inside the TCP header

FieldSizeJob
Source / Dest port16-bit eachIdentify the source & destination applications.
Sequence number32-bitOrders bytes so data can be reassembled.
Acknowledgment number32-bitThe next byte expected — confirms what was received.
Control bits (flags)6-bitURG · ACK · PSH · RST · SYN · FIN.
Window size16-bitHow many bytes the receiver can accept right now (flow control).
Checksum16-bitError-checks the header + data.

Part 3 · TCP

The three-way handshake

Client
1 · SYN →
Server
Server
2 · SYN, ACK →
Client
Client
3 · ACK →
Server
🧠
SYN → SYN-ACK → ACK. It confirms the destination exists, has the service open on that port, and agrees to start the session — then reliable data can flow.

Part 3 · TCP

Control flags & closing a session

The 6 control flags

URG urgent · ACK acknowledge · PSH push
RST reset (error/timeout) · SYN synchronise · FIN finish

4-way teardown

1 · Client → FIN
2 · Server → ACK
3 · Server → FIN
4 · Client → ACK

📌
SYN opens, FIN closes. Each direction is closed independently, so it takes four segments to fully tear a connection down.

Part 3 · TCP · reliability

Guaranteed, ordered delivery

🔢

Sequence numbers

Reorder segments that arrive out of order; detect gaps.

🔁

Retransmission

Unacknowledged segments are re-sent after a timeout.

🎯

SACK

Selective ACK (negotiated in the handshake) acknowledges exactly which bytes arrived — even discontinuous ones.

💡
Think of it like… numbered pages of a report faxed out of order — the sequence numbers let the receiver reassemble them correctly, and re-request only the pages that never arrived.

Part 3 · TCP · flow

Flow control, window size & MSS

Window size

The receiver advertises how many bytes it can accept right now. TCP raises or lowers the flow to match — preventing an overwhelmed receiver from dropping data.

Maximum Segment Size

MTU 1500
− 20 (IPv4 header)
− 20 (TCP header)
= MSS 1460 bytes
🌊
Congestion avoidance: when a router is overloaded it drops packets. TCP notices the loss and backs off its sending rate using timers and congestion-control algorithms.

Self-Test #2

TCP

Tap a green answer to reveal it.

Q Name the three segments of the TCP connection handshake, in order.
A SYN → SYN-ACK → ACK.
Q Which header field lets the receiver reorder out-of-order data?
A The sequence number (32-bit).
Q How is a typical IPv4 MSS of 1460 derived?
A 1500 MTU − 20 (IP header) − 20 (TCP header) = 1460 bytes.
Q What does the window-size field control?
A Flow control — how many bytes the receiver can accept at once.

Part 4 · UDP

UDP: fast and connectionless

Best-effort delivery

UDP just delivers datagrams between apps with very little overhead — no connection setup and no acknowledgment that data arrived.

What it does not do

No session establishment · lost segments are not resent · data is reassembled only in the order it arrives · the sender isn’t told about the receiver’s resources.

💡
Think of it like… posting a stack of unnumbered postcards. They’re light and quick, but some may get lost and they may arrive in any order — and you’ll never know which.

Part 4 · UDP

The UDP header: just 8 bytes

FieldSizeJob
Source port16-bitIdentifies the source application.
Destination port16-bitIdentifies the destination application.
Length16-bitLength of the UDP datagram.
Checksum16-bitError-checks header + data.
8 bytes

Four fields, 64 bits total — far simpler than TCP’s 20-byte header. That tiny header is exactly why UDP is so fast.

Part 4 · choosing

The right protocol for the job

TCPUDP
ConnectionConnection-oriented (handshake)Connectionless
ReliabilityGuaranteed, acknowledgedBest-effort, none
OrderingReordered by sequence numberDelivered as it arrives
OverheadHigher (20-byte header)Low (8-byte header)
Use when…Every byte must arrive in orderSpeed matters more than perfection

Part 4 · UDP

What uses UDP?

📹

Live media

VoIP, live video — can tolerate a little loss but not delay. A dropped frame beats a frozen call.

💬

Request / reply

Simple, quick transactions — DNS and DHCP. Small ask, small answer, retry if needed.

🛠️

App-managed

Apps that handle reliability themselves — SNMP, TFTP.

📌
Full circle: the DNS & DHCP you met in Chapter 7 both ride on UDP — now you know exactly why: small, fast, retry-able request/reply.

Self-Test #3

UDP & choosing a protocol

Tap a green answer to reveal it.

Q How big is the UDP header, and how many fields does it have?
A 8 bytes, 4 fields (source port, dest port, length, checksum).
Q A live video call drops a few packets — why is UDP still the right choice?
A It tolerates minor loss but needs low delay; UDP has no retransmit/handshake to slow it down.
Q You’re downloading a file and every byte must arrive intact. TCP or UDP?
A TCP — reliable, ordered, flow-controlled.
Q Give two protocols that use UDP.
A Any two of: DNS, DHCP, SNMP, TFTP, VoIP/live video.

One-page cheat sheet

Chapter 8 in a single glance

The layer’s job

  • App-to-app logical link
  • Track · segment · header · multiplex
  • Sits above IP

Ports & sockets

  • Socket = IP : port
  • Well-known 0–1023
  • Registered 1024–49151 · dynamic 49152–65535

Key ports

  • 22 SSH · 25 SMTP · 53 DNS
  • 67/68 DHCP · 80 HTTP · 443 HTTPS
  • 110 POP3 · 143 IMAP · 161 SNMP

TCP = reliable

  • SYN → SYN-ACK → ACK
  • Seq / ACK · retransmit · SACK
  • Window size · MSS 1460

UDP = best-effort

  • Connectionless · 8-byte header
  • No ACK, no reorder, no resend
  • Fast & low overhead

Flags

  • SYN opens · FIN closes
  • ACK confirms · RST resets
  • URG · PSH

App-to-app, your way.

Ports and sockets keep every conversation separate; TCP delivers reliably with a handshake, sequencing and flow control; UDP keeps it fast and simple. Revise with the cheat sheet, test yourself with the quizzes — and you’re ready.

Next up → Chapter 9 · Routing Protocols

Ready to make it real? Switch to the 🧪 Lab Guide up top and run these concepts on Kali Linux.

1 / 24

Chapter 8 · Hands-on labs

The Transport Layer, live on Kali Linux

Six short labs that turn the slides into commands you actually run — list live sockets, watch a TCP three-way handshake and teardown packet-by-packet, read sequence & window fields, and compare TCP against UDP head-to-head. Each maps to a Chapter 8 topic and ends by tying what you saw back to the concept.

SET-UP  ·  Open the Kali Terminal. A couple of labs use two terminals (A & B). Tools: ss/netstat, tcpdump, curl, nc, iperf3. Missing one? sudo apt install -y iproute2 tcpdump netcat-openbsd iperf3. The is just the prompt — Copy grabs only the command.
USE RESPONSIBLY  ·  Only capture traffic and connect to hosts you own or are permitted to test. Everything here targets your own machine, your LAN, or sites you’re allowed to reach.
1 · Sockets2 · Ports3 · Handshake 4 · Seq & window5 · UDP6 · TCP vs UDP✓ Answers
1

See Sockets & Conversations

Maps to Ch.8:Ports & sockets — source/destination ports, the socket pair, multiplexing many conversations. You’ll learn:List every live connection and read the four values that make each one unique. Tools:ss, netstat
1

List active TCP connections with their local & remote sockets:

ss -tan
Representative
State   Local Address:Port    Peer Address:Port
ESTAB   192.168.1.23:51000    142.250.74.36:443
LISTEN  0.0.0.0:22            0.0.0.0:*

Each ESTAB line is one conversation: local IP:portpeer IP:port — the socket pair. The :443 is HTTPS; your side (:51000) is an ephemeral port.

2

Generate a connection in Terminal B, then re-run the socket list and find it:

curl -s https://example.com > /dev/null &
ss -tan | grep :443
3

Which process owns which port? (the classic security check):

sudo ss -tanp
# older equivalent:
sudo netstat -tanp
Why it works  ·  ss lists the transport layer’s live conversations. The unique key on every row is the socket pair — the exact multiplexing the slides describe.
Your turn  ·  Open two browser tabs to the same site. In ss, how does your machine tell the two connections apart if the destination IP:port is identical? (answer below)
2

Well-Known Ports & Listening Services

Maps to Ch.8:Port ranges (well-known / registered / dynamic) and the well-known ports table. You’ll learn:Map port numbers to services and see which ports your own machine is listening on. Tools:ss, /etc/services, nmap
1

What is your machine listening on?

ss -tlnp
2

Look up any port number → service in the system’s port database:

grep -wE "22|53|80|443|67|161" /etc/services | head
Representative
ssh     22/tcp
domain  53/tcp
domain  53/udp
http    80/tcp
https   443/tcp
3

Scan a host you own to see which well-known ports are open:

nmap -F 127.0.0.1
Why it works  ·  /etc/services is the well-known-ports table from the slide, and an open port is a server application bound to that number — exactly “a service assigned to a port is open.”
Your turn  ·  Which range do the source ports of your outbound connections fall in (from Lab 1) — well-known, registered, or dynamic? (answer below)
3

Capture the Three-Way Handshake

Maps to Ch.8:TCP connection establishment (SYN, SYN-ACK, ACK) and the control flags. You’ll learn:Watch SYN → SYN-ACK → ACK cross the wire, then the FIN teardown, and read the flags yourself. Tools:tcpdump, curl, two terminals
1

Sniff a single web connection in Terminal A (flags show as [S], [S.], [.], [F.]):

sudo tcpdump -i any -n "tcp port 80 and host example.com"
2

Make the connection in Terminal B:

curl -s http://example.com > /dev/null
Terminal A — the handshake then teardown
IP you.51001 > example.80: Flags [S]   seq 1000          <- SYN
IP example.80 > you.51001: Flags [S.]  seq 9000 ack 1001  <- SYN, ACK
IP you.51001 > example.80: Flags [.]   ack 9001           <- ACK
... data ...
IP you.51001 > example.80: Flags [F.]  ...                <- FIN (teardown)

Read the flags: [S] = SYN, [S.] = SYN+ACK, [.] = ACK, [F.] = FIN+ACK. That’s the exact three-way handshake from the slides, live.

Why it works  ·  Before any HTTP data flows, TCP negotiates the session with SYN / SYN-ACK / ACK — you just watched a connection get established and torn down byte-by-byte.
Your turn  ·  How many packets make up the handshake, and how many the teardown? (answer below)
4

Sequence Numbers, Window & MSS

Maps to Ch.8:TCP reliability (sequence & acknowledgment numbers), flow control (window size), and MSS. You’ll learn:See the seq/ack counters advance and read the advertised window and negotiated MSS. Tools:tcpdump -S, ip
1

Capture with absolute sequence numbers and verbose TCP options:

sudo tcpdump -i any -nvS "tcp port 443 and host example.com"
2

In Terminal B, trigger it and watch seq, ack, win and mss appear:

curl -s https://example.com > /dev/null
Representative — note win and mss
Flags [S], seq 305419896, win 64240, options [mss 1460,sackOK,...]
Flags [S.], seq 87654321, ack 305419897, win 65535, options [mss 1460,...]
Flags [.], ack 1, win 502

seq/ack track every byte (reliability); win is the receiver’s advertised window (flow control); mss 1460 is the max segment size negotiated in the SYN.

3

Where does 1460 come from? Check your link MTU:

ip link show | grep -oE "mtu [0-9]+"
Why it works  ·  You saw the exact fields from the TCP-header slide doing their jobs: sequence/ack for reliable ordering, window for flow control, and MSS = MTU 1500 − 20 − 20 = 1460.
Your turn  ·  If your interface MTU is 1500, what MSS do you expect in the SYN — and why isn’t it 1500? (answer below)
5

UDP: No Handshake, No Promises

Maps to Ch.8:UDP — connectionless, best-effort, low overhead; the 8-byte header. You’ll learn:Send data over UDP with no connection at all, and contrast the capture with TCP’s handshake. Tools:tcpdump, nc -u, dig, two terminals
1

Watch a UDP exchange — a DNS query is pure UDP (Terminal A):

sudo tcpdump -i any -n udp port 53
dig kali.org
Just two packets — no SYN, no ACK, no teardown
IP you.51512 > 192.168.1.1.53: 12345+ A? kali.org.
IP 192.168.1.1.53 > you.51512: 12345 1/0/0 A 192.124.249.13

Compare with Lab 3: no handshake, no acknowledgments, no FIN — the datagram just goes and (maybe) comes back. That’s connectionless, best-effort UDP.

2

Send raw UDP yourself — listener in A, sender in B:

# Terminal A — UDP listener

nc -u -lvp 9999

# Terminal B — UDP sender (type a line, Enter)

nc -u 127.0.0.1 9999
Why it works  ·  UDP sets up nothing — nc -u just starts firing datagrams. No session, no confirmation. That tiny 8-byte header is the whole point: speed over guarantees.
Your turn  ·  In the UDP capture, how many packets did you see compared with the TCP handshake in Lab 3? What’s missing? (answer below)
6

TCP vs UDP, Head-to-Head

Maps to Ch.8:Choosing the right protocol — reliability & ordering (TCP) vs low overhead & speed (UDP). You’ll learn:Measure both protocols with the same tool and feel the trade-off between reliability and overhead. Tools:iperf3, two terminals
1

Start the server in Terminal A (serves both TCP and UDP):

iperf3 -s
2

Test TCP in Terminal B — note the Retr (retransmit) column, proof of TCP’s reliability:

iperf3 -c 127.0.0.1
3

Test UDP — note the Lost/Total Datagrams and Jitter, which only UDP reports:

iperf3 -c 127.0.0.1 -u -b 100M
Representative — UDP reports loss & jitter, TCP reports retransmits
[TCP]  ... Bitrate 44.8 Gbits/sec   Retr 0
[UDP]  ... Bitrate 100 Mbits/sec    Jitter 0.01 ms   0/85000 (0%)
Why it works  ·  Same tool, two protocols: TCP tracks and re-sends (Retr), UDP just fires and measures what fell off (Lost/Jitter). That’s the reliability-vs-overhead trade-off from the slides, quantified.
Your turn  ·  Push the UDP bitrate higher (-b 1G). Does loss appear? Why would that same loss be invisible over TCP? (answer below)

Answer Key & Where Next

Lab 1. The two connections have different source ports (ephemeral) on your machine. Same dest IP:port, different source port → different socket pair → the OS keeps them apart.

Lab 2. Your outbound source ports fall in the dynamic / ephemeral range (49152–65535) — the OS picks them for the client side.

Lab 3. The handshake is 3 packets (SYN, SYN-ACK, ACK); the teardown is 4 (FIN, ACK, FIN, ACK) because each direction closes independently.

Lab 4. You expect MSS 1460: 1500 MTU − 20 (IPv4 header) − 20 (TCP header). The full 1500 can’t be data — the headers have to fit inside the frame too.

Lab 5. UDP showed just 2 packets (query + reply) versus TCP’s handshake. Missing: SYN/SYN-ACK/ACK setup, acknowledgments, and the FIN teardown — UDP has none of them.

Lab 6. At high bitrates UDP loses datagrams (and never resends them). Over TCP that same loss is invisible to the application because TCP retransmits the missing bytes — you’d see it only as lower throughput / higher Retr.

This lab’s toolConnects to…
ss / netstat sockets (Lab 1–2)Chapter 7 — the ports DNS (53) & DHCP (67/68) use
tcpdump handshake (Lab 3)Chapter 9 — how these segments get routed hop-by-hop
seq / window / MSS (Lab 4)Chapter 4 & 10 — the IP/IPv6 headers MSS is derived from
iperf3 TCP vs UDP (Lab 6)Chapter 1 — bandwidth, throughput & goodput revisited
Nice work  ·  You’ve now seen every part of Chapter 8 at the terminal — sockets, ports, the TCP handshake, sequence & window fields, and connectionless UDP.
Chapter 8 — Transport Layer · Slides + Hands-On Kali Labs