How Does Your Computer Reach Baidu? A Deep Dive into LAN, ARP, Routing, and NAT
This article explains step‑by‑step how a request to www.baidu.com travels from a local PC through the LAN, across subnets, and through NAT, detailing IPv4 addressing, MAC resolution via ARP, routing table lookups, and the OSI‑model layers involved.
Introduction
The article walks through what happens when you request www.baidu.com, covering IPv4, MAC, DNS, switches, ARP, routers, routing tables, NAT, and the OSI‑7‑layer model.
1. Communication Within the Same LAN
Two hosts (A and B) share the subnet 192.168.1.0. Host A sends data to B; the packet descends from the application layer (e.g., HTTP over TCP) to lower layers, adding protocol headers at each step.
Host B determines whether a received packet is addressed to it by comparing the destination MAC address. The logic can be expressed as:
if received_packet.MAC == own_MAC {
// process packet
} else {
// discard
}To send a packet, Host A must include the following fields:
src ip = 192.168.1.2 // source IP
src mac = Host A MAC
dst ip = 192.168.1.3 // destination IP
dst mac = Host B MAC // destination MAC (obtained via ARP)The destination MAC address is resolved using the ARP protocol. The ARP resolution steps are:
Check the local ARP cache for a mapping of dst ip to dst mac. If present, use it.
If not present, broadcast an ARP request on the subnet.
Machines that receive the request compare the src ip in the request with their own IP. The owner replies with its MAC address and stores the mapping locally.
Switches also learn MAC‑to‑port mappings and forward frames accordingly.
2. Cross‑Subnet Request to Baidu
When the host (IP 192.168.0.64) pings baidu.com, the resolved public IP is 220.181.38.148:
~ % ping baidu.com
PING baidu.com (220.181.38.148): 56 data bytes
...The host also has a public IP assigned by the ISP: 121.36.30.75. To reach the remote subnet, the host consults its routing table ( route -n) and finds the default gateway (e.g., 192.168.0.1 on interface eth0).
The packet is first encapsulated with the gateway’s MAC address:
src ip = 192.168.0.64
src mac = fa:16:3e:6b:ab:64 // host MAC
dst ip = 220.181.38.251 // Baidu IP (resolved via DNS)
dst mac = MAC of eth0’s gatewayThe router receives the frame, checks the MAC, then examines the IP. Because the destination IP is not on the router’s LAN, it forwards the packet to its WAN interface after performing Source NAT (SNAT), replacing the source IP with its public IP ( 121.36.30.75).
src ip = 192.168.0.64 → src ip = 121.36.30.75 (SNAT)The router records this translation in its NAT table (NAPT), e.g.: 192.168.0.64:1234 → 121.36.30.75:1234 When Baidu replies, the packet arrives at the router with:
src ip = 220.181.38.251
src mac = Baidu gateway MAC
dst ip = 121.36.30.75:1234
dst mac = router’s WAN MACThe router looks up the NAT table, rewrites the destination back to the original private address, and forwards the frame to the host:
dst ip = 192.168.0.64:1234
dst mac = Host A MACThe host then processes the packet up the OSI layers until the application layer, where the HTTP response is rendered by the browser.
Conclusion
The request traverses the local LAN, is routed through the default gateway with ARP‑resolved MAC addresses, undergoes NAT translation, and finally reaches Baidu’s IDC network, where Baidu’s own load‑balancing decides the exact server. The response follows the reverse path, with NAT reversing the address translation so the original host receives the data.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
JavaEdge
First‑line development experience at multiple leading tech firms; now a software architect at a Shanghai state‑owned enterprise and founder of Programming Yanxuan. Nearly 300k followers online; expertise in distributed system design, AIGC application development, and quantitative finance investing.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
