Ethernet, MAC addresses, switches and ARP
The fields of an Ethernet frame, minimum and maximum size, the structure of the 48-bit MAC address, the switch learning table, going from IP to MAC with ARP, and attacks on these such as ARP spoofing and MAC flooding.
On the previous page you saw who gets to talk on a shared channel. Today almost all wired LANs are Ethernet, and in modern Ethernet the hosts are connected one by one to a switch. This page covers the “address” side of the link layer: MAC addresses, how a switch learns, and how to get from an IP address to a MAC address (ARP). You will come back to this page many times in the security half of the course, because the protocols at this layer do no authentication.
Golden rules:
- An Ethernet frame is 64 to 1518 bytes (excluding the preamble). The payload is at least 46 bytes; if shorter, it is padded.
- A switch learns the source address and forwards by the destination address.
- An ARP request is broadcast, the reply is unicast.
- The IP address stays the same end to end, the MAC address changes on every link.
The Ethernet frame
+----------+---------+---------+------+--------------+-----+
| Preamble | Dst MAC | Src MAC | Type | Payload | FCS |
| 8 byte | 6 byte | 6 byte | 2 B | 46-1500 byte | 4 B |
+----------+---------+---------+------+--------------+-----+
| Field | Job |
|---|---|
| Preamble | 7 bytes 10101010 + 1 byte 10101011 (SFD). The receiver synchronizes its clock. Not counted in the frame size. |
| Dst / Src MAC | Destination and source interface addresses |
| Type (EtherType) | The protocol in the payload: 0x0800 IPv4, 0x0806 ARP, 0x86DD IPv6 |
| Payload | Usually an IP datagram. MTU = 1500 bytes |
| FCS | CRC-32 (week 3). A corrupted frame is silently discarded |
Ethernet is connectionless and unreliable: no handshake, no ACK. A frame that fails the CRC is discarded; noticing the loss is the job of the upper layer (TCP).
Sizes and padding
Minimum: bytes. This limit comes from the CSMA/CD minimum frame rule on the previous page (512 bits). For a 20-byte datagram, bytes of padding are added.
Maximum: bytes.
Efficiency
On the wire, every frame is preceded by an 8-byte preamble and followed by a 12-byte inter-frame gap.
Max payload (1500) : 1500 / (1518 + 8 + 12) = 1500 / 1538 = 97.53%
Min payload (46) : 46 / (64 + 8 + 12) = 46 / 84 = 54.76%
1518 B @100 Mbps : 12,144 bit / 10^8 = 121.44 us
MAC addresses
A MAC (LAN, physical) address is 48 bits and is written in hexadecimal: 3C:22:FB:10:A4:7E. It is written into the network card (NIC) at manufacture, but it can be changed in software (this is a security issue).
| Part | Bits | Meaning |
|---|---|---|
| OUI | first 24 | Prefix the IEEE assigns to the manufacturer |
| NIC-specific | last 24 | Serial number assigned by the manufacturer |
| I/G bit | lowest bit of the first byte | 0 unicast, 1 group (multicast) |
| U/L bit | second-lowest bit of the first byte | 0 global (from the manufacturer), 1 locally assigned |
first byte binary I/G U/L type
0x00 00000000 0 0 unicast, global
0x01 00000001 1 0 multicast (01:00:5E -> IPv4 multicast)
0x3A 00111010 0 1 unicast, locally assigned (random MAC)
0xFF 11111111 1 1 FF:FF:FF:FF:FF:FF = broadcast
MAC versus IP. A MAC address is a flat identity like a social security number and carries no location information; it stays the same whichever network the laptop joins. An IP address is hierarchical like a postal address and changes with the network you connect to. Routing is done with IP, and delivery on the last link with MAC.
TIP · random MAC. Phones connect to each Wi-Fi network with a different, locally assigned (U/L = 1) MAC. The goal is to make it harder to track a user across networks by MAC: a privacy measure.
Switch: the self-learning bridge
A hub is a physical-layer device that just copies bits to all ports; everyone connected stays in one collision domain. A switch is a link-layer device: it reads the frame and sends it only to the port that needs it. Hosts are unaware that the switch exists (transparent).
A switch has a forwarding table (CAM): MAC → port, time. Nobody fills the table by hand; the switch learns it itself (self-learning):
- A frame arrived from port . Write the source MAC into the table as “port ” (or refresh its timer).
- Look up the destination MAC in the table:
- If it is not there: send the frame to all ports except the one it arrived on (flooding).
- If it is there and the port is : discard (filtering), the destination is already on the same segment.
- If it is there and the port is another port : forward only to (forwarding).
- Entries are deleted if unused for a certain time (aging time, typically 300 s).
Worked example: a learning trace
Frame (source -> destination, in port) Decision Table after
A -> B, port 1 flood A=1
B -> A, port 2 port 1 A=1 B=2
C -> A, port 3 port 1 A=1 B=2 C=3
A -> C, port 1 port 3 A=1 B=2 C=3
D -> B, port 4 port 2 A=1 B=2 C=3 D=4
Note: B is not learned from the first frame. The switch learns only from the source address; B enters the table only when it sends a frame itself.
Collision domain and broadcast domain
| Device | Layer | Collision domain | Broadcast domain |
|---|---|---|---|
| Hub | 1 | All ports in one domain | One |
| Switch | 2 | Each port is a separate domain | One (broadcast goes to every port) |
| Router | 3 | Each interface separate | Each interface separate |
On a full-duplex switch connection (separate send and receive wires between host and switch) collisions never occur; CSMA/CD is effectively disabled.
A VLAN (virtual LAN) logically splits a single physical switch into several switches. Different VLANs are different broadcast domains; traffic between them must pass through a router. Organizations use them to separate guest, student and management networks: a security boundary.
ARP: from IP address to MAC address
A host wants to send an IP datagram to a host on the same subnet. It needs to write the destination MAC in the frame but knows only the IP. ARP (Address Resolution Protocol) does this mapping.
- The host looks in its ARP cache. If there is an entry, it uses it.
- If not, it broadcasts an ARP request: destination MAC
FF:FF:FF:FF:FF:FF, content “Who has 10.0.0.9? I’m 10.0.0.5, my MAC is this.” - Everyone on the LAN receives the request, and only 10.0.0.9 answers. The ARP reply goes directly to the asker as a unicast.
- The asker stores the mapping in its cache with a TTL (minutes).
ARP is plug-and-play: the administrator configures nothing.
Sending to another subnet
H1 (192.168.1.10/24) is writing to a web server (93.184.216.34). Since the destination is on a different subnet:
1. H1 checks its mask: the destination is not in my subnet -> send to the default gateway
2. H1 does ARP for the gateway IP (192.168.1.1) and learns the MAC of the router interface
3. Frame: dst MAC = router interface, dst IP = 93.184.216.34
4. The router strips the frame, looks at the IP, and builds a NEW frame for the next link
(new src MAC = router's outgoing interface, dst MAC = next node)
PITFALL · no ARP for the remote server. ARP works only within the same subnet; a broadcast does not cross a router. In an exam, the answer to “what is the dst MAC?” is the MAC of the gateway, not of the server. The addresses in the IP header, on the other hand, do not change along the way (except with NAT, week 5).
Link-layer attacks
Ethernet and ARP assume that everyone on the local network is honest. When that assumption collapses:
| Attack | How it works | Effect | Defense |
|---|---|---|---|
| ARP spoofing (poisoning) | The attacker uses unsolicited ARP replies to say “the gateway’s IP is at my MAC” | Traffic flows through the attacker: MITM | Dynamic ARP Inspection, static ARP, TLS |
| MAC flooding | Thousands of frames with fake source MACs fill the CAM table | The switch floods unknown destinations, and the attacker sees everything | Port security (MAC limit per port) |
| MAC spoofing | The card’s MAC is changed to someone else’s | MAC-based access control is bypassed | 802.1X authentication |
| Rogue DHCP | A fake DHCP server hands out itself as the gateway | MITM | DHCP snooping |
The common lesson: at the link layer, identity is claimed, not verified. That is why we rely on end-to-end encryption (week 12, TLS) for confidentiality and integrity.
Common mistakes
| Wrong idea | Correct |
|---|---|
| Ethernet minimum frame is 46 bytes | 46 bytes is the payload; the frame is 64 bytes. |
| The preamble is included in the frame size | The 64 and 1518 limits do not include the preamble. |
| A switch learns the destination address | It learns the source address and looks up the destination. |
| A frame for a destination not in the table is dropped | It is flooded. What is dropped is a destination on the same port. |
| The ARP reply is also broadcast | The reply is unicast. |
| ARP is done for the remote server’s MAC | It is done for the gateway. |
| A switch splits the broadcast domain | It doesn’t; a router or a VLAN does. |
| A MAC address cannot be changed | It is easily changed in software; it is not proof of identity. |
Test yourself
Exam-style questions. Solve them on paper first, then reveal the answer.
An IP datagram of only 20 bytes is sent inside an Ethernet frame. How many bytes of padding must be added to the payload?
Show answer
The Ethernet payload must be at least 46 bytes (frame 6 + 6 + 2 + 46 + 4 = 64 bytes). bytes of padding.
The receiver works out the padding from the total length field in the IP header and discards it.
Which Ethernet header field tells the receiver which network-layer protocol is carried in the payload?
- Preamble
- Destination MAC address
- EtherType
- FCS (CRC)
Show answer
EtherType: 0x0800 IPv4, 0x0806 ARP, 0x86DD IPv6. From this the receiver knows which protocol to hand the payload to (demultiplexing).
The FCS is for error detection, and the preamble is for clock synchronization.
How many bits are in a MAC address, and how many bits form the OUI (vendor prefix)?
- 32 and 16
- 48 and 24
- 48 and 16
- 64 and 32
Show answer
A MAC is 48 bits (6 bytes), for example 3C:22:FB:10:A4:7E. The first 24 bits are the OUI that the IEEE assigns to the manufacturer, and the last 24 bits are the manufacturer's serial number.
The address space is .
A frame's destination MAC address begins with the byte 0x01. What kind of address is it?
- Unicast, globally administered
- Unicast, locally administered
- Multicast (group) address
- Invalid address
Show answer
The lowest bit of the first byte is the I/G bit: 1 means a group (multicast/broadcast), 0 means a single interface (unicast).0x01 = 00000001, the lowest bit is 1: multicast. The second-lowest bit (U/L) is 0: global. The MAC equivalent of IPv4 multicast starts with 01:00:5E.
A switch with an empty table receives these frames in order (source, destination, incoming port): (A, B, 1), (B, A, 2), (C, A, 3), (A, C, 1). What does the switch do with each frame?
Show answer
For each frame the switch records the source address with the incoming port in the table, and looks up the destination in the table.
1) A→B: A=1 is learned, B is unknown → flood (all ports except 1).
2) B→A: B=2 is learned, A is in the table at port 1 → only port 1.
3) C→A: C=3 is learned, A is at port 1 → port 1.
4) A→C: C is at port 3 → port 3.
A switch receives a frame on port 4 whose destination MAC is already in the table, mapped to port 4. What does it do?
- Floods it to all ports
- Forwards it back out port 4
- Discards it (filtering)
- Sends an ARP request
Show answer
The destination is on the segment the frame came from. The destination has already seen the frame (same segment), so the switch has no need to forward it: it discards the frame. This is called filtering.
Host H1 (IP 10.0.0.5) wants to send an IP datagram to 10.0.0.9 on the same LAN but does not know its MAC address. Which statement about ARP is correct?
- The ARP request is unicast to 10.0.0.9 and the reply is broadcast
- The ARP request is broadcast to FF:FF:FF:FF:FF:FF and the reply is unicast to H1
- Both request and reply are broadcast
- ARP queries a DNS server for the MAC address
Show answer
Since H1 doesn't know the MAC, it broadcasts the question to everyone: "Who has 10.0.0.9? Tell 10.0.0.5."
Only 10.0.0.9 answers, and since the asker's MAC is in the request, it sends the reply directly to H1 (unicast). H1 stores the result in its ARP cache with a TTL.
Host H1 (subnet 192.168.1.0/24) sends a datagram to a web server at 93.184.216.34. In the Ethernet frame that leaves H1, what are the destination IP and the destination MAC?
- IP of the server; MAC of the server
- IP of the router; MAC of the router
- IP of the server; MAC of H1's default gateway (router interface)
- IP of the router; MAC of the server
Show answer
The destination is on a different subnet. H1 performs ARP not for the server but for the default gateway.
The IP header stays the same end to end (the destination is the server). The MAC header is rewritten on every link; on this link the destination is the MAC of the router interface.
Counting the 8-byte preamble and the 12-byte inter-frame gap as overhead, what fraction of the wire time carries payload for a maximum-size frame (1500-byte payload)?
Show answer
Frame: bytes. On the wire there are also an 8-byte preamble and a 12-byte gap..
With the minimum payload (46 bytes) it drops to .
How long does it take to transmit a maximum-size 1518-byte Ethernet frame (excluding preamble) at 100 Mbps?
Show answer
bits. s .
An attacker on the LAN keeps sending unsolicited ARP replies saying 'IP 192.168.1.1 is at the attacker's MAC'. What is the attack and a suitable defense?
- MAC flooding; increase the switch table size
- ARP spoofing (poisoning) enabling man-in-the-middle; Dynamic ARP Inspection or static ARP entries for the gateway
- DNS spoofing; use DNSSEC
- SYN flood; use SYN cookies
Show answer
ARP has no authentication, and hosts store even replies they never asked for in their cache. The victims send the traffic meant for the gateway to the attacker: a man-in-the-middle (MITM), who can eavesdrop or modify.
Defense: Dynamic ARP Inspection on the switch (drop ARP that doesn't match DHCP records), static ARP for critical addresses, and most importantly end-to-end encryption (TLS), because even if the attacker gets in the middle, they can't read it.
A network has 3 hubs, each with 4 hosts, all connected to one 3-port switch. How many collision domains and how many broadcast domains are there?
Show answer
A hub merges all its ports into a single collision domain. Each port of a switch is a separate collision domain: 3 ports → 3 collision domains (each hub with its hosts is one domain).
A switch forwards broadcasts to all ports, so everything is one broadcast domain. What splits a broadcast domain is a router (or a VLAN).
Verification: Frame sizes, padding, efficiency, transmission time, MAC bit fields (I/G, U/L) and the switch learning trace were computed with node (verify/SEN2008/04.mjs). The ARP and collision domain questions are conceptual; they were checked against the protocol definitions.