14 – The Link Layer (2): Ethernet, MAC Addresses, ARP, Switches and VLANs
Course: ICT Basic course · Level: introductory Book: Kurose & Ross, 9th ed., chapter 6.3 (multiple access), 6.4 (switched LANs: addressing and ARP, Ethernet, switches, VLANs), 6.7 (a day in the life of a web request); chapter 7 (Wi-Fi) for background
Learning goals
After this article you can:
- explain the multiple access problem and the idea of CSMA/CD (legacy) and CSMA/CA (Wi-Fi);
- describe a MAC address and the Ethernet frame;
- explain how ARP maps IP addresses to MAC addresses (and what NDP does in IPv6);
- explain how a switch learns and forwards frames, and how it differs from a router;
- explain what VLANs are and why they are used;
- follow "a day in the life of a web request" through all layers.
1. Multiple access: who may send?
Some links are point-to-point (one sender, one receiver: a switch port to a PC, fibre between routers). Others are broadcast links: many nodes share one medium (Wi-Fi, old coax Ethernet, cable TV networks, 5G radio). If two nodes send at the same time → collision.
MAC (Medium Access Control) protocols decide who may send:
| Category | Idea | Examples |
|---|---|---|
| Channel partitioning | divide the channel into time slots (TDMA), frequencies (FDMA) or codes | 4G/5G (OFDMA), Wi-Fi 6/7 (OFDMA) |
| Random access | send when you want; detect/avoid collisions and retry after a random time | ALOHA, CSMA/CD (classic Ethernet), CSMA/CA (Wi-Fi) |
| Taking turns | polling or passing a token | Bluetooth, (legacy) Token Ring |
- CSMA/CD (Carrier Sense Multiple Access with Collision Detection): listen before sending, stop when a collision is detected, wait a random time (binary exponential backoff).
Legacy: CSMA/CD was essential with hubs and coax cables. Modern switched Ethernet is full-duplex: every device has its own link to the switch, so collisions don't happen and CSMA/CD isn't used any more.
- CSMA/CA (Collision Avoidance) is used by Wi-Fi: radio can't detect collisions while sending, so nodes wait a random time before sending, and the receiver confirms each frame with an ACK. Newer Wi-Fi (6/7) also uses OFDMA scheduling by the access point.
2. MAC addresses
Every network interface (NIC) has a MAC address (also: LAN address, physical address, hardware address):
- 48 bits, written in hexadecimal:
08:00:27:3a:5c:11or08-00-27-3A-5C-11 - The first 24 bits are the OUI (Organizationally Unique Identifier): which manufacturer. Look it up at https://maclookup.app/.
- Broadcast address:
ff:ff:ff:ff:ff:ff(all devices on the LAN).
| MAC address | IP address | |
|---|---|---|
| Size | 48 bits | 32 (IPv4) / 128 (IPv6) bits |
| Layer | link (2) | network (3) |
| Used for | delivery to the next device on the same link | delivery to the final destination across networks |
| Structure | flat (like a social security number) | hierarchical (like a postal address) |
| Changes when you move? | traditionally no | yes, depends on the network |
Updated: MAC addresses were meant to be fixed, but iOS, Android, Windows and macOS now use random ("private") MAC addresses per Wi-Fi network, to prevent tracking of people through their phone's MAC address.
3. The Ethernet frame (IEEE 802.3)
1 2 3 4 | |
- Type (EtherType): which network-layer protocol is inside:
0x0800IPv4,0x86DDIPv6,0x0806ARP,0x8100VLAN tag. - CRC: error detection (article 13). Frames with errors are dropped.
- Ethernet is connectionless and unreliable (no ACKs).
- Speeds: from 10 Mbit/s (1980s) to 1/2.5/10 Gbit/s at desks, 25/100/400/800 Gbit/s in data centres, and 1.6 Tbit/s being standardised.
4. ARP – Address Resolution Protocol
Problem: a host knows the destination's IP address, but to send a frame on the LAN it needs the MAC address.
ARP (RFC 826) solves this for IPv4:
1 2 3 4 5 | |
Sending to a host in another subnet: A doesn't ARP for the remote host but for its default gateway (router). The frame goes to the router's MAC address, while the IP datagram still has the final destination IP. The router then makes a new frame for the next link.
1 | |
IPv6 doesn't use ARP. Instead it uses NDP (Neighbor Discovery Protocol), with ICMPv6 Neighbor Solicitation and Neighbor Advertisement messages sent to multicast addresses instead of broadcast.
5. Switches
A switch is a layer-2 device that forwards frames based on MAC addresses.
5.1 Self-learning
The switch builds a MAC address table (switch table, CAM table) by itself:
- A frame arrives on port 1 with source MAC
AA→ the switch notes: "AAis on port 1". - Destination MAC known? → forward only to that port (filtering/forwarding).
- Destination unknown (or broadcast)? → send to all ports except the incoming one (flooding).
- Entries expire after a while (e.g. 300 seconds).
1 2 3 | |
Switches are transparent (hosts don't know they're there) and plug-and-play.
5.2 Switch vs. router
| Switch | Router | |
|---|---|---|
| Layer | 2 (link) | 3 (network) |
| Forwards based on | MAC address | IP address |
| Table | learned automatically | routing protocols / static configuration |
| Broadcasts | forwards them (one broadcast domain) | stops them (separates broadcast domains) |
| Connects | devices in one LAN/subnet | different networks/subnets |
Loops: with redundant links between switches, broadcasts would loop forever. The Spanning Tree Protocol (STP / RSTP) blocks redundant paths. Data centres often use routed designs (leaf-spine) instead.
6. VLANs – Virtual LANs
Without VLANs, everything connected to one switch is in one broadcast domain. With VLANs you can divide one physical switch (or a group of switches) into several virtual LANs, each its own broadcast domain and (usually) its own IP subnet.
1 2 3 4 5 6 | |
- Access port: belongs to one VLAN (for PCs, printers).
- Trunk port: carries several VLANs between switches/routers. Frames get an 802.1Q tag (4 extra bytes with the 12-bit VLAN ID, so up to 4094 VLANs).
- Traffic between VLANs must pass a router or layer-3 switch (where you can filter it with a firewall).
Why use VLANs? Security and segmentation (article 12), less broadcast traffic, flexibility (move a user to another department without re-cabling), and separating voice, guests and IoT.
In data centres and the cloud, VXLAN (up to 16 million segments, tunnelled over IP) extends the VLAN idea.
7. Putting it all together: a day in the life of a web request
You open your laptop at the HvA, connect to the network and visit www.google.com:
- DHCP (UDP broadcast inside an Ethernet broadcast frame): the laptop gets an IP address, subnet mask, gateway and DNS server.
- ARP: the laptop finds the MAC address of the gateway.
- DNS: the laptop sends a DNS query (UDP 53, or encrypted DoH) via the gateway to the resolver. The datagram is routed (OSPF inside the HvA/SURF network, BGP between SURF and Google) and answered.
- TCP 3-way handshake (or QUIC) with Google's server on port 443.
- TLS handshake: certificate check, keys agreed (article 17).
- HTTP request/response: the page arrives, often from a CDN server close by.
Every step uses the layers from this course: application → transport → network → link → physical, and back.
8. Try it yourself
ip link/ip a(Linux) orgetmac /v/ipconfig /all(Windows): what is your MAC address? Look up the manufacturer (OUI). Is your Wi-Fi MAC address randomised?ip neigh/arp -a: which IP–MAC pairs are in your ARP cache? Is the gateway there?- Wireshark ARP: delete the ARP cache (
sudo ip neigh flush all, orarp -d *as admin on Windows), start a capture with filterarp, and ping your gateway. Find the request (broadcast) and the reply. - Wireshark Ethernet: look at any frame. Which EtherType? Which source and destination MACs? Is the destination MAC the gateway's MAC when you visit a website?
- In Wireshark, filter
icmpv6.type == 135 || icmpv6.type == 136to see IPv6 Neighbor Solicitations/Advertisements.
Check your understanding
- Why is CSMA/CD no longer used in modern Ethernet?
- What are the differences between a MAC address and an IP address?
- Describe the ARP request and reply. Which one is a broadcast?
- To which MAC address does a host send a frame destined for a server on the Internet?
- How does a switch learn which device is on which port?
- What is a VLAN, and what is the difference between an access port and a trunk port?
References
Book
- Kurose & Ross, 9th ed., chapter 6.3–6.4 and 6.7 ("A day in the life of a web page request"); chapter 7 (Wi-Fi)
Videos
- PowerCert – ARP Explained – Address Resolution Protocol https://www.youtube.com/watch?v=cn8Zxh9bPio
- PowerCert – Hub, Switch, & Router Explained https://www.youtube.com/watch?v=1z0ULvg_pW8
- Ben Eater – Networking tutorial (Ethernet frames on real hardware) https://www.youtube.com/playlist?list=PLowKtXNTBypH19whXTVoG3oKSuOcw_XeW
- Professor Messer – CompTIA Network+ N10-009 (switching, VLANs, 802.1Q) https://www.youtube.com/playlist?list=PLG49S3nxzAnl_tQe3kvnmeMid0mjF8Le8
Articles and standards
- RFC 826 – ARP – https://www.rfc-editor.org/rfc/rfc826
- RFC 4861 – Neighbor Discovery for IPv6 – https://www.rfc-editor.org/rfc/rfc4861
- Practical Networking – Packet Traveling series (how packets move through switches and routers) – https://www.practicalnetworking.net/series/packet-traveling/packet-traveling/
- MAC address vendor lookup – https://maclookup.app/
Cyber Security
Why is this important for cyber security?
The link layer is built on trust: devices believe what others on the LAN tell them. Anyone who can plug into the network (or join the Wi-Fi) can abuse that.
| Attack | How it works | Effect |
|---|---|---|
| ARP spoofing / poisoning | the attacker sends fake ARP replies: "the gateway's IP is at my MAC" | man-in-the-middle: all traffic goes through the attacker, who can read or change it |
| MAC flooding | the attacker sends thousands of frames with fake source MACs; the switch's table overflows | the switch floods all frames to all ports → attacker can sniff everything |
| MAC spoofing | the attacker copies the MAC of an authorised device | bypasses MAC-based access lists or captive portals |
| VLAN hopping | abusing trunk negotiation (DTP) or double 802.1Q tagging | reaching another VLAN without passing the firewall |
| Rogue switch / STP attacks | an attacker's device claims to be the root bridge | traffic redirected, network instability |
| Rogue access point / evil twin | a fake Wi-Fi network with the same name (SSID) | users connect to the attacker |
| Rogue DHCP / RA | see article 11 |
What can you do to make it safe?
- Port security: limit the number of MAC addresses per switch port; shut down unused ports.
- 802.1X (network access control): devices must authenticate (certificate or account) before the switch port or Wi-Fi gives access. Combined with a RADIUS server, users can be placed in the right VLAN automatically. Eduroam uses 802.1X.
- Dynamic ARP Inspection (DAI) and DHCP snooping on managed switches block forged ARP replies and rogue DHCP servers.
- VLAN hardening: disable automatic trunking (DTP), don't use VLAN 1 for user traffic, use a separate "native" VLAN, and only allow the needed VLANs on trunks.
- STP protection: BPDU guard and root guard on access ports.
- Wi-Fi: use WPA3 (or WPA2-AES at least), WPA3-Enterprise/802.1X in companies, wireless intrusion detection against rogue APs. Never use WEP or WPA-TKIP (broken).
- Encrypt anyway: even if someone performs a man-in-the-middle attack on the LAN, TLS, SSH and VPNs keep the content safe. Layer-2 encryption MACsec (802.1AE) is used on sensitive links.
- Physical security: network cabinets and wall sockets in public areas are entry points.
Extra references
- Professor Messer – CompTIA Network+ N10-009 (network hardening: port security, DHCP snooping, DAI) – https://www.youtube.com/playlist?list=PLG49S3nxzAnl_tQe3kvnmeMid0mjF8Le8
- Wi-Fi Alliance – WPA3 – https://www.wi-fi.org/discover-wi-fi/security
- eduroam – https://eduroam.org/
- NCSC-NL – https://www.ncsc.nl/