Skip to content
BoKSA

11 – IPv4, IPv6, ICMP, DHCP and NAT

11 – IPv4, IPv6, ICMP, DHCP and NAT

Course: ICT Basic course · Level: introductory Book: Kurose & Ross, 9th ed., chapter 4.3 (the Internet Protocol: IPv4, addressing, DHCP, NAT, IPv6) and chapter 5 (ICMP)

Learning goals

After this article you can:

  • describe the fields of the IPv4 datagram and explain TTL and fragmentation;
  • explain how a host gets an IP address with DHCP (DORA);
  • explain why NAT exists, how it works with port numbers, and what its drawbacks are;
  • describe IPv6: address notation, header, address types, how hosts get an address (SLAAC/DHCPv6), and the transition from IPv4;
  • explain ICMP and how ping and traceroute use it.

1. IPv4

1.1 The IPv4 datagram

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
 0        4        8                16                               31
 ┌────────┬────────┬────────────────┬────────────────────────────────┐
 │version │ header │  type of       │        total length            │
 │  (4)   │ length │  service (DSCP/ECN)                             │
 ├────────┴────────┴────────────────┼──────┬─────────────────────────┤
 │      identification              │flags │   fragment offset       │
 ├─────────────────┬────────────────┼──────┴─────────────────────────┤
 │   TTL           │  protocol      │     header checksum            │
 ├─────────────────┴────────────────┴────────────────────────────────┤
 │                    source IP address (32 bits)                    │
 ├───────────────────────────────────────────────────────────────────┤
 │                  destination IP address (32 bits)                 │
 ├───────────────────────────────────────────────────────────────────┤
 │                       options (rare)                              │
 ├───────────────────────────────────────────────────────────────────┤
 │                 data (TCP segment, UDP datagram, ICMP …)          │
 └───────────────────────────────────────────────────────────────────┘

Important fields:

Field Meaning
TTL (Time To Live) decreased by 1 by every router; at 0 the datagram is dropped and an ICMP "time exceeded" is sent back. Prevents packets from circling forever
Protocol which upper-layer protocol is in the data: 6 = TCP, 17 = UDP, 1 = ICMP
Header checksum protects only the header; recomputed by every router (because TTL changes)
DSCP / ECN priority (QoS) and congestion signalling
Identification, flags, fragment offset used for fragmentation

Header size without options: 20 bytes. So a TCP/IPv4 packet has at least 40 bytes of headers.

1.2 Fragmentation and MTU

Every link has a Maximum Transmission Unit (MTU), e.g. 1500 bytes for Ethernet. In IPv4, a router may split (fragment) a datagram that is too large; the destination reassembles it. In practice fragmentation is avoided: hosts use Path MTU Discovery (the "Don't Fragment" bit + ICMP "fragmentation needed" messages). IPv6 routers never fragment.

1.3 IP addresses and interfaces

An IP address belongs to an interface, not to a device. A router with 8 interfaces has 8 IP addresses. A laptop with Wi-Fi and Ethernet has at least 2.

Addressing and subnetting are covered in article 12.


2. DHCP – Dynamic Host Configuration Protocol

How does a laptop get an IP address when it connects to a network? Manually (static) or automatically with DHCP (RFC 2131).

DHCP is an application-layer protocol over UDP (server port 67, client port 68). It works with broadcasts, because the new client doesn't have an address yet and doesn't know the server.

DORA

