Linkmacouilink layer48-bitrandomization

MAC Addresses: Identity for One Hop

A MAC address is a 48-bit link-layer identifier meant to be unique on a segment: it names an interface for the switches and neighbours on that segment, is rewritten at every router, is trivially changeable, and is now randomised per network by phones and laptops — which is why "the MAC identifies the machine" is wrong in every direction that matters.

Conceptual
Interview question
Progress

The problem

IP addresses are assigned by whoever runs the network and change when you move. Before any of that happens, the link layer needs a way to say "this frame is for that interface" that works out of the box, with no configuration and no server. Where does such an identifier come from, and how far does its meaning reach?

48 bits, half vendor, half serial

A MAC (media access control) address is 48 bits, written as six hex bytes: 3c:22:fb:4a:91:07. The first 24 bits are an OUI (organisationally unique identifier) that the IEEE sells to manufacturers — 3c:22:fb is Apple, 00:50:56 is VMware, 52:54:00 is QEMU/KVM’s default range — and the last 24 bits are assigned by the manufacturer, in principle uniquely per interface. That is what "burned-in address" means: a factory-set number that lets a NIC work on any network with zero configuration.

Two bits of the first byte carry flags. The lowest bit (I/G) is 1 for group addresses — multicast, including the all-ones broadcast ff:ff:ff:ff:ff:ff — and 0 for a single interface. The second-lowest bit (U/L) is 1 for locally administered: an address set by software rather than a factory, which is what virtual machines, containers, bonded interfaces and randomised Wi-Fi addresses use. A MAC whose second hex digit is 2, 6, A or E is locally administered; 02:42:ac:11:00:02 is Docker’s signature.

Anatomy of a MAC address
3c:22:fb:4a:91:07
└──┬───┘ └──┬───┘
  OUI     vendor-assigned (24 bits)
 (Apple)

first byte 0x3c = 0011 1100
                          │└─ I/G bit = 0 → unicast (1 = multicast/broadcast)
                          └── U/L bit = 0 → globally administered (1 = local, e.g. 02:..., 06:..., 0a:..., 0e:...)

ff:ff:ff:ff:ff:ff      broadcast: every interface on the segment
01:00:5e:xx:xx:xx      IPv4 multicast (low 23 bits of the group address)
33:33:xx:xx:xx:xx      IPv6 multicast (low 32 bits of the group address)
02:42:ac:11:00:02      Docker container (locally administered)

Scope: one segment, one hop

Here is the fact that everything else follows from: a MAC address only means something on the local segment. It is written into a frame by the sender on this link and read by the switches and the receiving interface on this link. When the frame reaches a router, the router strips the whole Ethernet header, forwards the IP packet, and builds a new frame with its *own* MAC as source and the next hop’s MAC as destination. The server at the other end of the internet sees the MAC of the last router before it — it has no way of learning yours, and no reason to.

This is why the claim "a MAC address uniquely identifies a machine on the internet" is wrong, not merely imprecise. It is not carried across the internet at all. It does not identify a machine (a laptop has several — Ethernet, Wi-Fi, Bluetooth, a VM bridge, each with its own). It is not even guaranteed unique: vendors have shipped duplicates, VMs are cloned, and any user can set one. What the MAC *is* good for is exactly its job: telling the neighbours and switches on this cable which interface should pick up this frame. ARP and Neighbor Discovery exist to map an IP to that one-hop identifier; see ARP and Neighbor Discovery: From an IP to a Local MAC.

The consequences are practical. A firewall rule "block this MAC" only works on the same segment. A DHCP reservation keyed by MAC only works until the device randomises. An "allowed MACs" list on a Wi-Fi network stops nobody who can type ip link set dev wlan0 address …. And any log that claims to show the "client MAC" of a remote user is showing a router.

  • Carried: one hop. Rewritten: at every router. Visible to the server: never (unless it is on your segment).
  • Not routable: no router forwards on MAC. Not authenticated: any host can claim any MAC. Not one per machine: one per interface.

Randomised and locally administered addresses

Conceptual

Because a stable burned-in address makes a device trackable across every network it joins — coffee shop, airport, office — iOS (since 14), Android (since 10), Windows 10+ and macOS now use randomised MAC addresses on Wi-Fi by default: a locally administered address generated per network (per SSID), sometimes rotated over time. Your phone presents a different MAC to your home network than to the office, and it is not the one printed under Settings → About. This is deliberate and it breaks every assumption built on MAC stability: DHCP reservations, captive-portal "remember this device", parental-control filters and MAC-based network access control.

Software-set addresses are everywhere else too. Every Docker container gets 02:42:…; every KVM virtual machine 52:54:00:…; a bonded pair of NICs shares one; a VRRP virtual router advertises 00:00:5e:00:01:xx that moves between physical routers on failover. In each case the address is chosen to be unique *on that segment*, which is all the link layer needs. "Locally administered" is not a corner case; on a modern network it may be most of the table.

What can go wrong with a link-layer identity

Spoofing is a one-line command: set the interface’s MAC to another host’s, and switches will learn the new port and deliver that host’s frames to you (until the real host sends and flips the table back — the flapping itself is the symptom). Combined with ARP spoofing it is the classic on-segment interception. Duplicates — two interfaces with the same MAC on one segment, from a cloned VM image or a manufacturing error — produce exactly this flapping with no attacker: both hosts get intermittent connectivity and the switch logs "MAC moved".

