Link layer and IP
引入
7:25
计算机网络
网络将你的字节传送到遍布全球、彼此互不隶属的机器上。前三个单元介绍帧的传输:分层、链路层与 IP,以及路由。接下来的两个单元介绍如何通过传输层和应用层协议,使交付可靠且有用。最后两个单元介绍如何保障网络安全并扩展网络规模。本课程中的每个首部都会逐字节解码,方便你核对。
英文讲解 · 可切换中英文字幕
本课内容
| English | 释义 | 拼音 |
|---|---|---|
| frame/freɪm/ | 帧 | zhēn |
| MAC address/mæk əˈdres/ | MAC地址 | MAC dì zhǐ |
| CRC/ˌsiː ɑː ˈsiː/ | 循环冗余校验 | xún huán rǒng yú jiào yàn |
| IP address/ˌaɪ ˈpiː əˈdres/ | IP地址 | IP dì zhǐ |
| NAT/næt/ | 网络地址转换 | wǎng luò dì zhǐ zhuǎn huàn |
| subnet/ˈsʌbnet/ | 子网 | zi wǎng |
| ARP/ɑːp/ | 地址解析协议 | dì zhǐ jiě xī xié yì |
| hosts | 主机 | zhǔ jī |
| default gateway/dɪˈfɒlt ˈɡeɪtweɪ/ | 默认网关 | mò rèn wǎng guān |
两种地址,两种作用域
- 以太网帧:6字节目的MAC地址,6字节源地址,2字节类型,有效载荷,4字节CRC。MAC标识邻居且每次跳转都会改变。
- IPv4头部:版本/IHL、总长度、TTL、协议、校验和、4字节源和目的IP地址。IP标识陌生人且永不改变。


Crossing 3 routers, the destination IP —
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
MAC names the neighbour and changes; IP names the stranger and never does.
解析课程页眉
45 00 00 3C … 40 06 …:版本 4,IHL 5 — 头部长 $5 \times 4 = 20$ 字节;总长度 $0x003C = 60$(20 头部 + 40 载荷);TTL $0x40 = 64$;协议 6 = TCP。- CRC 逐跳保护整个帧;IP 校验和仅端到端保护页眉 — 路由器会重写页眉(TTL 递减),但不会修改数据,因此完整性范围仅限于其重写的部分。
IHL = 5 means the header is —
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
IHL counts 32-bit words: 5 x 4 = 20 bytes.
三个路由器,四个帧
- 跨越 3 个路由器时,数据包承载 4 个帧并携带 4 个不同的目标 MAC 地址 — 每跳一个,由 IP 选定 — 而其目标 IP 在整个过程中保持不变。
- IHL 统计 32-位字,总长度统计字节:混淆这两种单位是经典的页眉错误。
Total length 0x003C with IHL 5 leaves — payload bytes
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
60 total - 20 header = 40 payload bytes.
As a packet crosses three routers, its destination MAC address stays the same all the way.
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
A MAC address names only the next neighbour, so each of the $4$ frames carries a new destination MAC. The destination IP address is what stays the same end to end.
这是一张新卡片,翻译完成前会显示英文。
Subnets and ARP
- The prefix length fixes the size of a subnet 子网. A /24 has $256$ addresses and $254$ usable hosts (the network and broadcast addresses are reserved); a /26 has $64$, so $62$ hosts. Host $192.168.1.130/26$ is in the block $192.168.1.128$ to $.191$.
- To send inside its own subnet, a host needs the neighbour's MAC, so ARP 地址解析协议 broadcasts "who has this IP?" and caches the reply. For any address outside the subnet, the host sends the frame to the MAC of the default gateway 默认网关 instead.
How many usable host addresses does a /27 subnet have?
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
2^(32-27) = 32 addresses, minus network and broadcast = 30.
What is the network address of 10.0.5.77/28?
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
A /28 block holds 16 addresses; 77 falls in 64 to 79, so the network address is 10.0.5.64.
这是一张新卡片,翻译完成前会显示英文。
Many hosts behind one address
- A home router with NAT 网络地址转换 gives the laptops private addresses such as 192.168.1.20. On the way out, it rewrites the source to its one public address and a new port, and remembers the pair.
- Replies come back to that port and are rewritten again. An outside host cannot open a connection inwards, because no entry exists until an inside host sends first.
Behind NAT, an outside host can open a connection to an inside laptop with no setup.
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
The router has no mapping until the inside host sends first.
这是一张新卡片,翻译完成前会显示英文。
Worked example: split a /24 into four
- Four /26 blocks of 64 addresses fit in 192.168.1.0/24: .0, .64, .128 and .192, each with 62 usable hosts 主机.
- Host 192.168.1.200/26 is in the last block: network .192, broadcast .255, hosts .193 to .254. A /27 halves that again: 32 addresses, $\mathbf{30}$ hosts.
Usable hosts in a /27 subnet?
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
$2^5 = 32$ addresses minus network and broadcast.
Host 192.168.1.200/26 belongs to the block starting at:
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
The /26 blocks start at .0, .64, .128 and .192.
这是一张新卡片,翻译完成前会显示英文。
Marks that slip away
- IHL in bytes. IHL counts 32-bit words: IHL $5$ means $20$ bytes.
- The MAC as an end-to-end address. The MAC changes at every hop; the IP address IP地址 stays the same.
- Thinking the IP checksum covers the data, end to end. It covers only the header and is recomputed at every router; TCP's checksum protects the data end to end.
这是一张新卡片,翻译完成前会显示英文。
Recap
- The MAC names the next neighbour and changes every hop; the IP address IP地址 names the destination and stays fixed.
- IHL counts 32-bit words; total length counts bytes.
- CRC: one link. IP checksum: the header, hop by hop. TCP/UDP checksum: the data, end to end.
出了什么问题?只有网站团队能看到这些信息。