Skip to content
BoKSA

14 – The Link Layer (2): Ethernet, MAC Addresses, ARP, Switches and VLANs

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:11 or 08-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
 ┌──────────┬──────────┬──────────┬──────┬───────────────────────┬─────────┐
 │ preamble │ dest MAC │ src MAC  │ type │  data (46–1500 bytes) │ CRC-32  │
 │  8 bytes │  6 bytes │  6 bytes │  2   │  e.g. IP datagram     │ 4 bytes │
 └──────────┴──────────┴──────────┴──────┴───────────────────────┴─────────┘
  • Type (EtherType): which network-layer protocol is inside: 0x0800 IPv4, 0x86DD IPv6, 0x0806 ARP, 0x8100 VLAN 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
 A (192.168.1.10) wants to send to B (192.168.1.20):

 1. A broadcasts:  ARP request  "Who has 192.168.1.20? Tell 192.168.1.10"  → dst MAC ff:ff:ff:ff:ff:ff
 2. B answers:     ARP reply    "192.168.1.20 is at 3c:22:fb:12:34:56"     → unicast to A
 3. A stores this in its ARP cache (for a limited time, e.g. a few minutes)

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
ip neigh            # Linux: the ARP/neighbour cache   (Windows/macOS: arp -a)

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:

  1. A frame arrives on port 1 with source MAC AA → the switch notes: "AA is on port 1".
  2. Destination MAC known? → forward only to that port (filtering/forwarding).
  3. Destination unknown (or broadcast)? → send to all ports except the incoming one (flooding).
  4. Entries expire after a while (e.g. 300 seconds).
1
2
3
 MAC address        port   age
 aa:aa:aa:aa:aa:aa   1      12 s
 bb:bb:bb:bb:bb:bb   3      40 s

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
            ┌─────────────────── switch ───────────────────┐
            │ VLAN 10 Staff │ VLAN 20 Students │ VLAN 99 Mgmt │
            │ ports 1–8     │ ports 9–20       │ port 24      │
            └──────┬────────────────────────────────────────┘
                   │ trunk port (802.1Q tags: VLAN 10, 20, 99)
                 router / layer-3 switch (routes and filters between VLANs)
  • 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:

  1. DHCP (UDP broadcast inside an Ethernet broadcast frame): the laptop gets an IP address, subnet mask, gateway and DNS server.
  2. ARP: the laptop finds the MAC address of the gateway.
  3. 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.
  4. TCP 3-way handshake (or QUIC) with Google's server on port 443.
  5. TLS handshake: certificate check, keys agreed (article 17).
  6. 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

  1. ip link / ip a (Linux) or getmac /v / ipconfig /all (Windows): what is your MAC address? Look up the manufacturer (OUI). Is your Wi-Fi MAC address randomised?
  2. ip neigh / arp -a: which IP–MAC pairs are in your ARP cache? Is the gateway there?
  3. Wireshark ARP: delete the ARP cache (sudo ip neigh flush all, or arp -d * as admin on Windows), start a capture with filter arp, and ping your gateway. Find the request (broadcast) and the reply.
  4. 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?
  5. In Wireshark, filter icmpv6.type == 135 || icmpv6.type == 136 to see IPv6 Neighbor Solicitations/Advertisements.

Check your understanding

  1. Why is CSMA/CD no longer used in modern Ethernet?
  2. What are the differences between a MAC address and an IP address?
  3. Describe the ARP request and reply. Which one is a broadcast?
  4. To which MAC address does a host send a frame destined for a server on the Internet?
  5. How does a switch learn which device is on which port?
  6. 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

Articles and standards


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