Sub topic 1
Where MAC addresses live: LANs and the link layer
Prerequisites
This chapter assumes you know the following:
- What a network is and what an IP address does.
- How to read hexadecimal and binary numbers.
- How to run commands in a terminal.
You do not need to know anything about MAC addresses yet. This chapter sets up the context that the rest of the tutorial builds on.
The problem a MAC address solves
An IP address tells a packet where it is going across the whole internet. It does not tell the last network segment which physical network card should pick the data up. Something has to name the actual device on the wire or on the Wi-Fi channel. That something is the MAC address.
A MAC address (Media Access Control address) is a 48-bit identifier that Ethernet and Wi-Fi use to deliver frames between devices on the same local network. It is usually written as six pairs of hexadecimal digits, such as 02:00:5e:10:00:01.
What a LAN is
A LAN (local area network) is a group of devices that can reach each other directly, without passing through a router. A home network, an office floor, and a lab bench are typical examples. Devices on a LAN connect through switches, access points, or both.
The set of devices that receive each other's broadcast messages is called a broadcast domain. In most small networks, the LAN and the broadcast domain are the same thing. A router marks the edge of the domain, because routers do not forward link-layer broadcasts.
The link layer
Network software is split into layers. Each layer solves one problem and hands its result to the next. The table below shows the layers that matter here.
| Layer | Common name | Address it uses | Scope of the address |
|---|---|---|---|
| Application | HTTP, DNS, and others | Hostnames, ports | End to end |
| Transport | TCP, UDP | Port numbers | End to end |
| Network | IP | IP address | End to end across routers |
| Link | Ethernet, Wi-Fi | MAC address | One LAN only |
The link layer moves data between two devices that share the same physical or wireless network. Its unit of data is a frame. A frame wraps an IP packet with a link-layer header that contains the MAC addresses of the sender and the receiver.
The key point is scope. An IP address is meant to stay the same for the whole trip. A MAC address only has meaning on the local link, so it is replaced as the data moves from one LAN to the next. A later chapter covers this in detail.
Why the link layer needs its own address
Consider two laptops on the same switch. Laptop A knows the IP address of laptop B. A can build the IP packet, but the network card cannot send it by IP address alone. A card only recognizes frames addressed to its own MAC address, to a broadcast address, or to a multicast group it has joined. Frames addressed to anyone else are normally dropped by the card in hardware.
So before laptop A can send anything, it needs to learn B's MAC address. The protocol that does this for IPv4 is ARP, which gets its own chapter. For IPv6 the job belongs to Neighbor Discovery.
Where the address comes from
Most network interfaces have a MAC address assigned by the manufacturer and stored in the hardware. Operating systems can override it. Many modern phones and laptops use randomized addresses for Wi-Fi, which later chapters discuss.
A machine with several interfaces, such as a wired port and a Wi-Fi card, has one MAC address per interface. The address belongs to the interface and not to the computer as a whole.
Seeing it on your machine
On Linux, this command lists each interface and its MAC address on the link/ether line.
ip link showEach Ethernet or Wi-Fi interface prints a line such as link/ether 02:00:5e:10:00:01 brd ff:ff:ff:ff:ff:ff. The brd value is the broadcast address, which a later chapter explains.
Exercise
Laptop A sends a file to a web server on the other side of the internet. Which kind of address stays the same for the whole trip, and which kind is only valid on A's own LAN?
Show answer
The IP address stays the same end to end. The MAC address is only valid on A's own LAN, because it belongs to the link layer, which delivers frames between devices on one network segment.
Exercise
A laptop has both a wired Ethernet port and a Wi-Fi card. How many MAC addresses does it have, and why?
Show answer
At least two, one per interface. A MAC address identifies a network interface, not the whole computer.