NAT, and the Helpers Around IP: ARP, DHCP & ICMP
GATE 2027 CS/IT core: Network Address Translation. ARP, DHCP and ICMP are enrichment (not named in the 2027 list) but standard B.Tech material.
“How a whole hostel Wi-Fi shares one public IP, and the small protocols that make IP usable at all.”
1.Why NAT exists
§ 5.1.Prerequisites: IPv4 addressing and CIDR from [IPv4 fragmentation and CIDR subnetting](/notes/computer-networks/ipv4-fragmentation-and-cidr-subnetting), and the idea of TCP/UDP ports.
IPv4 has a 32-bit address space, which is not enough for every phone and laptop to get its own globally unique address. RFC 1918 reserves three blocks for private use inside organisations: 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. Routers on the public internet do not forward packets addressed to these ranges, so many networks can reuse the same private addresses.
A NAT router sits at the border between the private network and the internet. It owns at least one public address. When an inside host talks to the outside, the router rewrites the packet so it appears to come from the public address, and it keeps enough state to send the reply back to the right inside host.
Everyone in the hostel posts letters with the hostel's single street address. Reception notes which room sent which letter, so when a reply arrives addressed to the hostel, it knows which room to hand it to.
2.How port translation (NAPT) works
§ 5.2.Most home and campus routers do Network Address and Port Translation (NAPT), so many inside hosts share one public IP. The router tells conversations apart using transport ports.
Outbound: a packet leaves host 192.168.1.10 from port 5000. The router picks an unused public port, say 40001, rewrites the packet's source to its public address and port 40001, and records the mapping (192.168.1.10:5000 ↔ public:40001) in its translation table.
Inbound: the server replies to public:40001. The router looks up port 40001, rewrites the destination back to 192.168.1.10:5000, and forwards it inside.
Because the IP addresses and ports changed, the router must recompute the IP header checksum and the TCP/UDP checksum. The transport checksum covers a pseudo-header that includes the source and destination IP addresses, so it changes too.
3. Worked trace: one request through NAT
| Inside host192.168.1.10:5000 | Server198.51.100.20:80 | Router public IP203.0.113.5 | Assigned public port40001 |
The laptop sends the packet unchanged.
↳ Result: src 192.168.1.10:5000 → dst 198.51.100.20:80The router rewrites only the source and stores the mapping 192.168.1.10:5000 ↔ 203.0.113.5:40001.
↳ Result: src 203.0.113.5:40001 → dst 198.51.100.20:80The server answers whoever appeared to send the request.
↳ Result: src 198.51.100.20:80 → dst 203.0.113.5:40001The router finds port 40001 in its table and rewrites only the destination.
↳ Result: src 198.51.100.20:80 → dst 192.168.1.10:50004. What NAT costs you
| Feature / Aspect | Benefit | Cost |
|---|---|---|
| Address space | Many hosts share one public IPv4 address | The 16-bit port space limits simultaneous mappings per public IP and protocol |
| Reachability | Inside hosts are not directly addressable from outside | Outside hosts cannot start connections inward without a static mapping (port forwarding) |
| Layering | Transparent to most client-server apps | Breaks the end-to-end principle: a network-layer device edits transport-layer ports |
| Protocols | Works for ordinary TCP/UDP flows | Protocols that carry IP addresses inside their payload need special helpers |
✎ Takeaway: NAT is a workaround for IPv4 address shortage, not a security feature by design, even though it hides inside addresses.
5.ARP: from IP address to MAC address (enrichment)
§ 5.5.IP gets a packet to the right network, but on the final link the frame needs a MAC address. The Address Resolution Protocol (ARP) finds the MAC address that belongs to an IPv4 address on the same link.
The sender broadcasts an ARP request (destination MAC FF:FF:FF:FF:FF:FF) asking who has a given IP. The owner answers with a unicast ARP reply containing its MAC. Both sides cache the result in an ARP table for a while, so most packets need no ARP traffic.
If the destination is on another network, the host does not ARP for the remote host. It ARPs for its default gateway's MAC and sends the frame there, with the IP destination still set to the remote host.
6.DHCP and ICMP (enrichment)
§ 5.6.DHCP gives a joining host its IP address, subnet mask, default gateway and DNS server, leased for a limited time. The exchange is Discover → Offer → Request → Acknowledge (DORA). The client has no address yet, so its Discover goes out from 0.0.0.0 to the broadcast address 255.255.255.255, over UDP from client port 68 to server port 67.
ICMP carries error reports and diagnostics for IP. It travels inside IP packets (protocol number 1). Common types: echo request (8) and echo reply (0), used by ping; destination unreachable (3); and time exceeded (11), sent when a router decrements TTL to zero.
Traceroute uses time exceeded: it sends probes with TTL = 1, 2, 3, … and each router that drops a probe reveals itself with an ICMP time-exceeded message. Path MTU discovery uses the destination-unreachable 'fragmentation needed' code, sent when a packet with the Don't Fragment bit is too large for the next link.
7.Common mix-ups
§ 5.7.The server's address is never touched. Only the inside host's address and port are hidden behind the router's.
ARP requests are broadcasts, and broadcasts do not cross routers.
ICMP messages use IP protocol number 1. They have no TCP or UDP header.
Practice
A NAT router with public address P receives an outgoing TCP segment from 10.0.0.7:3000 to S:443. Which fields does it rewrite?
Host H (192.168.1.5) sends an IP packet to a server on another network through its gateway R. Which destination MAC address is in the frame H transmits?
Why must a NAT router recompute the TCP checksum after rewriting only IP addresses and ports?
Which ICMP message type does traceroute rely on to discover each router on the path?
One-minute revision
“NAT: outbound rewrites source IP:port, inbound rewrites destination IP:port, using a translation table.”
- •Private: 10/8, 172.16/12, 192.168/16
- •NAPT entry: (private IP, port) ↔ (public IP, port)
- •DHCP: DORA over UDP 68 → 67
- •ICMP types: 8/0 echo, 3 unreachable, 11 time exceeded
- •ARP for the gateway when the destination is remote
- •MACs change every hop; IPs don't (unless NAT)
- •NAT breaks inbound connections without port forwarding
- •Recompute IP and TCP/UDP checksums after rewriting
Primary Academic References & Exam Sources
Every concept in Notes From a B.Tech Brain is synthesized from authoritative academic texts, seminal peer-reviewed research, verified exam archives, and renowned university lectures.
Curated for clarity, rigorous numerical solving, and semester excellence:
GATE-level numerical drilling and PYQ analysis.
Step-by-step conceptual walkthroughs with worked GATE numericals.
Clear whiteboard lectures for foundational and semester exam coverage.