1
2
3
4
5
 client (0.0.0.0)                                DHCP server (192.168.1.1)
   │── DHCP DISCOVER  src 0.0.0.0:68 → 255.255.255.255:67 ──►│  "is there a DHCP server?"
   │◄─ DHCP OFFER     yiaddr = 192.168.1.23, lease 24 h ─────│  "you can have .23"
   │── DHCP REQUEST   "I'd like 192.168.1.23" (broadcast) ──►│  (other servers learn their offer wasn't chosen)
   │◄─ DHCP ACK       "OK, it's yours for 24 h" ─────────────│

Besides the IP address, DHCP gives the client: - the subnet mask (or prefix length); - the default gateway (first-hop router); - the DNS server(s); - the lease time: after about half of it, the client tries to renew.

In larger networks, a DHCP relay (on the router) forwards broadcasts to a central DHCP server in another subnet.


3. NAT – Network Address Translation

3.1 Why?

IPv4 has only 2³² ≈ 4.3 billion addresses. The last free blocks were handed out by IANA in 2011 and by RIPE NCC in 2019. To save addresses, home and company networks use private addresses (RFC 1918) internally:

Private range Prefix
10.0.0.0 – 10.255.255.255 10.0.0.0/8
172.16.0.0 – 172.31.255.255 172.16.0.0/12
192.168.0.0 – 192.168.255.255 192.168.0.0/16

These addresses are not routed on the Internet. A NAT router translates them to one (or a few) public address(es).

3.2 How it works (NAPT / PAT)

1
2
3
4
5
6
7
8
9
   LAN (private)                       NAT router                     Internet
 10.0.0.2:3345 ──► src 10.0.0.2:3345  →  src 145.92.10.7:5001  ──► 93.184.215.14:443
                                       NAT translation table
                                  ┌───────────────────┬───────────────────┐
                                  │ WAN side          │ LAN side          │
                                  │ 145.92.10.7:5001  │ 10.0.0.2:3345     │
                                  │ 145.92.10.7:5002  │ 10.0.0.5:51010    │
                                  └───────────────────┴───────────────────┘
 10.0.0.2:3345 ◄── dst 10.0.0.2:3345  ←  dst 145.92.10.7:5001  ◄── reply

The router changes the source IP and source port of outgoing packets and remembers the mapping. Replies are translated back. With 16-bit port numbers, one public IP can serve tens of thousands of connections.

3.3 Drawbacks

  • Breaks the end-to-end principle: devices behind NAT can't easily be reached from outside. Servers need port forwarding; P2P apps and games need tricks (STUN, TURN, ICE, UPnP).
  • Routers have to look at the transport layer (port numbers), which violates layering.
  • Logging/troubleshooting becomes harder: many users share one IP.

3.4 CGNAT (updated)

Many ISPs (especially mobile networks, and some new fibre/cable providers) now use Carrier-Grade NAT (CGNAT): your home router gets an address from 100.64.0.0/10 (RFC 6598), and the ISP translates again. You're then behind two NATs, and port forwarding from the Internet doesn't work. This is one more reason to move to IPv6.

NAT is not a security feature in itself, even though it blocks unsolicited inbound connections as a side effect. Use a real firewall.


4. IPv6

4.1 Why IPv6?

  • 128-bit addresses: 2¹²⁸ ≈ 3.4 × 10³⁸ addresses. Enough for every device, without NAT.
  • Simpler, fixed 40-byte header: faster processing.
  • No fragmentation by routers, no header checksum (link and transport layers already check).
  • Built-in auto-configuration (SLAAC).

4.2 Notation

8 groups of 4 hexadecimal digits, separated by colons:

1
2
3
2001:0db8:0000:0000:0000:ff00:0042:8329
→ leading zeros may be left out:        2001:db8:0:0:0:ff00:42:8329
→ one series of zero groups may be "::": 2001:db8::ff00:42:8329

Prefixes work like CIDR: 2001:db8:abcd::/48 for a site, /64 for every LAN.

4.3 The IPv6 header (40 bytes)

Field Corresponds to (IPv4)
Version (6) version
Traffic class DSCP/ECN
Flow label new: identifies a flow of packets
Payload length total length
Next header protocol (also used to chain extension headers)
Hop limit TTL
Source / destination address (128 bits each)

Gone: header checksum, fragmentation fields (moved to an optional extension header used only by the sender), options.

4.4 Address types

Type Prefix Use
Global unicast 2000::/3 public, routable addresses
Link-local fe80::/10 only on the local link; every interface always has one
Unique local fc00::/7 (fd00::/8 in practice) private addresses (comparable to RFC 1918)
Multicast ff00::/8 one-to-many (IPv6 has no broadcast)
Loopback ::1 the host itself (like 127.0.0.1)

4.5 How does an IPv6 host get an address?

  • SLAAC (Stateless Address Autoconfiguration): the router sends Router Advertisements with the /64 prefix; the host creates its own interface ID (usually random, for privacy, RFC 8981).
  • DHCPv6: like DHCP for IPv4 (often used in companies; Android doesn't support stateful DHCPv6).
  • NDP (Neighbor Discovery Protocol, part of ICMPv6) replaces ARP (article 14).

4.6 The transition from IPv4 to IPv6

There is no "flag day", so both protocols exist side by side:

  • Dual stack: devices and networks run IPv4 and IPv6 at the same time. This is the most common approach. Browsers try both and use the fastest ("Happy Eyeballs").
  • Tunnelling: IPv6 packets carried inside IPv4 packets (6in4) over IPv4-only parts of the network. Mostly historical now.
  • Translation: NAT64/DNS64 lets IPv6-only clients reach IPv4-only servers. 464XLAT is used by many mobile networks, which run IPv6-only internally.

Adoption (2026): about half of Google's users reach it over IPv6 (Google measured just over 50% for the first time in March 2026). Countries differ a lot: France and India over 70%, while the Netherlands is in between. Several big Dutch providers support IPv6 fully, but not all.


5. ICMP – Internet Control Message Protocol

ICMP (RFC 792; ICMPv6 RFC 4443) is used by hosts and routers to report errors and exchange network information. ICMP messages are carried inside IP datagrams (protocol number 1; for ICMPv6, next header 58).

Type (IPv4) Message Used by
8 / 0 Echo request / echo reply ping
3 Destination unreachable (code 0 = network, 1 = host, 3 = port, 4 = fragmentation needed) error messages, Path MTU Discovery
11 Time exceeded (TTL = 0) traceroute
5 Redirect rarely used; often blocked

How does traceroute work? The source sends packets with TTL = 1, 2, 3, …. The router where the TTL reaches 0 drops the packet and sends back ICMP Time Exceeded, which reveals its address and the RTT. When the packet reaches the destination, the host answers with ICMP port unreachable (UDP traceroute, Linux) or echo reply (ICMP traceroute, Windows tracert).

In IPv6, ICMPv6 is essential: Neighbor Discovery, Router Advertisements and Path MTU Discovery all depend on it. Never block all ICMPv6.


6. Try it yourself

Tools: on Linux use ip a, ip r, ip -6 r and sudo dhclient -v or sudo networkctl renew <interface> / nmcli on modern Debian. On Windows: ipconfig /all, ipconfig /release and ipconfig /renew.

  1. ip a: what are your IPv4 and IPv6 addresses? Which one is link-local? Is there a global IPv6 address?
  2. DHCP in Wireshark: start a capture with filter dhcp (or bootp in old versions) and run sudo dhclient -r && sudo dhclient -v (Linux) or ipconfig /release and ipconfig /renew (Windows). Find the four DORA messages. What lease time do you get? Which DNS server and gateway?
  3. NAT: compare ip a (private address) with your public address (curl -4 https://ifconfig.co and curl -6 https://ifconfig.co). Is your address in 100.64.0.0/10 (CGNAT)?
  4. IPv6: test your connection at https://test-ipv6.com/ and https://www.internet.nl/ (connection test).
  5. ICMP: ping -c 3 www.hva.nl, ping -6 -c 3 www.google.com, and traceroute www.hva.nl. In Wireshark, filter icmp || icmpv6 and find the Time Exceeded messages. Look at the TTL values.
  6. Kurose & Ross Wireshark IP exercise: https://gaia.cs.umass.edu/kurose_ross/wireshark.php.

Check your understanding

  1. What is the purpose of the TTL field?
  2. Which four messages does DHCP use, and why are they broadcasts?
  3. What information does a client get from DHCP besides an IP address?
  4. Why was NAT introduced? Name two disadvantages.
  5. Shorten this IPv6 address: 2001:0db8:0000:0000:0001:0000:0000:0001.
  6. Name three differences between the IPv4 and IPv6 headers.
  7. How does traceroute use the TTL field and ICMP?

References

Book

  • Kurose & Ross, 9th ed., chapter 4.3 (IPv4, addressing, DHCP, NAT, IPv6), chapter 5 (ICMP)

Videos

Standards, statistics and tools


Cyber Security

Why is this important for cyber security?

Risk Explanation
IP spoofing the source address in IP isn't checked; attackers fake it for DDoS reflection attacks and to hide
Rogue DHCP server an attacker (or a misconfigured device) answers DHCP requests faster than the real server and hands out his own gateway/DNS → all traffic goes through the attacker (man-in-the-middle)
DHCP starvation an attacker requests all available addresses with fake MAC addresses; real clients get none (DoS)
Rogue Router Advertisements (IPv6) the same idea in IPv6: a fake router announces itself as gateway. Dangerous in "IPv4-only" networks where nobody watches IPv6, since IPv6 is enabled by default on every OS
NAT gives a false sense of security it blocks unsolicited inbound connections, but not malware that connects outward, not attacks on forwarded ports, and not UPnP holes opened automatically by devices
IPv6 without firewall rules IPv6 devices often have public addresses; if the firewall only has IPv4 rules, IPv6 may be wide open
ICMP abuse ping sweeps (finding live hosts), ICMP floods, ICMP tunnelling for data exfiltration

What can you do to make it safe?

  • DHCP snooping on managed switches: only designated ports may send DHCP server messages. RA Guard does the same for IPv6 Router Advertisements.
  • Dynamic ARP Inspection / IP source guard to block spoofed addresses on the LAN (article 14).
  • Anti-spoofing filters (BCP 38): ISPs and companies drop outgoing packets with source addresses that don't belong to them.
  • Treat IPv6 as a first-class citizen: create firewall rules for IPv4 and IPv6, monitor both, and if you don't use IPv6, disable it in a controlled way, don't just ignore it.
  • Use a real firewall (default deny inbound) instead of relying on NAT, and disable UPnP on routers unless you really need it.
  • Filter ICMP carefully: allow what's needed (echo for diagnostics, "fragmentation needed"/"packet too big" for PMTUD, essential ICMPv6), rate-limit it, and block the rest. Blocking all ICMP breaks networks.
  • Keep track of addresses: DHCP logs and IP address management (IPAM) help to trace which device had which address during an incident.

Extra references