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 1.
- Example (Class C sized subnet): 223.1.1.0/24⇒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: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—but the address is specific to one subnet and therefore routable across the Internet.
- Example: for 223.1.1.0/24 the directed broadcast is 223.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.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 0, implied prefix /8.
- Class B: leading bits 10, implied prefix /16.
- Class C: leading bits 110, implied prefix /24.
- Class D: leading bits 1110, reserved for multicast.
- Class E: leading bits 1111, 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 yields two /27 sub-prefixes.
- Combining two adjacent /25 networks recreates the parent /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 100, 50 and 25 hosts.
- Steps (largest first):
- 100 hosts ⇒ need ≥100+2=102 addresses ⇒ /25 (gives 27−2=126 usable).
- Assigned range: 223.1.1.0 – 223.1.1.127 ⇒ 223.1.1.0/25.
- 50 hosts ⇒ need /26 ( 26−2=62 usable).
- Assigned range: 223.1.1.128 – 223.1.1.191 ⇒ 223.1.1.128/26.
- 25 hosts ⇒ need /27 ( 25−2=30 usable).
- Assigned range: 223.1.1.192 – 223.1.1.223 ⇒ 223.1.1.192/27.
- Remaining addresses: 223.1.1.224/27 (unused / future growth).
Subnetting with Private Address Blocks
- RFC 1918 private ranges: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16.
- When space is plentiful (e.g.
using 172.16.0.0/12): simply dedicate one /24 per building/department if ≤254 hosts each.
- Example allocation:
- 172.16.1.0/24 — subnet needing 100 hosts.
- 172.16.2.0/24 — subnet needing 50 hosts.
- 172.16.3.0/24 — subnet needing 25 hosts.
Subnetting Exercises (Campus Scenarios)
- Exercise 1: public block 192.40.8.0/21, reserve first /24 for core, then carve out ranges for Science (120 hosts), Engineering (200), Library (80), Arts (50), Administration (40), Hostel (60), Wi-Fi (350) plus point-to-point router links.
- Exercise 2: identical logical design but using private block 172.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:
- Direct assignment from Regional Internet Registries (RIRs) – usually paid, and IPv4 is exhausted.
- 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/8, 172.16/12, 192.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)
- Host 10.0.0.1 sends datagram to 128.119.40.186.
- NAT rewrites source 10.0.0.1→138.76.29.7, stores mapping.
- Reply arrives for 138.76.29.7.
- NAT consults table, rewrites destination 138.76.29.7→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-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 1) 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 8 bytes of the offending IP packet).
Common ICMP Types & Codes
- Echo reply: Type 0 Code 0.
- Echo request: Type 8 Code 0.
- Destination unreachable: Type 3 with multiple codes:
- 0 network unreachable, 1 host unreachable, 3 port unreachable, 4 fragmentation needed but DF set, 6 network unknown, 10 communication administratively prohibited, etc.
- TTL expired: Type 11 Code 0.
- Bad IP header: Type 12 Code 0.
Ping (ICMP Echo)
- Sender emits Echo Request (Type 8).
- Receiver responds with Echo Reply (Type 0).
- Identifier + Sequence Number let sender match replies and measure RTT.
ICMP Destination Unreachable
- Usually generated by an intermediate router.
- Frame includes IP header + first 8 bytes of original payload so the sender can identify the failed packet.
Traceroute Algorithm
- Send 3 probes per hop, incrementing TTL: 1,2,3,….
- Each router that decrements TTL to 0 returns ICMP Time exceeded (Type 11).
- When destination is finally reached, it replies with Port unreachable (Type 3 Code 3) — 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 0806).
ARP Table (Cache)
- Each host stores learned bindings: IP, MAC, TTL (≈20 min default).
- Fixed header (8 bytes): Hardware Type, Protocol Type, HLEN, PLEN, Opcode.
- 0001 = Ethernet, 0800 = IPv4, HLEN =6, PLEN =4.
- Opcode 1 = request, 2 = 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
- Host A needs MAC of host B (IP known, MAC unknown, not in cache).
- A broadcasts ARP Request with:
- Dest MAC ff:ff:ff:ff:ff:ff, Target IP = B, Target MAC = 00:00:00:00:00:00.
- Every LAN node examines; only B replies via unicast ARP Reply:
- Contains B’s MAC in Sender MAC/Target MAC fields.
- A receives, updates its ARP table, sets TTL timer.
- 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.