Link layer and IP
مُقدَّمفي هذا الدرس
| English | المعنى |
|---|---|
| frame/freɪm/ | A discrete unit in a sequence or transmission; in video, one complete image, and in networking, a link-layer data unit. |
| MAC address/mæk əˈdres/ | A link-layer identifier used to address a network interface within a local network. |
| CRC/ˌsiː ɑː ˈsiː/ | فحص التكرار الزائد للدورة |
| IP address/ˌaɪ ˈpiː əˈdres/ | A numerical address used to identify and route traffic to an interface on an Internet Protocol network. |
| subnet/ˈsʌbnet/ | Subdivisions of an IP network defined by their address prefixes. |
| ARP/ɑːp/ | the protocol that finds the MAC address for an IP address on the local network |
| default gateway/dɪˈfɒlt ˈɡeɪtweɪ/ | the router a host sends packets to when the destination is outside its own network |
| NAT/næt/ | network address translation: a router rewrites private source addresses and ports to one public address and remembers each mapping |
Two addresses, two scopes
- An Ethernet frame 帧: a 6-byte destination MAC address MAC地址, a 6-byte source, a 2-byte type, the payload and a 4-byte CRC 循环冗余校验. The MAC names the next neighbour and changes at every hop.
- An IPv4 header: version and IHL, total length, TTL (time to live), protocol, checksum, and the 4-byte source and destination IP address IP地址. The IP address names the far-away destination and does not change on the way (unless NAT rewrites it, below).

Crossing 3 routers, the destination IP —
الصعوبة 1/5 · 100 عملة + مكافأة صغيرة عند الإنجاز الأول اليوم
MAC names the neighbour and changes; IP names the stranger and never does.
Decode the course header
- The header starts
45 00 00 3C … 40 06 …. Read it field by field:
| Bytes | Field | Meaning |
|---|---|---|
45 |
version 4, IHL 5 | IPv4; header $5 \times 4 = 20$ bytes |
00 |
service type | nothing special |
00 3C |
total length | 60 bytes: 20 header + 40 payload |
40 |
TTL | 64 more hops allowed |
06 |
protocol | 6 = TCP |
- Three checks, three scopes. The Ethernet CRC protects the whole frame on one link. The IP checksum covers only the header; every router lowers the TTL by 1, so it must recompute that checksum at every hop.
- The data is protected end to end by the TCP or UDP checksum, which no router touches.
IHL = 5 means the header is —
الصعوبة 1/5 · 100 عملة + مكافأة صغيرة عند الإنجاز الأول اليوم
IHL counts 32-bit words: 5 x 4 = 20 bytes.
Three routers, four frames
- Crossing 3 routers, a packet travels in 4 frames with 4 different destination MACs, one per hop, chosen using the IP address. Its destination IP stays the same the whole way.
- IHL counts 32-bit words, but total length counts bytes. Mixing up the two units is the classic header bug.
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 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 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.
ما المشكلة؟ لا يرى ذلك سوى فريق الموقع.