9 · DHCP, NAT, IPv6 and tunnelling ★
Slides 4-43 → 4-51, 4-56 → 4-68 · HW5 P7 · Sample midterm 1.2 · Book 4.3.3 – 4.3.5
Getting an IP address: two questions (4-43)
- Host part (how does a host get its address inside the network?): either hard-coded by the sysadmin in a config file (e.g.
/etc/rc.configin UNIX), or DHCP, which gets it dynamically from a server. DHCP is "plug-and-play". - Network part (how does the network get its block?): it gets an allocated portion of its provider ISP's address space (4-51).
- Slide example (4-51): ISP holds
200.23.16.0/20and carves it into 8 blocks of /23: Org 0 =200.23.16.0/23, Org 1 =200.23.18.0/23, Org 2 =200.23.20.0/23, … Org 7 =200.23.30.0/23. Org k starts at third octet16 + 2k. - Where does the ISP get its block? From ICANN (Internet Corporation for Assigned Names and Numbers), which allocates addresses through regional registries and also manages the DNS root servers.
DHCP: Dynamic Host Configuration Protocol (4-44)
- Goal: a host dynamically gets an IP address from a network server when it "joins" the network.
- Lease: the host can renew its lease on the address it's using.
- Reuse: addresses are only held while the host is connected/on, so they can be reused.
- Mobile users who join and leave the network are supported.
- Where's the server? Typically co-located in the router, serving all subnets the router attaches to (4-45). If a subnet has no server, a relay agent (usually the router) forwards the messages.
- Transport: DHCP runs over UDP. Server port 67, client port 68.
The four messages (4-44, 4-46)
Slide scenario: server 223.1.2.5, arriving client gets 223.1.2.4.
| # | Message | Source (IP, port) | Dest (IP, port) | yiaddr | Trans. ID | Meaning |
|---|---|---|---|---|---|---|
| 1 | DISCOVER | 0.0.0.0, 68 | 255.255.255.255, 67 | 0.0.0.0 | 654 | "Is there a DHCP server out there?" |
| 2 | OFFER | 223.1.2.5, 67 | 255.255.255.255, 68 | 223.1.2.4 | 654 | "I'm a DHCP server! Here's an IP address you can use." Lifetime 3600 s |
| 3 | REQUEST | 0.0.0.0, 68 | 255.255.255.255, 67 | 223.1.2.4 | 655 | "OK. I would like to use this IP address!" Lifetime 3600 s |
| 4 | ACK | 223.1.2.5, 67 | 255.255.255.255, 68 | 223.1.2.4 | 655 | "OK. You've got that IP address!" Lifetime 3600 s |
- yiaddr = "your IP address", the address being offered/assigned.
- Transaction ID matches a reply to its request (OFFER echoes DISCOVER's 654; ACK echoes REQUEST's 655).
- Everything is broadcast to
255.255.255.255. The client has no address yet, so its source is0.0.0.0, even in the REQUEST. - DISCOVER and OFFER are optional: they can be skipped "if a client remembers and wishes to reuse a previously allocated network address" (RFC 2131).
- Why broadcast the REQUEST? Several servers may have sent offers. The broadcast tells all of them which offer was picked.
DHCP returns more than an address (4-47)
- Address of the first-hop router (default gateway) for the client.
- Name and IP address of the DNS server.
- Network mask (which part is network, which part is host).
- Wireshark ACK on a home LAN (4-50): Subnet Mask = 255.255.255.0, Router = 192.168.1.1, three DNS server addresses, domain name.
Encapsulation (4-48, 4-49)
- DHCP message in UDP, in IP, in Ethernet.
- The REQUEST goes out as an Ethernet broadcast frame (dest MAC
FF:FF:FF:FF:FF:FF). The router running the DHCP server receives it and demuxes Ethernet → IP → UDP → DHCP. - The server's ACK carries the client's IP address, the first-hop router address, and the DNS server name and address, and is demuxed back up to DHCP at the client.
NAT: network address translation (4-56 → 4-60)
- Idea: all devices in the local network share one IPv4 address as far as the outside world is concerned (4-56).
- Every datagram leaving the local network has the same source NAT address (slide:
138.76.29.7) but different source port numbers. Inside, datagrams use10.0.0/24addresses as usual. - Private address space (4-57):
10/8,172.16/12,192.168/16. Usable only inside a local network, never routed on the public Internet.
Why NAT (4-57)
- One IP address from the provider ISP is enough for all devices.
- Change internal addresses without notifying the outside world.
- Change ISP without renumbering the devices inside.
- Security side effect: inside devices are not directly addressable or visible from outside.
What the NAT router does (4-58)
- Outgoing: replace (source IP, port #) with (NAT IP address, new port #). Remote hosts reply to that pair.
- Remember: store every (source IP, port #) ↔ (NAT IP, new port #) pair in the NAT translation table.
- Incoming: replace (NAT IP, new port #) in the destination fields with the stored (source IP, port #).
Slide walk-through (4-59)
| Step | Where | Source | Destination |
|---|---|---|---|
| 1 | Host 10.0.0.1 → router (LAN) | 10.0.0.1, 3345 | 128.119.40.186, 80 |
| 2 | Router → Internet (WAN), table updated | 138.76.29.7, 5001 | 128.119.40.186, 80 |
| 3 | Reply arrives at router | 128.119.40.186, 80 | 138.76.29.7, 5001 |
| 4 | Router → host (LAN) | 128.119.40.186, 80 | 10.0.0.1, 3345 |
Table row: WAN 138.76.29.7, 5001 ↔ LAN 10.0.0.1, 3345.
- How many connections? The port field is 16 bits, so one WAN-side address supports over 60,000 simultaneous connections (216 = 65,536 ports, minus reserved ones).
Controversies (4-60)
- Routers "should" only process up to layer 3, but NAT rewrites port numbers (layer 4).
- Address "shortage" should be solved by IPv6, not patched with NAT.
- Violates the end-to-end argument: a network-layer device manipulates port numbers.
- NAT traversal: a client outside can't start a connection to a server behind NAT, since there's no table entry yet (fixes: static port forwarding, relays, UPnP).
- But NAT is here to stay: used heavily in home and institutional nets and 4G/5G cellular nets.
How to solve: build a NAT translation table
- Assign LAN addresses: give each host and the router's LAN interface a distinct address inside the private prefix. Skip the network address (
.0) and the broadcast address (.255). - The router has two addresses: the ISP-given public one on the WAN side, a private one on the LAN side.
- LAN side of each row: (host's private IP, source port the host picked). Two connections from the same host need two different source ports.
- WAN side of each row: (router's public IP, a new port the router picked). Every WAN port must be unique. The public IP is the same in every row.
- The remote server (IP, port 80) does not go in the table.
Worked example: HW5 P7
Q (HW5 P7): Consider the network setup in Figure 4.25 (3 hosts on a home LAN behind one NAT router). Suppose the ISP instead assigns the router the address 24.34.112.235 and the network address of the home network is 192.168.1/24.
- (a) Assign addresses to all interfaces in the home network.
- (b) Suppose each host has two ongoing TCP connections, all to port 80 at host
128.119.40.86. Provide the six corresponding entries in the NAT translation table.
(a) Hosts 192.168.1.1, 192.168.1.2, 192.168.1.3; router LAN interface 192.168.1.4. (Official answer. Any distinct addresses in 192.168.1.1–192.168.1.254 also work.)
(b) Official table:
| WAN side | LAN side |
|---|---|
| 24.34.112.235, 4000 | 192.168.1.1, 3345 |
| 24.34.112.235, 4001 | 192.168.1.1, 3346 |
| 24.34.112.235, 4002 | 192.168.1.2, 3445 |
| 24.34.112.235, 4003 | 192.168.1.2, 3446 |
| 24.34.112.235, 4004 | 192.168.1.3, 3545 |
| 24.34.112.235, 4005 | 192.168.1.3, 3546 |
3 hosts × 2 connections = 6 rows WAN IP : always 24.34.112.235 (the one public address) WAN port : 4000..4005, one new port per connection, all different LAN side : (host address, the source port that host chose) dest : 128.119.40.86, 80 for all six, not stored in this table
Sample midterm 1.2
Q (sample midterm 1.2): Suppose I run NAT at home and use Comcast cable service. Suppose my IP address is 10.0.0.1. What protocol did I run to get this IP address? Will this address be used to access the Internet directly? Why?
IPv6 (4-61 → 4-62)
Motivation
- Initial: the 32-bit IPv4 address space would be completely allocated.
- Faster processing/forwarding: a 40-byte fixed-length header.
- Flows: enable different network-layer treatment of "flows".
Header: 40 bytes, fixed
|<-------------------- 32 bits -------------------->| | ver(4) | pri(8) | flow label (20) | | payload len (16) | next hdr (8) | hop limit (8)| | source address (128 bits) | | destination address (128 bits) | | payload (data) |
32 + 32 + 128 + 128 = 320 bits = 40 bytes
- Version: 6.
- Priority (traffic class): priority among datagrams in a flow.
- Flow label: identifies datagrams in the same "flow" (the concept of "flow" isn't well defined).
- Payload length: bytes after the 40-byte header.
- Next header: which protocol gets the payload (TCP, UDP, …), like IPv4's protocol field.
- Hop limit: decremented at each router; at 0 the datagram is dropped (IPv4's TTL).
- 128-bit source and destination addresses.
What's missing compared with IPv4 (4-62)
- No checksum, to speed processing at routers (link and transport layers already check).
- No fragmentation/reassembly at routers. A router with a too-big datagram drops it and sends back an ICMPv6 "Packet Too Big" error. Only the source and destination fragment and reassemble.
- No options. They're available as an upper-layer, next-header protocol.
IPv4 → IPv6 transition: tunnelling (4-63 → 4-66)
- Not all routers can be upgraded at once: there are no "flag days". The network must run with mixed IPv4 and IPv6 routers.
- Tunnelling: an IPv6 datagram is carried as the payload of an IPv4 datagram among IPv4 routers ("packet within a packet").
- Generic idea: any datagram can ride as payload inside another protocol's datagram across a region that doesn't speak it. Tunnelling is used heavily elsewhere (4G/5G).
- Normal case (4-64): two IPv6 routers joined by Ethernet: IPv6 datagram is the payload of a link-layer frame.
- Tunnel case (4-65): two IPv6 routers joined through an IPv4 network: the IPv6 datagram is the payload of an IPv4 datagram.
Slide 4-66: A → F, IPv4 routers C and D in the middle
| Link | What's on the wire |
|---|---|
| A → B | Plain IPv6: Flow X, Src A, Dest F, data |
| B → C, C → D, D → E | IPv4 header src B, dest E, payload = the untouched IPv6 datagram (Flow X, Src A, Dest F, data) |
| E → F | Plain IPv6 again: Flow X, Src A, Dest F, data |
- B and E are dual-stack (IPv6/v4): B encapsulates, E decapsulates.
- Logical view: B and E look directly linked. Physical view: the path goes through IPv4-only routers C and D.
Adoption (4-67, 4-68)
About 40% of Google clients use IPv6 (2023); NIST: 1/3 of US government domains are IPv6-capable; deployment has taken 25 years and counting. Network-layer changes are hard because every router must change, while apps (WWW, social media, streaming) changed fast.
• Ports: server 67, client 68. Don't swap them.
• The REQUEST is still from 0.0.0.0 and still broadcast. The client has no address until the ACK.
• OFFER/ACK go to 255.255.255.255, not to the offered yiaddr.
• The four messages are D-O-R-A: DISCOVER, OFFER, REQUEST, ACK.
• NAT table: the WAN IP is the same in every row; the WAN ports must all differ. LAN ports may repeat across different hosts.
• Don't give a host the
.0 network address or the .255 broadcast address, and don't forget the router's own LAN interface.• The remote server's address and port 80 don't go in the NAT table.
• A private address (10/8, 172.16/12, 192.168/16) never appears on the public Internet.
• IPv6 header is 40 bytes fixed (IPv4 is 20+ bytes). Addresses are 128 bits, flow label 20 bits.
• IPv6 routers don't fragment. Fragmentation isn't gone entirely: only the endpoints do it.
• Tunnel: IPv6 sits inside IPv4. The outer IPv4 destination is the tunnel exit (E), not the final host F.
Quick check
1. A DHCP server at 192.168.10.1 offers 192.168.10.23 to a new laptop with lease 7200 s. DISCOVER uses transaction ID 88 and REQUEST uses 89. Write the four messages with src/dst IP and port, yiaddr and ID.
| Msg | Src | Dst | yiaddr | ID |
|---|---|---|---|---|
| DISCOVER | 0.0.0.0, 68 | 255.255.255.255, 67 | 0.0.0.0 | 88 |
| OFFER | 192.168.10.1, 67 | 255.255.255.255, 68 | 192.168.10.23 (lifetime 7200 s) | 88 |
| REQUEST | 0.0.0.0, 68 | 255.255.255.255, 67 | 192.168.10.23 (lifetime 7200 s) | 89 |
| ACK | 192.168.10.1, 67 | 255.255.255.255, 68 | 192.168.10.23 (lifetime 7200 s) | 89 |
2. Why is the DHCP REQUEST sent from 0.0.0.0 to 255.255.255.255?
The client doesn't own the address until the ACK, so it can't use it as a source. Broadcasting tells every server that sent an offer which offer was accepted.3. Besides the IP address, what three things does DHCP give the host?
The first-hop router address, the DNS server name and address, and the subnet mask.4. How is a DHCP REQUEST encapsulated, and what is the Ethernet destination?
DHCP in UDP (dst port 67) in IP (dst 255.255.255.255) in Ethernet with dest MAC FF:FF:FF:FF:FF:FF (link-layer broadcast).5. Name three goals of DHCP.
Plug-and-play (get an address on joining), lease renewal, reuse of addresses (held only while connected), and support for mobile users joining and leaving.6. NAT, new numbers: the ISP gives the router 71.58.9.200; the home network is 10.0.0/24. Three hosts each have two TCP connections to port 443 at 52.10.3.7. Assign addresses and build the NAT table, using WAN ports starting at 6000.
Addresses: hosts10.0.0.2, 10.0.0.3, 10.0.0.4; router LAN interface 10.0.0.1. Hosts pick source ports (here 5100/5101 on each host; reuse across hosts is fine).
| WAN side | LAN side |
|---|---|
| 71.58.9.200, 6000 | 10.0.0.2, 5100 |
| 71.58.9.200, 6001 | 10.0.0.2, 5101 |
| 71.58.9.200, 6002 | 10.0.0.3, 5100 |
| 71.58.9.200, 6003 | 10.0.0.3, 5101 |
| 71.58.9.200, 6004 | 10.0.0.4, 5100 |
| 71.58.9.200, 6005 | 10.0.0.4, 5101 |
7. NAT router 138.76.29.7. Host 10.0.0.3 sends from port 4100 to 93.184.216.34 port 80; the router picks 5007. Give source and destination for all four legs.
1 LAN out : S 10.0.0.3, 4100 D 93.184.216.34, 80 2 WAN out : S 138.76.29.7, 5007 D 93.184.216.34, 80 3 WAN in : S 93.184.216.34, 80 D 138.76.29.7, 5007 4 LAN in : S 93.184.216.34, 80 D 10.0.0.3, 4100Table row:
138.76.29.7, 5007 ↔ 10.0.0.3, 4100.8. (Sample 1.2) My home IP is 10.0.0.1 behind NAT on Comcast. Which protocol gave it to me? Is it used on the Internet directly?
DHCP. No: 10.0.0.1 is a private address (10/8), not routable on the Internet. The NAT router rewrites it to Comcast's public address plus a new port on the way out and reverses that on replies.9. Why can one NAT address support about 60,000 simultaneous connections?
Connections are told apart by WAN-side port, and the port field is 16 bits: 216 = 65,536 values, minus reserved ones, gives about 60,000.10. Give three arguments against NAT.
Routers should only process up to layer 3 (NAT touches ports); the address shortage should be fixed by IPv6; it violates the end-to-end argument. Also, an outside client can't reach a server behind NAT without NAT traversal.11. ISP holds 200.23.16.0/20 and splits it into 8 equal blocks. What is Organization 5's block and its address range?
/20 → 8 blocks: 20 + 3 = /23 (each /23 spans 2 values of the third octet) Org k third octet = 16 + 2k → Org 5 = 16 + 10 = 26 block: 200.23.26.0/23 range: 200.23.26.0 – 200.23.27.255 (2^9 = 512 addresses)
12. List the IPv6 header fields and show that the header is 40 bytes.
Version (4 bits), priority (8), flow label (20), payload length (16), next header (8), hop limit (8), source (128), destination (128).4+8+20 = 32; 16+8+8 = 32; 32+32+128+128 = 320 bits = 40 bytes
13. What three IPv4 features are gone from IPv6, and what happens when a datagram is too big for the next link?
No checksum, no fragmentation/reassembly at routers, no options. The router drops the datagram and sends an ICMPv6 "Packet Too Big" message to the source, which resends smaller datagrams.14. A (IPv6) sends to F (IPv6) via B (v6/v4), C and D (IPv4 only), E (v6/v4). What do the IPv4 and IPv6 headers say between C and D?
Outer IPv4: src B, dest E. Its payload is the unchanged IPv6 datagram: src A, dest F (flow X) plus data. E strips the IPv4 header and forwards the IPv6 datagram to F.15. A 1000-byte TCP payload (20-byte TCP header) crosses that tunnel. How many bytes is the IPv4 datagram between B and E?
TCP segment = 1000 + 20 = 1020 IPv6 datagram = 1020 + 40 = 1060 (payload length field = 1020) IPv4 datagram = 1060 + 20 = 1080 bytes
← prev · all topics · next →