Documentation Index
Fetch the complete documentation index at: https://resources.devweekends.com/llms.txt
Use this file to discover all available pages before exploring further.
Module 3: Physical & Data Link Layers
These layers are responsible for moving bits across the wire (or air) and organizing them into frames for local delivery. If the network is a postal system, these two layers are the physical roads and the local delivery trucks — they handle the last mile of actually getting data from one device to the device next to it.3.1 Layer 1: Physical Layer
The Physical Layer defines the hardware elements involved in transmitting data. This is the only layer that deals with actual physical signals — everything above is logical abstraction.Key Concepts
- Media: Copper cables (Cat5e, Cat6), Fiber Optic, Wireless (Radio waves). Each has different speed limits, distance limits, and interference characteristics.
- Signals: Digital (bits — discrete 0s and 1s) vs Analog (waves — continuous signals). Copper and fiber carry digital signals; Wi-Fi uses analog radio waves that encode digital data.
- Topologies: Bus (one shared cable), Star (central hub/switch), Ring (devices in a loop), Mesh (every device connected to every other). Modern LANs almost universally use the star topology with a switch at the center.
Practical Considerations
| Cable Type | Max Speed | Max Distance | Use Case |
|---|---|---|---|
| Cat5e | 1 Gbps | 100 meters | Office LAN (legacy) |
| Cat6 | 10 Gbps | 55 meters (10G) / 100m (1G) | Modern office LAN |
| Cat6a | 10 Gbps | 100 meters | Data centers, new builds |
| Single-mode Fiber | 100+ Gbps | 80+ km | Long-distance, ISP backbone |
| Multi-mode Fiber | 10-100 Gbps | 300-550 meters | Data center interconnects |
3.2 Layer 2: Data Link Layer
The Data Link Layer ensures error-free transmission between two directly connected nodes. While Layer 3 (IP) handles end-to-end delivery across the entire internet, Layer 2 only cares about the next hop — getting the frame to the next directly connected device. Think of it this way: IP is the full postal address (city, street, house number). MAC is the name of the person handing the letter to the next person in the chain. At each hop, the MAC addresses change, but the IP addresses stay the same.MAC Addresses
- Media Access Control (MAC) address is a unique identifier assigned to a network interface controller (NIC).
- Format:
00:1A:2B:3C:4D:5E(48-bit hex, 6 bytes). - The first 3 bytes (
00:1A:2B) identify the manufacturer (OUI - Organizationally Unique Identifier). You can look up the vendor atmacvendors.com— handy when troubleshooting unknown devices on your network. - The last 3 bytes (
3C:4D:5E) are assigned by the manufacturer to be unique per device.
MAC vs IP — a common confusion: MAC addresses are used for local delivery (within the same network segment). IP addresses are used for global routing (across the internet). When you send a packet to Google, the destination IP is Google’s server, but the destination MAC is your local router — because that is the next hop. Your router then changes the destination MAC to the next router’s MAC, and so on, hop by hop.
Ethernet Frames
Data is packaged into frames — the Layer 2 unit of data.- Preamble (8 bytes): Synchronization pattern that tells the receiver “a frame is coming.” Think of it as the ringing before a phone call.
- Destination MAC (6 bytes): Where it is going on the local network.
- Source MAC (6 bytes): Where it came from.
- Type/Length (2 bytes): Identifies the protocol of the payload (e.g.,
0x0800= IPv4,0x0806= ARP,0x86DD= IPv6). - Payload (46-1500 bytes): The actual data — an IP packet at Layer 3. The maximum payload size (1500 bytes) is called the MTU (Maximum Transmission Unit).
- FCS (4 bytes): Frame Check Sequence — a CRC checksum for error detection. If the FCS does not match, the frame is silently dropped. There is no retransmission at Layer 2; that is TCP’s job at Layer 4.
3.3 Switching
A Switch operates at Layer 2. It uses MAC addresses to forward frames to the correct port. Unlike a hub (which blindly copies every frame to every port), a switch is intelligent — it learns which devices are on which ports and sends frames only where they need to go.How a Switch Learns and Forwards
- Learning: When a frame arrives on port 1 with Source MAC
AA:BB:CC:DD:EE:FF, the switch records: “MACAA:BB:CC:DD:EE:FFis reachable via port 1.” This builds the MAC address table (also called CAM table) over time. - Forwarding: When a frame arrives with Destination MAC
11:22:33:44:55:66, the switch looks up its MAC table. If there is an entry saying that MAC is on port 5, the frame is sent only to port 5 — no other device sees it. - Flooding: If the Destination MAC is unknown (not in the table yet) or is a broadcast address (
FF:FF:FF:FF:FF:FF), the switch sends the frame to all ports except the one it arrived on. This ensures delivery even when the switch has not yet learned the destination.
Practical Scenario
Next Module
Module 4: Network Layer
Dive into IP addressing and Routing.
Interview Deep-Dive
What is the difference between a hub and a switch, and why did switches replace hubs entirely?
What is the difference between a hub and a switch, and why did switches replace hubs entirely?
Strong Answer:
- A hub is a Layer 1 device that simply repeats every incoming electrical signal on every port. It is a shared medium — every device connected to the hub sees every frame, regardless of whether it is the intended recipient. This creates a single collision domain where only one device can transmit at a time, and it means any device can eavesdrop on all traffic.
- A switch is a Layer 2 device that learns which MAC addresses are reachable on which ports by inspecting the source MAC of incoming frames. It builds a MAC address table (CAM table) and then forwards frames only to the port where the destination MAC resides. This creates a separate collision domain per port, dramatically increasing throughput.
- Switches replaced hubs because the performance difference is enormous. On a 24-port hub with 1 Gbps, all 24 devices share that 1 Gbps bandwidth. On a 24-port switch, each device gets a dedicated 1 Gbps connection. In a busy office, that is the difference between unusable and perfectly fine.
- There is also a security angle: on a hub, any device can capture all traffic with a packet sniffer. On a switch, traffic is isolated per port. Although ARP spoofing and MAC flooding attacks can still be used to circumvent this, a switch provides significantly better baseline security than a hub.
You are troubleshooting a network issue and a colleague says 'it must be an MTU problem.' What does that mean, and how would you diagnose and fix it?
You are troubleshooting a network issue and a colleague says 'it must be an MTU problem.' What does that mean, and how would you diagnose and fix it?
Strong Answer:
- MTU (Maximum Transmission Unit) is the largest payload size a Layer 2 frame can carry — typically 1500 bytes for standard Ethernet. If an IP packet exceeds the MTU of a link in the path, it must either be fragmented into smaller packets or, if the “Don’t Fragment” (DF) bit is set, the router drops the packet and sends back an ICMP “Fragmentation Needed” message.
- MTU problems most commonly surface with VPNs and tunnels. When you add a VPN encapsulation (say IPsec, which adds roughly 50-70 bytes of overhead), the effective MTU drops from 1500 to around 1430-1450 bytes. Packets that fit fine at 1500 bytes now exceed the tunnel’s effective MTU. If the DF bit is set and the ICMP “Fragmentation Needed” message is blocked by a firewall (which is depressingly common), you get a “black hole” — the connection appears to hang on large payloads while small packets (like pings) work fine.
- To diagnose, I would use
ping -M do -s 1472 targeton Linux (orping -f -l 1472 targeton Windows). This sends a 1472-byte payload with DF set. If it works, try 1473, and keep increasing. When it fails, you have found the path MTU. The total packet size is payload + 8 bytes ICMP header + 20 bytes IP header, so a 1472 payload means a 1500-byte packet. - To fix: reduce the MTU on the interface (
ip link set dev eth0 mtu 1400), or if using a VPN, configure TCP MSS clamping so that TCP connections negotiate a smaller maximum segment size that fits within the reduced MTU. Most VPN software has this as a configuration option.
Explain how ARP works. What happens when a device needs to communicate with another device on the same subnet for the first time?
Explain how ARP works. What happens when a device needs to communicate with another device on the same subnet for the first time?
Strong Answer:
- ARP (Address Resolution Protocol) translates a known IP address into the corresponding MAC address on the local network segment. This is necessary because Layer 2 switching uses MAC addresses, but applications only know IP addresses.
- When Device A (192.168.1.10) wants to send a packet to Device B (192.168.1.20) on the same subnet for the first time, A checks its ARP cache. Finding no entry for 192.168.1.20, it broadcasts an ARP Request to the broadcast MAC address (FF:FF:FF:FF:FF:FF): “Who has 192.168.1.20? Tell 192.168.1.10.” Every device on the local segment receives this frame.
- Device B recognizes its own IP in the request and sends an ARP Reply directly (unicast) back to Device A: “192.168.1.20 is at MAC AA:BB:CC:DD:EE:FF.” Device A caches this mapping and uses it for all subsequent frames to 192.168.1.20 until the cache entry expires (typically 60-300 seconds depending on the OS).
- If Device A wants to reach an IP on a different subnet (say 8.8.8.8), it does not ARP for 8.8.8.8. Instead, it ARPs for the default gateway’s IP (192.168.1.1) to get the gateway’s MAC address. It then sends the frame to the gateway’s MAC with the destination IP set to 8.8.8.8. The gateway handles routing from there. This is a subtlety that many people miss — the destination MAC is always the next hop, not the final destination.