Internet Protocol (IPv4): Broadcasting, Subnetting, NAT, ICMP & ARP

Broadcast Addresses

  • IPv4 supports broadcasting: a single datagram is delivered to all hosts/routers on the local subnet.
    • Achieved by putting the broadcast address in the destination IP field.
  • How to form the broadcast address of a subnet:
    • Keep the network prefix untouched.
    • Set every bit in the host portion to 11.
    • Example (Class C sized subnet): 223.1.1.0/24⇒223.1.1.255223.1.1.0/24 \Rightarrow 223.1.1.255.
  • Delivery mechanics on Ethernet:
    • IP datagram is wrapped in an Ethernet frame whose destination MAC is ff:ff:ff:ff:ff:ffff:ff:ff:ff:ff:ff (all 1 bits at Layer-2).
  • Constraint: the broadcast address may appear only as a destination, never as a source, in an IP packet.

Directed vs Limited Broadcast

  • Directed broadcast
    • Constructed exactly the same way—host bits =1=1—but the address is specific to one subnet and therefore routable across the Internet.
    • Example: for 223.1.1.0/24223.1.1.0/24 the directed broadcast is 223.1.1.255223.1.1.255.
    • Any host, anywhere, could send to that address; routers will forward until the packet reaches the target subnet, where it is broadcast locally.
  • Limited broadcast
    • Fixed, subnet-independent address 255.255.255.255255.255.255.255 (all 1s in every octet).
    • Routers never forward such packets; the scope is limited to the originating subnet.

IP Address Classes (OBSOLETE)

  • Historic, now discouraged way of carving the IPv4 space by inspecting the first few bits.
  • Encodings and implied prefix lengths:
    • Class A: leading bit 00, implied prefix /8/8.
    • Class B: leading bits 1010, implied prefix /16/16.
    • Class C: leading bits 110110, implied prefix /24/24.
    • Class D: leading bits 11101110, reserved for multicast.
    • Class E: leading bits 11111111, future use / experimental.
  • Modern practice: always state netmask or CIDR prefix explicitly; never rely on classful inference.

Subnetting Concepts

  • Subnetting = subdividing one larger IP block into several smaller, non-overlapping blocks.
  • Visualised as a binary aggregation tree; every left/right branch halves the available address space.
  • Examples:
    • Splitting a /26/26 yields two /27/27 sub-prefixes.
    • Combining two adjacent /25/25 networks recreates the parent /24/24.
  • Key rule: choose the longest prefix that still offers ≥ required host addresses (remember 2 hosts lost to network & broadcast IDs).

Worked Subnetting Example (223.1.1.0/24)

  • Goal: create three usable subnets for 100100, 5050 and 2525 hosts.
  • Steps (largest first):
    1. 100100 hosts ⇒ need ≥100+2=102\ge 100+2 = 102 addresses ⇒ /25/25 (gives 27−2=1262^{7}-2 = 126 usable).
    • Assigned range: 223.1.1.0 – 223.1.1.127223.1.1.0 \text{ – } 223.1.1.127 ⇒ 223.1.1.0/25223.1.1.0/25.
    1. 5050 hosts ⇒ need /26/26 ( 26−2=622^{6}-2 = 62 usable).
    • Assigned range: 223.1.1.128 – 223.1.1.191223.1.1.128 \text{ – } 223.1.1.191 ⇒ 223.1.1.128/26223.1.1.128/26.
    1. 2525 hosts ⇒ need /27/27 ( 25−2=302^{5}-2 = 30 usable).
    • Assigned range: 223.1.1.192 – 223.1.1.223223.1.1.192 \text{ – } 223.1.1.223 ⇒ 223.1.1.192/27223.1.1.192/27.
  • Remaining addresses: 223.1.1.224/27223.1.1.224/27 (unused / future growth).

Subnetting with Private Address Blocks

  • RFC 1918 private ranges: 10.0.0.0/810.0.0.0/8, 172.16.0.0/12172.16.0.0/12, 192.168.0.0/16192.168.0.0/16.
  • When space is plentiful (e.g. using 172.16.0.0/12172.16.0.0/12): simply dedicate one /24/24 per building/department if ≤254254 hosts each.
    • Example allocation:
    • 172.16.1.0/24172.16.1.0/24 — subnet needing 100100 hosts.
    • 172.16.2.0/24172.16.2.0/24 — subnet needing 5050 hosts.
    • 172.16.3.0/24172.16.3.0/24 — subnet needing 2525 hosts.

Subnetting Exercises (Campus Scenarios)

  • Exercise 1: public block 192.40.8.0/21192.40.8.0/21, reserve first /24/24 for core, then carve out ranges for Science (120120 hosts), Engineering (200200), Library (8080), Arts (5050), Administration (4040), Hostel (6060), Wi-Fi (350350) plus point-to-point router links.
  • Exercise 2: identical logical design but using private block 172.16.0.0/12172.16.0.0/12.
  • Both emphasise choosing prefixes based on host counts and keeping aggregation contiguous.

Private vs Public Addressing & Allocation

  • Private addresses suffice only for internal communication.
  • To reach the global Internet, hosts need public, globally routable unicast addresses.
  • Public address procurement channels:
    1. Direct assignment from Regional Internet Registries (RIRs) – usually paid, and IPv4 is exhausted.
    2. Delegation from an ISP – ISP owns a larger block delegated by an RIR and loans you a subset.
  • Because ISPs rarely provide one public address per internal host, most organisations deploy NAT.

