COMPUTER NETWORKS/Student Engineering Notebook
Page 08·notes
NETWORK LAYER, IPV4 ADDRESSING & CIDR SUBNETTING—~28 MIN READ

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

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.

mental model— Think of a hostel reception desk

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

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.

WORKED NUMERICAL · STUDENT DERIVATION✎ Key Takeaway: Outbound changes the source; inbound changes the destination. The server side of the conversation is never rewritten.

3. Worked trace: one request through NAT

Problem Statement:
A laptop at 192.168.1.10 opens a TCP connection from port 5000 to a web server at 198.51.100.20, port 80. The NAT router's public address is 203.0.113.5, and it assigns public port 40001. Write the source and destination IP:port of the packet on each side of the router, in both directions.
Inside host192.168.1.10:5000Server198.51.100.20:80Router public IP203.0.113.5Assigned public port40001
Step 1: Request, inside the LAN

The laptop sends the packet unchanged.

↳ Result: src 192.168.1.10:5000 → dst 198.51.100.20:80
Step 2: Request, after NAT

The 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:80
Step 3: Reply, on the internet

The server answers whoever appeared to send the request.

↳ Result: src 198.51.100.20:80 → dst 203.0.113.5:40001
Step 4: Reply, after NAT

The router finds port 40001 in its table and rewrites only the destination.

↳ Result: src 198.51.100.20:80 → dst 192.168.1.10:5000
Final Answer:Outbound, NAT rewrites the source (192.168.1.10:5000 becomes 203.0.113.5:40001). Inbound, it rewrites the destination back. The server never sees the private address.

4. What NAT costs you

Feature / AspectBenefitCost
Address spaceMany hosts share one public IPv4 addressThe 16-bit port space limits simultaneous mappings per public IP and protocol
ReachabilityInside hosts are not directly addressable from outsideOutside hosts cannot start connections inward without a static mapping (port forwarding)
LayeringTransparent to most client-server appsBreaks the end-to-end principle: a network-layer device edits transport-layer ports
ProtocolsWorks for ordinary TCP/UDP flowsProtocols 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)

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)

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

MythNAT changes the destination address of outgoing packets.
RealityOutgoing packets get a new source; replies get a new destination.

The server's address is never touched. Only the inside host's address and port are hidden behind the router's.

MythTo reach a host on another network, ARP for that host's MAC.
RealityARP only works on the local link; you ARP for the gateway.

ARP requests are broadcasts, and broadcasts do not cross routers.

MythICMP runs over TCP or UDP.
RealityICMP sits directly inside IP.

ICMP messages use IP protocol number 1. They have no TCP or UDP header.

STUDENT PRACTICE · CONCEPT DRILL

Practice

Problem 1 · FOUNDATION

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?

Problem 2 · GATE-LEVEL

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?

Problem 3 · TRICKY

Why must a NAT router recompute the TCP checksum after rewriting only IP addresses and ports?

Problem 4 · FOUNDATION

Which ICMP message type does traceroute rely on to discover each router on the path?

RAPID REVIEW · NOTEBOOK SUMMARY

One-minute revision

core principle:

“NAT: outbound rewrites source IP:port, inbound rewrites destination IP:port, using a translation table.”

must-remember principles:
  • •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
critical exam pitfalls:
  • •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
SOURCE TRANSPARENCY & CITATIONS

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.

Primary Academic Texts
RFC 3022: Traditional IP Network Address Translator (Traditional NAT)↗by · Basic NAT and NAPT, translation tables, checksum adjustment.
ACADEMIC STANDARD
RFC 1918: Address Allocation for Private Internets↗by · The three private IPv4 address blocks.
ACADEMIC STANDARD
ACADEMIC STANDARD
RFC 2131: Dynamic Host Configuration Protocol↗by · DHCP message exchange and leases.
ACADEMIC STANDARD
ACADEMIC STANDARD
Computer Networking: A Top-Down Approachby · Network layer chapters: NAT, DHCP, ICMP; link layer chapter: ARP.
ACADEMIC STANDARD
Official Examination Archives
GATE 2027 CS/IT syllabus↗IIT Madras · Computer Networks: IPv4 fragmentation, CIDR notation, Network Address Translation.
GATE CS OFFICIAL
RECOMMENDED YOUTUBE EDUCATORS & FULL-COURSE PLAYLISTS

Curated for clarity, rigorous numerical solving, and semester excellence:

Knowledge Gate · Computer Networks for GATE↗Instructor: Sanchit Jain · Covers: OSI/TCP-IP layers, sliding window, CRC, subnetting, TCP congestion control

GATE-level numerical drilling and PYQ analysis.

Open YouTube↗
Gate Smashers · Computer Networks Full Course↗Instructor: Varun Singla · Covers: Ethernet, IP addressing, routing algorithms, TCP/UDP, DNS & HTTP

Step-by-step conceptual walkthroughs with worked GATE numericals.

Open YouTube↗
Neso Academy · Computer Networks Series↗Instructor: Neso Academy · Covers: Data link layer, framing, error detection, medium access, TCP/IP

Clear whiteboard lectures for foundational and semester exam coverage.

Open YouTube↗