Sub topic 5
The link layer: Ethernet frames and MAC addresses
This chapter assumes you know what the TCP/IP four-layer model is, that data is encapsulated as it moves down the stack, and that you can run commands in a terminal. It covers the lowest TCP/IP layer: how a frame is built, how MAC addresses work, how ARP finds them, and where the layer's responsibility ends.
What the link layer does
The link layer moves data between two devices that share one network segment, such as the same Ethernet switch or the same Wi-Fi network. It does not decide how a packet crosses the internet. That is the job of the internet layer above it.
The link layer has four main responsibilities:
- It defines how bits are put on a medium (copper, fiber, radio).
- It defines the frame, the unit of data that carries a payload to the next device.
- It identifies the sender and receiver on the local segment with hardware addresses.
- It detects damaged frames with a checksum.
In the OSI model, this one TCP/IP layer corresponds to two layers: Layer 1 (physical) and Layer 2 (data link). Ethernet, the most common wired technology, covers both. Wi-Fi (IEEE 802.11) also covers both, with a different frame format.
A link is a single hop. When your laptop talks to a server across the world, the packet crosses many links. Each link gets its own frame, with its own source and destination hardware addresses. The packet inside stays the same, apart from fields such as the IP time-to-live (TTL).
MAC addresses
A MAC address (Media Access Control address) is a 48-bit identifier for a network interface. It is written as six bytes in hexadecimal, such as 3c:22:fb:1a:90:7e. Some systems use dashes (Windows) or dotted groups (Cisco, 3c22.fb1a.907e).
The address has two parts:
- The first three bytes are the OUI (Organizationally Unique Identifier), assigned by the IEEE to a manufacturer.
- The last three bytes are assigned by that manufacturer to the individual interface.
Two bits in the first byte have special meaning:
| Bit in first byte | Value 0 | Value 1 |
|---|---|---|
| Least significant bit (I/G) | Unicast: one destination | Group: multicast or broadcast |
| Second least significant bit (U/L) | Universally administered (set by the manufacturer) | Locally administered (set by software) |
The broadcast address ff:ff:ff:ff:ff:ff has every bit set. Every device on the segment accepts a frame sent to it.
Some points about MAC addresses are easy to get wrong:
- A MAC address identifies an interface, not a computer. A laptop with Ethernet and Wi-Fi has two.
- A MAC address is only meaningful on the local segment. Routers rewrite the source and destination MAC address at every hop, so the MAC address of a remote server never appears in your frames.
- MAC addresses can be changed in software. Virtual machines, containers, and bridges use locally administered addresses. Modern phones and laptops often randomize the Wi-Fi MAC address to limit tracking. A MAC address is therefore not proof of identity.
You can view your own interface addresses with the ip command on Linux:
ip link showLook for the link/ether field on each interface. That field is the MAC address.
The Ethernet II frame
The most common frame format on IP networks is Ethernet II. Its fields appear on the wire in this order:
| Field | Size | Purpose |
|---|---|---|
| Destination MAC | 6 bytes | Next device on this link |
| Source MAC | 6 bytes | Sender on this link |
| EtherType | 2 bytes | Identifies the protocol of the payload |
| Payload | 46 to 1500 bytes | The data, usually an IP packet |
| FCS | 4 bytes | Frame Check Sequence, a CRC-32 checksum |
The header is 14 bytes (6 + 6 + 2). The FCS is a 4-byte trailer. Before the frame there is also a preamble and a start-of-frame delimiter, which let the receiver synchronize its clock. Capture tools do not show them.
EtherType
The EtherType field tells the receiver which protocol to hand the payload to. This is how the link layer connects to the layer above it. Common values:
| EtherType | Protocol |
|---|---|
| `0x0800` | IPv4 |
| `0x0806` | ARP |
| `0x86DD` | IPv6 |
| `0x8100` | 802.1Q VLAN tag follows |
If the value is 0x0800, the receiving system passes the payload to its IPv4 code. If the value is unknown, the frame is dropped.
Frame size and MTU
The payload limit of 1500 bytes is the MTU (Maximum Transmission Unit) of standard Ethernet. An IP packet larger than the MTU must be fragmented (IPv4) or must not be sent at all (IPv6, or IPv4 with the Don't Fragment bit set). The smallest payload is 46 bytes. Shorter payloads are padded so the whole frame is at least 64 bytes, which the original shared-medium Ethernet needed for collision detection.
Some networks use jumbo frames with an MTU of about 9000 bytes. All devices on the path must agree. A mismatch causes a classic fault: small packets work (ping, DNS) and large transfers stall.
The checksum
The sender computes a CRC-32 over the frame and stores it in the FCS. The receiver recomputes it. If the values differ, the frame is silently discarded. The link layer does not ask for a retransmission. Recovery is left to a higher layer such as TCP.
You often will not see the FCS in a capture, because the network card checks and strips it before the operating system sees the frame.
VLAN tags
An 802.1Q VLAN tag adds 4 bytes between the source MAC and the EtherType. It carries a 12-bit VLAN ID, so one physical switch can keep several logical networks separate. A tagged frame has the EtherType 0x8100 in the position where the real EtherType would normally be, followed by the tag and then the real EtherType. Frames with this tag can be up to 1522 bytes in total payload plus header, which is why you may see "baby giant" counters on switches.
How a switch uses MAC addresses
A switch is a link-layer device. It learns where each MAC address lives:
- A frame arrives on port 3 with source MAC
AA. The switch records "AA is reachable on port 3" in its MAC address table. - The switch looks up the destination MAC. If it is in the table, the switch forwards the frame only out of that port.
- If the destination is unknown, or it is broadcast, the switch floods the frame out of every port except the one it arrived on.
Table entries expire after a few minutes without traffic (commonly 300 seconds). A switch does not read IP addresses. A router, by contrast, works at the internet layer and connects separate link-layer segments.
ARP: finding the MAC address for an IP address
A host that wants to send an IPv4 packet to a neighbor knows the IP address but needs the MAC address to build the frame. ARP (Address Resolution Protocol) supplies it.
- The host sends an ARP request as a broadcast frame: "Who has 192.168.1.1? Tell 192.168.1.20."
- The owner of that IP address replies by unicast with its MAC address.
- The host stores the result in its ARP cache and sends the frame.
When the destination is on a different network, the host does not ARP for the remote IP address. It ARPs for the MAC address of its default gateway and sends the frame there. The IP destination stays remote while the MAC destination is the router.
On Linux you can inspect the cache and the neighbor state:
ip neigh showEntries move through states such as REACHABLE, STALE, and FAILED. A FAILED or INCOMPLETE entry for the gateway means ARP requests are getting no answer, which points to a fault at the link layer or on the local segment.
ARP has no authentication. Any host can send a forged reply, an attack called ARP spoofing. Switch features such as dynamic ARP inspection exist to counter it. IPv6 replaces ARP with Neighbor Discovery, which runs over ICMPv6. The next chapters and the caveats chapter return to this blurred boundary.
Seeing a frame in practice
Scapy builds a frame by stacking headers with the / operator. This example builds the same stack that a TCP SYN would use and prints each layer:
from scapy.all import Ether, IP, TCP
pkt = Ether() / IP(dst="192.0.2.10") / TCP(dport=80, flags="S")
pkt.show()The Ether section shows dst, src, and type. Scapy fills in the type as IPv4 (0x800) because an IP layer follows. The addresses are filled from your routing and ARP information when the packet is sent.
To see real frames, capture some traffic. The -e option prints the link-layer header:
sudo tcpdump -nn -e -v -c 5 'tcp port 80'Each line begins with the source and destination MAC addresses and the EtherType, followed by the IP and TCP details. The MAC addresses on a packet leaving your machine are your interface and your gateway, even if the IP destination is far away.
Common faults at this layer
| Symptom | Likely cause |
|---|---|
| No link light, interface shows `NO-CARRIER` | Cable, port, or transceiver problem |
| Interface up, `ip neigh` shows `FAILED` for the gateway | Wrong VLAN, switch port blocked, or gateway down |
| Small packets work, large transfers hang | MTU mismatch, such as jumbo frames on one side |
| Rising CRC or FCS error counters | Bad cable, duplex mismatch, or interference |
| Intermittent connectivity and duplicate IPs | Two hosts claiming one IP address, or MAC address conflicts |
You can read the error counters with:
ip -s link showSummary of key facts
- The link layer delivers frames across one hop, using MAC addresses.
- An Ethernet II frame has a 14-byte header, a payload of 46 to 1500 bytes, and a 4-byte FCS.
- EtherType selects the protocol of the payload.
- Switches forward by MAC address, while routers forward by IP address and rewrite MAC addresses at each hop.
- ARP maps an IPv4 address to a MAC address on the local segment.
Exercise
Your laptop (192.168.1.20) sends a packet to a web server at 203.0.113.5. The default gateway is 192.168.1.1. Which IP address and which MAC address appear as the destination in the first frame, and why does the destination MAC address change at the next hop?
Show answer
The IP destination is 203.0.113.5, the server. The destination MAC is the MAC address of the gateway 192.168.1.1, which the laptop learns with ARP. MAC addresses only identify the next device on the current link. The router removes the frame, reads the IP packet, and builds a new frame for the next link, with its own source MAC and the next hop's destination MAC. The IP addresses stay the same.
Exercise
A host can ping its neighbors by IP address on the same switch, but a large file copy to one neighbor stalls. Smaller transfers succeed. Which link-layer setting would you check first, and which command shows counters that could confirm a problem?
Show answer
Check the MTU on both hosts and on the switch ports, because a jumbo-frame mismatch lets small frames pass and drops large ones. Use ip link show to read the MTU, and ip -s link show to look for dropped or errored frames.