08: The Link Layer: Ethernet, MAC, ARP and Switches
Course: Networking - Security Advanced · Updated: October 2026 Literature: K&R chapter 6 (The Link Layer and LANs): multiple access protocols, switched LANs, "a day in the life of a web page request" Related labs: Wireshark lab: Ethernet and ARP (solution)
Learning objectives
After studying this article you can:
- describe the services of the link layer and where it is implemented
- explain multiple access and the CSMA and CSMA/CD protocols
- explain MAC addresses and the difference from IP addresses
- explain how ARP maps an IP address to a MAC address, within a subnet and to another subnet
- describe the Ethernet frame and the Ethernet standards
- explain how a switch learns, filters and forwards (self-learning), and compare switches with routers
- follow "a day in the life of a web page request" through all the layers
1. Link-layer services
The link layer moves a datagram from one node to the adjacent node over a single link. Its services:
- Framing: putting the datagram inside a frame with a header and trailer
- Link access: deciding who may send on a shared medium (MAC protocol)
- Reliable delivery between neighbours. Rare on wired links, common on wireless links (Wi-Fi ACKs, see article 10).
- Error detection and correction: parity, checksums, CRC (Cyclic Redundancy Check)
The link layer is implemented in the network interface card (NIC), partly in hardware and partly in the driver.
2. Multiple access protocols
On a broadcast link (shared medium), several nodes can send at the same time and cause a collision. There are three families of MAC protocols:
| Family | Examples | Idea |
|---|---|---|
| Channel partitioning | TDMA, FDMA, CDMA | Divide the channel into time slots or frequencies |
| Random access | ALOHA, slotted ALOHA, CSMA, CSMA/CD, CSMA/CA | Send at full rate and recover when there is a collision |
| Taking turns | Polling, token passing, Bluetooth | A master or token decides who may send |
CSMA: Carrier Sense Multiple Access
"Listen before you talk." If the channel is busy, wait. Collisions can still happen because of propagation delay: two nodes can't yet hear each other's signal.
CSMA/CD: with Collision Detection (classic Ethernet)
- The NIC gets a datagram and makes a frame.
- If the channel is idle, send. If it's busy, wait until it's idle.
- If the whole frame is sent without a collision, done.
- If a collision is detected while sending: stop and send a jam signal.
- Binary exponential backoff: after the m-th collision, choose K at random from {0, 1, ..., 2ᵐ−1} and wait K × 512 bit times. The more collisions, the longer the average wait.
Note (2026): modern Ethernet is full-duplex and switched, so every link has only two nodes, and there are no collisions. CSMA/CD only matters for historical half-duplex hubs. The principle of random access with backoff lives on in Wi-Fi (CSMA/CA).
3. MAC addresses and ARP
3.1 MAC addresses
- 48 bits, written in hexadecimal:
1A-2F-BB-76-09-ADor1a:2f:bb:76:09:ad - Assigned to the NIC by the manufacturer. The first 24 bits are the OUI (Organizationally Unique Identifier) of the vendor.
- Flat addressing (it doesn't depend on where you are), unlike hierarchical IP addresses
- Broadcast address:
FF-FF-FF-FF-FF-FF
| MAC address | IP address | |
|---|---|---|
| Layer | Link (2) | Network (3) |
| Structure | Flat | Hierarchical (network + host part) |
| Analogy | Social security number (BSN) | Postal address |
| Changes when you move? | No (although see MAC randomisation below) | Yes |
MAC randomisation: iOS, Android, Windows and macOS now use a random MAC address per Wi-Fi network by default, for privacy. This makes tracking harder, but it also affects networks that identify devices by MAC address.
3.2 ARP: Address Resolution Protocol (RFC 826)
Question: I know the IP address of my destination. What is its MAC address?
Every host and router keeps an ARP table: <IP address; MAC address; TTL> (typically a few minutes).
Same subnet:
- A wants to send to B (IP known, MAC unknown).
- A broadcasts an ARP request: "Who has 192.168.1.20? Tell 192.168.1.10" (destination MAC
FF-FF-FF-FF-FF-FF). - B answers with a unicast ARP reply: "192.168.1.20 is at 58-23-D7-FA-20-B0".
- A stores this in its ARP table.
ARP is plug-and-play: no administrator is needed.
To another subnet (through a router):
- A sees that B is in another subnet, so the frame has to go to the default gateway (router R).
- A uses ARP to find R's MAC address.
- A sends a frame with: destination MAC = R, destination IP = B.
- R removes the frame, forwards the datagram, and makes a new frame for the next link with its own source MAC and the next hop's MAC.
Key point: the IP addresses stay the same end to end (apart from NAT). The MAC addresses change on every hop.
In IPv6, ARP is replaced by Neighbor Discovery Protocol (NDP) (ICMPv6 Neighbor Solicitation/Advertisement, RFC 4861).
1 2 3 4 | |
4. Ethernet
Ethernet is the dominant wired LAN technology. It has gone from 10 Mbit/s (1980s, coax cable) to 400 Gbit/s and 800 Gbit/s in data centres (2024–2026), and 1.6 Tbit/s is in development.
4.1 The Ethernet frame
1 2 3 4 | |
- Preamble + SFD: synchronises the receiver's clock (
10101010 ... 10101011) - Type (EtherType): which protocol is in the payload, e.g.
0x0800= IPv4,0x86DD= IPv6,0x0806= ARP,0x8100= VLAN tag (see article 09) - CRC: error detection. A frame with errors is dropped without notice.
- MTU: 1500 bytes. In data centres, jumbo frames of up to ~9000 bytes are used.
Ethernet is connectionless (no handshake) and unreliable (no ACKs). Reliability comes from higher layers (TCP).
4.2 Ethernet standards (IEEE 802.3)
| Standard | Speed | Medium |
|---|---|---|
| 100BASE-TX | 100 Mbit/s | Copper (Cat5) |
| 1000BASE-T | 1 Gbit/s | Copper (Cat5e/6) |
| 2.5G/5GBASE-T | 2.5/5 Gbit/s | Copper. Common for Wi-Fi 6/7 access points. |
| 10GBASE-T / -SR / -LR | 10 Gbit/s | Copper / multimode fibre / single-mode fibre |
| 25/100/400/800 GbE | Data centre | Fibre and DAC cables |
| PoE (802.3af/at/bt) | up to 90 W | Power over the network cable for phones, access points and cameras |
5. Switches
5.1 How a switch works
A switch is a link-layer device:
- Transparent: hosts don't know that switches exist
- Plug-and-play and self-learning: no configuration needed for basic operation
- Store-and-forward (or cut-through): it looks at the destination MAC of each frame and forwards it selectively
- Full-duplex links, so no collisions. Many hosts can send at the same time.
5.2 Self-learning
The switch keeps a switch table (MAC address table / CAM table): <MAC address, interface, TTL>.
When a frame arrives on interface x:
1 2 3 4 5 6 7 | |
5.3 Switches vs routers
| Switch | Router | |
|---|---|---|
| Layer | 2 (link) | 3 (network) |
| Addresses | MAC | IP |
| Table building | Self-learning (flooding) | Routing algorithms (OSPF, BGP) |
| Plug-and-play | Yes | No (configuration needed) |
| Broadcast domain | One large domain (broadcast storms are possible) | Separates broadcast domains |
| Topology | Tree (loops are prevented with Spanning Tree Protocol, STP/RSTP 802.1w) | Any topology |
In practice, many devices are layer-3 switches that do both.
6. A day in the life of a web page request
A student connects a laptop to the campus network and visits www.google.com. This puts everything together:
- DHCP (UDP, broadcast): the laptop gets an IP address, the default gateway and the DNS server. (DHCP Discover → Offer → Request → ACK, carried in Ethernet broadcast frames.)
- ARP: the laptop finds the MAC address of the default gateway.
- DNS: the laptop sends a DNS query (UDP 53, or DNS over HTTPS) to the DNS server. The query goes through the router, and the routing (OSPF/BGP) brings it to the DNS server.
- TCP: three-way handshake with Google's server on port 443 (or QUIC over UDP 443).
- TLS: handshake, certificate check and keys (see article 13).
- HTTP:
GET /, and the server answers with the web page.
Doing this yourself in Wireshark is one of the best ways to understand networking.
References
Videos
- Jim Kurose: Link layer, Ethernet, switches, a day in the life (chapter 6 video lectures): https://gaia.cs.umass.edu/kurose_ross/lectures.php
- Practical Networking: "Packet Traveling" series (how a packet moves through switches and routers, with ARP): https://www.practicalnetworking.net/series/packet-traveling/packet-traveling/
- Ben Eater: "How do hubs, switches, and routers work?" and the Ethernet series: https://www.youtube.com/@BenEater
- Chris Greer: ARP and Ethernet analysis in Wireshark: https://www.youtube.com/@ChrisGreer
- Jeremy's IT Lab: Ethernet, switching, STP (free CCNA course): https://www.youtube.com/@JeremysITLab
Articles
- Practical Networking, Packet Traveling (highly recommended): https://www.practicalnetworking.net/series/packet-traveling/packet-traveling/
- K&R Wireshark labs (latest versions): https://gaia.cs.umass.edu/kurose_ross/wireshark.php
- IEEE OUI lookup (which vendor does a MAC address belong to?): https://regauth.standards.ieee.org/standards-ra-web/pub/view.html#registries
Standards
- IEEE 802.3: Ethernet · IEEE 802.1D/802.1w: Spanning Tree / Rapid STP
- RFC 826: ARP · RFC 4861: IPv6 Neighbor Discovery · RFC 2131: DHCP
Tools
- Wireshark with filters
arp,eth.addr == ...,dhcp ip neigh,arp -a,Get-NetNeighbor- Cisco Packet Tracer (free with the Cisco Networking Academy): simulate switches and ARP: https://www.netacad.com/
Cyber Security
Why it matters
The link layer was designed for trusted local networks. There is no authentication in ARP or in normal Ethernet. Anyone who is connected to the LAN (an insider, a compromised laptop, an attacker on guest Wi-Fi, or a rogue device in a meeting room) can attack it:
| Attack | Description |
|---|---|
| ARP spoofing / ARP poisoning | The attacker sends fake ARP replies: "the gateway's IP is at my MAC". Victims then send all their traffic through the attacker, a man-in-the-middle (MITM). The attacker can read, change or block it. Tools: arpspoof, Ettercap, Bettercap. |
| MAC flooding | The attacker floods the switch with thousands of fake source MAC addresses. The CAM table fills up and the switch starts flooding all frames like a hub, so the attacker can sniff all the traffic (tool: macof). |
| MAC spoofing | Pretending to have another device's MAC address to get past MAC-based access control (e.g. captive portals or "MAC filtering"). |
| DHCP spoofing / starvation | A rogue DHCP server hands out the attacker's IP as gateway or DNS server, which is MITM again. Starvation uses up all the addresses in the legitimate DHCP pool. |
| STP manipulation | The attacker claims to be the root bridge, so traffic flows through them or the network becomes unstable. |
| IPv6 attacks | Rogue Router Advertisements or NDP spoofing, even in "IPv4-only" networks, because IPv6 is enabled by default on all operating systems (tool: mitm6, often used in Active Directory attacks). |
These are standard steps in penetration tests and real attacks inside company networks.
How to make it safe
- Port security on switches: limit the number of MAC addresses per port, and shut down or alert on violations. This stops MAC flooding.
- DHCP snooping: only trusted ports (towards the real DHCP server) may send DHCP offers.
- Dynamic ARP Inspection (DAI): the switch checks ARP replies against the DHCP-snooping table and drops spoofed ARP.
- IPv6 RA Guard and DHCPv6 Guard, or properly manage IPv6. Don't ignore it.
- BPDU Guard / Root Guard: end-user ports may not send STP messages.
- 802.1X network access control (NAC): a device must authenticate (with a certificate or username/password through RADIUS) before the switch port is opened. MAC filtering alone is not security.
- MACsec (IEEE 802.1AE): encryption and integrity on Ethernet links, used between switches, in data centres and for sensitive links.
- Segmentation with VLANs (see article 09): keep guests, IoT, printers and servers apart, so that an attack stays in a small domain.
- Encrypt end to end (TLS, SSH, VPN): even if someone gets MITM on the LAN, they can't read or change the content.
- Monitor: tools such as
arpwatch, an IDS (Zeek, Suricata, see article 16) and switch logs can detect ARP changes, new MAC addresses and rogue DHCP servers. - Physical security: disable unused wall ports and lock network cabinets.
Extra references
- Cisco, Layer 2 Security features: DHCP snooping, DAI, IP Source Guard, Port Security (configuration guides): https://www.cisco.com/
- SANS Reading Room, Layer 2 attacks and their mitigation: https://www.sans.org/white-papers/
- Bettercap documentation (understand the attacker's tools; use only in your own lab): https://www.bettercap.org/
- Fox-IT, mitm6: compromising IPv4 networks via IPv6 (2018): https://blog.fox-it.com/2018/01/11/mitm6-compromising-ipv4-networks-via-ipv6/
- MITRE ATT&CK T1557: Adversary-in-the-Middle (ARP cache poisoning, DHCP spoofing): https://attack.mitre.org/techniques/T1557/