Layer 2 and Layer 3: Networking Foundations for AWS
Layer 2 and layer 3 (for example, VLANs, IP addressing, gateways, routing, switching)
Layer 2 and Layer 3: Networking Foundations for AWS
To master AWS Advanced Networking, one must first master the fundamentals of how data moves across physical and virtual wires. This guide covers the essential mechanics of switching (Layer 2) and routing (Layer 3), and how they are abstracted in the cloud through Software-Defined Networking (SDN).
Learning Objectives
By the end of this guide, you should be able to:
- Differentiate between Layer 2 (Data Link) and Layer 3 (Network) operations.
- Explain how VLANs and MAC address tables function within a switched environment.
- Contrast the roles of a Router and a Gateway in hybrid connectivity.
- Understand the impact of Software-Defined Networking (SDN) on traditional control and forwarding planes.
Key Terms & Glossary
- MAC (Media Access Control) Address: A unique identifier assigned to a Network Interface Controller (NIC) for communications at the data link layer.
- Frame: The unit of data at Layer 2, containing source and destination MAC addresses.
- Packet: The unit of data at Layer 3, containing source and destination IP addresses.
- ASIC (Application-Specific Integrated Circuit): Specialized hardware used in switches to perform wire-speed forwarding with low latency.
- STP (Spanning Tree Protocol): A network protocol that builds a loop-free logical topology for Ethernet networks.
- Collision Domain: A network segment where data packets can "collide" with one another during transmission; modern switches create one domain per port.
The "Big Idea"
In traditional networking, every device is a "black box" containing its own brain (Control Plane) and muscles (Forwarding Plane). In the AWS ecosystem, this is flipped. AWS uses Software-Defined Networking (SDN) to pull the "brains" out of the individual switches and routers, centralizing them in a global control plane. This allows for massive scale and programmatic control (APIs) that physical hardware simply cannot match.
Formula / Concept Box
| Concept | Layer | PDU (Data Unit) | Addressing | Primary Hardware |
|---|---|---|---|---|
| Data Link | Layer 2 | Frame | MAC Address | Switch / Bridge |
| Network | Layer 3 | Packet | IP Address | Router / Gateway |
[!IMPORTANT] A Default Gateway in a standard TCP/IP configuration is almost always the local Layer 3 router interface.
Hierarchical Outline
- Layer 2: Switching
- Forwarding Logic: Based on MAC Addresses; builds a local forwarding table.
- Traffic Reduction: Switches send frames only to the destination port, rather than flooding all ports.
- Loop Prevention: Uses Spanning Tree Protocol (STP) to prevent broadcast storms.
- VLANs (Virtual LANs): Logical segmentation of a physical switch into multiple broadcast domains.
- Layer 3: Routing
- Forwarding Logic: Based on IP Addresses.
- Network Interconnection: Routers connect different networks and divide broadcast domains.
- Gateways: Act as translators between different protocols (e.g., translating between different communication standards).
- Software-Defined Networking (SDN)
- Control Plane: The "management" software that decides where traffic should go.
- Forwarding Plane: The "silicon" (hardware) that actually moves the bits.
- Abstraction: SDN decouples these, allowing centralized management via API.
Visual Anchors
The Data Encapsulation Process
Switch vs. Router Logic
Definition-Example Pairs
- Broadcast Domain: The logical area in which a device can reach another by a broadcast address.
- Example: In a standard home network, all devices connected to the same Wi-Fi router share a broadcast domain; an ARP request from one laptop is heard by all.
- Control Plane: The part of the network architecture that determines the path of the traffic.
- Example: BGP (Border Gateway Protocol) running on a router is part of the control plane; it learns routes and builds the table, but doesn't touch the actual user data.
- VLAN (Virtual Local Area Network): A subnetwork which can group together collections of devices on separate physical local area networks.
- Example: Separating the "Accounting Department" and "Guest Wi-Fi" on the same physical switch hardware so they cannot talk to each other without a router.
Worked Examples
Example 1: Collision Domain Calculation
Scenario: A 24-port Layer 2 switch has 10 computers and 2 servers connected directly to its ports.
- Calculation: Since it is a switch (not a hub), each port is its own collision domain.
- Result: There are 24 collision domains available, and 12 are currently active.
Example 2: The Routing Decision
Scenario: A packet arrives at a router with a destination of 10.0.1.55. The router's table has:
10.0.1.0/24-> Interface eth10.0.0.0/0-> Interface eth0 (Default Gateway)
- Decision: The router identifies that
10.0.1.55fits into the10.0.1.0/24subnet. - Result: It forwards the packet out of eth1.
Checkpoint Questions
- What is the primary difference between a Layer 2 switch and a Layer 3 router regarding broadcast domains?
- Why is the separation of the control plane and forwarding plane essential for cloud providers like AWS?
- What protocol is used at Layer 2 to prevent switching loops?
- How does a Gateway differ from a standard Router?
Muddy Points & Cross-Refs
- Router vs. Gateway: In AWS, you will see "Internet Gateway" or "Transit Gateway." While we often use the terms interchangeably in home networking (the "default gateway"), in a technical sense, a Gateway translates between different protocols, while a Router moves traffic between networks using the same protocol.
- L3 Switches: You may encounter "Layer 3 Switches." These are simply switches that have been given routing capabilities through hardware, allowing them to route traffic at wire speed using ASICs.
Comparison Tables
Router vs. Gateway
| Feature | Router | Gateway |
|---|---|---|
| OSI Layer | Layer 3 | Layer 3 to Layer 7 |
| Primary Goal | Route packets between networks | Translate between different protocols |
| Routing Protocol | Runs BGP, OSPF, etc. | Generally does not run routing protocols |
| Complexity | High (Path determination) | Very High (Protocol translation) |
Software-Defined vs. Traditional Networking
| Feature | Traditional Networking | SDN (AWS Approach) |
|---|---|---|
| Management | Individual device configuration | Centralized Console / API |
| Scalability | Limited by hardware manual labor | Near-infinite via automation |
| Planes | Control/Forwarding integrated | Control/Forwarding decoupled |