The design intent was never security. It was: give every interface a name that is unique enough on a cable that frames go to the right place, with no configuration. Everything that needs identity across networks — authentication, sessions, device management — has to live above the link layer, and the link layer is not going to help.

Key points

  • A MAC is 48 bits: a 24-bit vendor OUI and a 24-bit serial, with two flag bits for multicast and locally administered.
  • It identifies an *interface* on *one segment* for *one hop*. Every router strips it and writes a new one; the remote server never sees yours.
  • It is not globally unique in practice, not routable, not authenticated, and not one per machine.
  • Phones and laptops randomise their Wi-Fi MAC per network by default; VMs, containers and virtual routers use software-assigned addresses. Locally administered is normal.
  • MAC-based access control, reservations and "remember this device" break by design; identity across networks belongs above the link layer.

Why does this exist?

Mechanisms are answers to constraints. Open each question before reading the answer.

▸Why a factory-assigned address when IP addresses are assigned anyway?

Something has to work before any assignment happens: the DHCP request that gets you an IP is itself a frame that needs a source address. A burned-in unique-enough address bootstraps everything else with zero configuration.

▸Why 48 bits?

Large enough (2^47 unicast addresses) that a vendor block scheme could hand out uniqueness without coordination per device, small enough for 1980s hardware to match at line rate. It has held up.

▸Why do phones randomise it?

A stable identifier broadcast in cleartext to every network you join is a tracking beacon. Randomising per network keeps the link layer working (unique on this segment) while denying cross-network correlation.

How it fails

What the failure looks like from inside real software.
Reference · show
  • DHCP reservation stops matching after a phone OS update: the device now presents a randomised MAC; the reservation targets the burned-in one.
  • Two VMs cloned from one image share a MAC: both get intermittent connectivity, the switch logs address flapping, ARP entries point at the wrong host.
  • A "block by MAC" rule at the office firewall does nothing for a device on a different subnet — the firewall sees the router’s MAC.
  • Wi-Fi MAC allowlisting as security: bypassed by one ip link set … address after sniffing one legitimate frame.
  • A log analysis that groups "client MACs" from a remote server: every entry is the same upstream router.

Check yourself

Answer out loud or on paper first, then compare. These come from the interview questions linked to this lesson.

  1. What is the difference between a switch and a router? What does each one look at, and what does each one change in the packet?

    Show a strong answer

    A switch forwards Ethernet frames by destination MAC address within one network segment. It learns by watching: every frame’s source MAC is recorded against the port it arrived on, building a MAC table. A frame to a known MAC goes out one port; to an unknown MAC, or to the broadcast address, it is flooded out every port. The switch never modifies the frame and does not look at IP. Everything connected to the same switch (or VLAN) is one broadcast domain: an ARP request reaches all of it.

    A router forwards IP packets between networks by destination IP address, using a routing table and longest-prefix match to choose a next hop and an outgoing interface. It strips the incoming Ethernet header, decrements the TTL/hop limit, and writes a new Ethernet header addressed to the next hop’s MAC (resolved by ARP or Neighbor Discovery). Broadcasts stop at the router — that is what makes it a boundary between networks.

    The practical consequence: hosts on the same subnet talk directly through switches (fast, no IP-level device involved); hosts on different subnets must go through a router, which is why the default gateway matters and why "same subnet but unreachable" points at layer 2 (ARP, VLANs, MAC tables) while "different subnet unreachable" points at routes and firewalls.

    Full interview question, with follow-ups and red flags →
  2. Describe what happens to an HTTP request as it goes down the stack on the sender and up on the receiver. What does each layer add and why?

    Show a strong answer

    The application writes an HTTP message — text headers and a body — into a socket. TCP treats it as a byte stream, splits it into segments no larger than the MSS (typically 1460 bytes on Ethernet without options), and prefixes each with a header carrying source and destination ports (which process), a sequence number (where these bytes belong in the stream), an acknowledgement number, flags and the receive window. TCP’s header solves TCP’s problem: reliable ordered delivery between two processes.

    IP wraps each segment with source and destination IP addresses, a TTL/hop limit, a protocol number (6 = TCP) and, for IPv4, a header checksum and fragmentation fields; IPv6 has a fixed 40-byte header and pushes rarely used fields into extension headers. IP’s job is getting the packet to the right host across many networks; it neither knows nor cares what is inside. The link layer (Ethernet) adds source and destination MAC addresses and a frame check sequence — its problem is getting the frame across one physical segment to the next hop.

    On the wire the frame is bits. At each router the Ethernet header is stripped and a new one written with the next hop’s MAC — so MAC addresses change at every hop while the IP addresses stay constant end to end (unless NAT rewrites them). The IP TTL is decremented. On the destination host the process reverses: the NIC checks the frame, IP verifies the address and hands the payload to TCP by protocol number, TCP finds the socket by the 4-tuple and reassembles the byte stream, and the application read()s an HTTP message identical to what was written.

    Full interview question, with follow-ups and red flags →
  3. A switch receives a frame for a MAC it has never seen. What does it do?

    Show a strong answer

    Floods it out every port except the one it came from; learns the source MAC; once the destination replies it learns that too.

    Full interview question, with follow-ups and red flags →