Layer 2: Switching and MAC Addresses
At the Data Link Layer (Layer 2), devices communicate using MAC (Media Access Control) addresses. Switches maintain a MAC Address Table mapping ports to MAC addresses. When a switch receives a frame, it looks up the destination MAC. If found, it forwards the frame to the specific port; if not, it floods the frame to all ports (except the source).
The Glue: ARP (Address Resolution Protocol)
Devices know IP addresses, but hardware requires MAC addresses. ARP bridges this gap. When a host wants to send data to a local IP, it broadcasts: 'Who has 192.168.1.5? Tell 192.168.1.10'. The target replies with its MAC.
Layer 3: Routing and Tables
Routers forward packets between different networks based on IP addresses. Every host and router maintains a Routing Table. The fundamental rule of routing is the Longest Prefix Match: the most specific route (highest subnet mask) wins.
In the example above, traffic to `10.0.0.50` uses the local link (`eth0`). Traffic to `8.8.8.8` matches the `default` route (0.0.0.0/0) and is sent to the gateway `10.0.0.1`.
Static vs. Dynamic Routing
Static Routing: Routes are manually configured. Simple, predictable, but doesn't scale or heal.
Dynamic Routing: Routers exchange information to build tables automatically.
- IGP (Interior Gateway Protocol): Used within an autonomous system (e.g., OSPF, IS-IS). Focuses on speed and efficiency.
- EGP (Exterior Gateway Protocol): Used between autonomous systems. BGP (Border Gateway Protocol) is the protocol of the Internet. It makes routing decisions based on paths, network policies, and rules rather than just speed.