Network Address Translation (NAT) – Principles

  • Inside network uses private addresses (10/810/8, 172.16/12172.16/12, 192.168/16192.168/16).
  • NAT router sits at the boundary and changes address fields on-the-fly:
    • Outbound: replace source private IP with a public IP (or with one of many via pooling). Store mapping in translation table.
    • Inbound: look up translation table and rewrite destination public IP back to original private IP.
  • Typical NAT table entry: outside address ↔ inside address (plus TCP/UDP port numbers when Port Address Translation (PAT) is used).

Detailed NAT Walk-through (Single Public IP)

  1. Host 10.0.0.110.0.0.1 sends datagram to 128.119.40.186128.119.40.186.
  2. NAT rewrites source 10.0.0.1→138.76.29.710.0.0.1 \rightarrow 138.76.29.7, stores mapping.
  3. Reply arrives for 138.76.29.7138.76.29.7.
  4. NAT consults table, rewrites destination 138.76.29.7→10.0.0.1138.76.29.7 \rightarrow 10.0.0.1, forwards internally.
  • Port multiplexing allows sharing one public IP among many internal hosts — NAT also rewrites TCP/UDP ports (covered later in TCP/UDP lecture).

Advantages of NAT

  • Only one (or a small pool of) public IPs needed — conserves scarce IPv4 addresses.
  • Internal addressing freedom: can renumber inside hosts, or switch ISPs, without visible change to the outside world.
  • Implicit security: inside hosts are not directly reachable, offering a basic firewall-like barrier.

Hands-On NAT Exercise (Wi-Fi Test)

  • Join SLIIT-STDSLIIT\text{-}STD Wi-Fi, record device’s private IP.
  • Browse to https://focnet.sliit.lk/ie1030/nat-test.php.
  • Page echoes the public IP:PORT currently representing you on the Internet — precisely the NAT table mapping.

ICMP – Internet Control Message Protocol

  • Sits above IP (protocol number 11) and is carried inside IP packets.
  • Core purposes:
    • Error reporting (destination unreachable, fragmentation needed, TTL expired, etc.).
    • Echo diagnostics (ping).
    • Router discovery & advertisement.
  • Generic ICMP packet structure: Type | Code | Checksum | data (often the first 88 bytes of the offending IP packet).

Common ICMP Types & Codes

  • Echo reply: Type 00 Code 00.
  • Echo request: Type 88 Code 00.
  • Destination unreachable: Type 33 with multiple codes:
    • 00 network unreachable, 11 host unreachable, 33 port unreachable, 44 fragmentation needed but DF set, 66 network unknown, 1010 communication administratively prohibited, etc.
  • TTL expired: Type 1111 Code 00.
  • Bad IP header: Type 1212 Code 00.

Ping (ICMP Echo)

  • Sender emits Echo Request (Type 88).
  • Receiver responds with Echo Reply (Type 00).
  • Identifier + Sequence Number let sender match replies and measure RTT.

ICMP Destination Unreachable

  • Usually generated by an intermediate router.
  • Frame includes IP header + first 88 bytes of original payload so the sender can identify the failed packet.

Traceroute Algorithm

  • Send 3 probes per hop, incrementing TTL: 1,2,3,…1,2,3,\dots.
  • Each router that decrements TTL to 00 returns ICMP Time exceeded (Type 1111).
  • When destination is finally reached, it replies with Port unreachable (Type 33 Code 33) — traceroute stops.
  • RTT for each hop measured from request ➔ corresponding ICMP reply.

Address Resolution Protocol (ARP)

  • Goal: map known IPv4 addresses to unknown MAC addresses on a local (broadcast) network.
  • ARP is considered layer 2.5 — messages are not encapsulated in IP; instead they ride directly inside Ethernet frames (Ethertype 08060806).

ARP Table (Cache)

  • Each host stores learned bindings: IP, MAC, TTL (≈2020 min default).

ARP Packet Format

  • Fixed header (8 bytes): Hardware Type, Protocol Type, HLEN, PLEN, Opcode.
    • 00010001 = Ethernet, 08000800 = IPv4, HLEN =6=6, PLEN =4=4.
    • Opcode 11 = request, 22 = reply.
  • Variable portion: Sender MAC, Sender IP, Target MAC, Target IP (total 20 bytes for Ethernet/IPv4).
  • Entire ARP message encapsulated in an Ethernet frame → FCS.

ARP Operational Sequence

  1. Host A needs MAC of host B (IP known, MAC unknown, not in cache).
  2. A broadcasts ARP Request with:
    • Dest MAC ff:ff:ff:ff:ff:ffff:ff:ff:ff:ff:ff, Target IP = B, Target MAC = 00:00:00:00:00:0000:00:00:00:00:00.
  3. Every LAN node examines; only B replies via unicast ARP Reply:
    • Contains B’s MAC in Sender MAC/Target MAC fields.
  4. A receives, updates its ARP table, sets TTL timer.
  5. Subsequent IP packets to B are encapsulated using B’s resolved MAC.

Inter-Protocol Relationships (Big Picture)

  • IP delivers packets end to end; broadcast, subnetting & NAT modify addressing semantics.
  • ICMP gives the network a “voice” for diagnostics & error signalling.
  • ARP glues IP to the underlying data-link layer, enabling local delivery.
  • Combined, these protocols enable scalable, routable, and debuggable IPv4 networking in both private and public contexts.