CS 168 · DISCUSSION 09 · GUIDED REASONING WORKBOOK
统一 scenario:一台刚连 Wi-Fi 的 laptop 第一次访问公网 server。每一跳同时写 L2、L3、L4 字段,避免把 next hop 与 end-to-end destination 混掉。
无需离开 CourseStack:先预测,再在表格、时间线或状态空间里完成推导;卡住时逐层打开提示,最后才展开解释与变式。
已阅读 Spring 2026 worksheet 与 official solution;以下是原创等价练习。官方 IDs 用于 coverage,对精确原题请回到页末 PDF。
对应官方 1.1、1.2、1.3、1.4、1.5、1.6、1.7、1.8
Why the official problem exists:用“我缺什么 state”选择 DHCP、ARP、NAT,而不是背层次。
Laptop 只知道自己的 NIC MAC;尚无 IP、mask、gateway、DNS。目标稍后是 8.8.8.8:443。
先预测:谁告诉 laptop 自己的 IP 与 default gateway?
为 own IP、own MAC、gateway MAC、public source tuple 四个未知量填 producer、scope、lifetime。
own MAC 已由 NIC 配置。
ARP 的问题形式是“本地这个 IP 的 MAC?”
NAT mapping 在第一枚 outbound flow packet 时创建。
DHCP 给 IP/mask/gateway/DNS 与 lease;NIC 已知自身 MAC;ARP 得 gateway MAC;NAT 用 private tuple 建 public tuple。port 可复用区分共享 public IP 后的 flows,但这削弱纯端到端透明性。
协议是 state discovery/translation 的责任分工。
gateway ARP entry 已缓存但 DHCP lease 过期,哪些步骤能跳过,哪些必须重做?
对应官方 2.1、2.2、2.3、2.4、2.5、2.6、2.7、2.8
Why the official problem exists:检查端到端 IP 不变、逐跳 MAC 改变和 next-hop decision。
Laptop A=10.0.0.10/24, MAC AA;gateway R=10.0.0.1, MAC RR;server C=203.0.113.8。A 尚无 ARP entry。
先预测:A 发往 C 的第一帧 dst MAC 是?
| 阶段 | src MAC | dst MAC | src IP | dst IP |
|---|---|---|---|---|
| ARP request | AA | ff:ff:ff:ff:ff:ff | 10.0.0.10 | 询问10.0.0.1 |
| A→R data | AA | ____ | ____ | ____ |
| R 下一链路 | R-next | next-hop | ____ | ____ |
先用 mask 判断同 subnet。
ARP request broadcast,reply unicast。
router 去掉旧 L2 frame,再为新 link 封装;IP endpoints 保持。
A 发现 C 非本地,ARP 广播询问 gateway;R 单播回复。data frame 是 AA→RR,IP 仍 10.0.0.10→203.0.113.8。R 查 FIB,每跳重建 MAC header;除 NAT 边界外 IP endpoints 不变。
routing 选择 next-hop IP/interface,ARP 把该本地 next hop 解析成 frame destination。
C 改为 10.0.0.88,同一表格哪些字段和 packets 消失?
对应官方 3.1、3.2
Why the official problem exists:追 outbound 与 reply 的 5-tuple 改写并说明为什么 port 不只是 host multiplexing。
A=10.0.0.10:50000,NAT public=198.51.100.7,分配 port=60000,server=8.8.8.8:443。
先预测:outbound 经过 NAT 后 destination tuple?
| 方向/位置 | src IP:port | dst IP:port | NAT lookup |
|---|---|---|---|
| outbound before | 10.0.0.10:50000 | 8.8.8.8:443 | create |
| outbound after | ____ | ____ | private→public |
| reply before | ____ | ____ | public port |
| reply after | ____ | ____ | public→private |
outbound 改 source tuple。
reply 的 destination 是 NAT public tuple。
mapping 允许回复恢复 private destination。
outbound source→198.51.100.7:60000,destination不变。reply 是 8.8.8.8:443→198.51.100.7:60000;NAT 查表改 destination 为 10.0.0.10:50000。
共享 address 依靠 port-indexed state 把 reply demultiplex 回内部 flow。
两台内网 host 都用 source port 50000 访问同一 server,NAT 必须如何分配 public ports?
新 laptop 从无配置到 HTTPS reply,画 DHCP、ARP、outbound frame、NAT mapping、reply reverse mapping;每条消息填 MAC/IP/port。