Sub topic 13
MAC Spoofing, ARP Spoofing, and Basic Defenses
This chapter assumes you know how a switch builds its MAC table, how ARP maps an IPv4 address to a MAC address, and how an Ethernet frame is laid out. You should also be comfortable running ip commands on Linux. The chapter covers where these mechanisms can be abused and which defenses work at each layer.
Why a MAC address is a weak identity
A MAC address is a 6-byte field in the frame header. The sender fills it in, and nothing in Ethernet checks that the sender is entitled to use it. Wi-Fi works the same way, unless a security layer such as 802.1X or WPA authentication sits on top. Neither switches nor ARP authenticate anything by default.
The same trust gap shows up in three places:
- The source MAC in a frame can be set to any value.
- The switch learns whatever source MAC it sees and believes it.
- ARP hosts accept replies, and often unsolicited replies, without proof that the sender owns the IP address.
Each attack below uses one of these gaps.
MAC spoofing
MAC spoofing means a device transmits frames using a source MAC address other than the one burned into its hardware. Operating systems allow this because the address is just a configuration value in the driver.
On Linux, change the address of an interface you own like this:
sudo ip link set dev eth0 down
sudo ip link set dev eth0 address 02:00:5e:10:00:99
sudo ip link set dev eth0 up
ip link show dev eth0The address starts with 02, so the locally administered bit is set. That is the correct choice for a made-up address, as the earlier chapter on universal and local addresses explained. An attacker who wants to impersonate a specific device copies that device's real address instead.
What attackers gain
- Bypassing MAC filters. Some access points and switch ports allow only listed MAC addresses. An attacker who observes an allowed address on the air or the wire can copy it.
- Bypassing captive portals. A portal that remembers an authenticated client by MAC will let another device that copies that MAC through.
- Evading per-device limits. Hotel or ISP plans that bind service to one MAC can be sidestepped by cloning it.
- Impersonating a trusted host. Any rule that says "this MAC is the printer" or "this MAC is the gateway" trusts something the sender controls.
Limits of the technique
Two devices using the same MAC on one segment disrupt each other. The switch moves the MAC between ports every time either device transmits, so each device gets only part of its traffic. On Wi-Fi, an access point treats both as one client. Spoofing therefore works best when the real owner is offline. It is also visible: the MAC table flaps, and logs may show the same address on two ports.
There are legitimate uses too. Privacy features randomize the address (see the previous chapter), and administrators clone a MAC when replacing a router that an ISP has registered.
MAC flooding
A switch's MAC table has finite size. In a MAC flooding attack, the attacker sends frames with thousands of random source addresses. Once the table is full, the switch cannot learn new entries. Many switches then flood frames for unknown destinations out of every port in the VLAN, as a hub would, so the attacker can capture traffic that was never addressed to them.
The attack is noisy, because one port suddenly claims thousands of MAC addresses. Modern managed switches defend against it with port security, described below.
ARP spoofing
ARP has three properties that make it easy to abuse:
- It is stateless. A host will accept a reply even if it never sent a request.
- It is unauthenticated. Nothing ties the claimed IP to the sender.
- It overwrites. A newer reply replaces the existing cache entry on most systems.
ARP spoofing (also called ARP poisoning) exploits this. The attacker sends forged ARP replies that map someone else's IP address to the attacker's MAC address.
In a typical man-in-the-middle attack, the attacker poisons two hosts: the victim and the default gateway.
The attacker must keep sending these replies every few seconds, because real ARP traffic and cache expiry restore the correct entries. The attacker also has to enable IP forwarding. Without it the victim's traffic is dropped, which causes a denial of service rather than interception.
What ARP spoofing can and cannot do
- It works only inside one broadcast domain. ARP does not cross routers, so an attacker on another subnet cannot poison your cache.
- It lets the attacker read, drop, or alter unencrypted traffic. Traffic protected by TLS or SSH can still be dropped, and the attacker sees which hosts you contact. The content stays protected unless the user clicks through a certificate warning.
- On Wi-Fi with a shared password (WPA2-Personal), clients can often still poison each other. Access points need client isolation to stop that.
A related trick is the gratuitous ARP. A host announces its own IP-to-MAC mapping without being asked. Failover systems use it legitimately, so it cannot simply be blocked. An attacker uses the same message to overwrite other hosts' caches.
Signs on the host
You can see poisoning in the neighbor table you learned to read in the earlier chapter on inspecting MAC addresses:
- The gateway's MAC address changes without a hardware change.
- Two different IP addresses map to the same MAC address. This is normal for a router with several addresses or for proxy ARP, but unexpected for ordinary hosts.
- Entries flip repeatedly between two MAC addresses.
The script below polls the IPv4 neighbor table on Linux and prints an alert whenever the MAC for a known IP address changes. It is a teaching tool. It can raise false alarms when a NIC is replaced or a failover moves an address legitimately.
import subprocess
import time
def read_neighbors() -> dict:
out = subprocess.run(
["ip", "-4", "neigh", "show"],
capture_output=True, text=True, check=True,
).stdout
table = {}
for line in out.splitlines():
fields = line.split()
if "lladdr" in fields:
ip = fields[0]
mac = fields[fields.index("lladdr") + 1].lower()
table[ip] = mac
return table
def watch(interval: int = 5) -> None:
known = read_neighbors()
print(f"Watching {len(known)} neighbor entries every {interval}s")
while True:
time.sleep(interval)
current = read_neighbors()
for ip, mac in current.items():
old = known.get(ip)
if old is not None and old != mac:
print(f"ALERT: {ip} changed from {old} to {mac}")
known[ip] = mac
if __name__ == "__main__":
try:
watch()
except KeyboardInterrupt:
passTools such as arpwatch do the same job continuously and keep a database of observed pairs.
Defenses
No single control stops all of these attacks. Defenses work at the switch, the host, and above the link layer.
| Attack | Control | Where it runs | What it does |
|---|---|---|---|
| MAC flooding, MAC spoofing on a port | Port security | Switch | Limits how many MACs a port may learn, and can pin MACs to a port |
| ARP spoofing | Dynamic ARP Inspection (DAI) | Switch | Drops ARP packets whose IP-to-MAC pair does not match a trusted binding |
| Rogue DHCP, ARP spoofing | DHCP snooping | Switch | Allows DHCP replies only from trusted ports and builds the binding table that DAI uses |
| Rogue devices | 802.1X | Switch or access point | Requires authentication before a port or Wi-Fi association is usable |
| Poisoning between clients | Client isolation, VLANs, private VLANs | Switch or access point | Prevents hosts from reaching each other at layer 2 |
| Poisoning of critical entries | Static ARP entries | Host | Pins an IP-to-MAC mapping so replies cannot change it |
| Interception | TLS, SSH with host key checks, VPN | Application | Makes intercepted traffic unreadable and tampering detectable |
Switch configuration
The example below uses Cisco IOS syntax. Other vendors have equivalent features under different names, so check your switch's documentation.
ip dhcp snooping
ip dhcp snooping vlan 10
ip arp inspection vlan 10
interface GigabitEthernet0/1
description user port
switchport mode access
switchport access vlan 10
switchport port-security
switchport port-security maximum 2
switchport port-security mac-address sticky
switchport port-security violation restrict
interface GigabitEthernet0/24
description uplink to router
ip dhcp snooping trust
ip arp inspection trustThe mechanics are as follows:
- DHCP snooping watches DHCP exchanges on untrusted ports and records which IP address, MAC address, and port belong together.
- DAI checks every ARP packet on untrusted ports against that table. A forged reply claiming the gateway's IP from the wrong MAC is dropped and logged.
- Port security caps the MACs per port and can use sticky learning to remember them. With
restrict, the switch drops violating frames and logs them. Theshutdownmode disables the port.
Static ARP entries on a host
For one critical mapping, such as the default gateway, a host can refuse to learn it dynamically:
sudo ip neigh replace 192.168.1.1 lladdr 00:11:22:33:44:55 dev eth0 nud permanentThis protects a single machine, but it does not scale. Replace the gateway's NIC or fail over to a standby router and the entry silently breaks connectivity.
Gotchas
- MAC filtering is not authentication. Addresses are visible in every frame, so an allow-list gives only a weak speed bump. Use 802.1X or WPA-Enterprise instead.
- DAI depends on trustworthy bindings. Hosts with static IP addresses need static entries, or DAI will drop their ARP packets.
- Sticky port security can lock out legitimate changes. Replacing a laptop means clearing the learned address.
- Virtualization looks like spoofing. A hypervisor port legitimately carries many MACs, so limits of one will cause outages.
- IPv6 has the same weakness. Neighbor Discovery messages are unauthenticated too. Features such as RA Guard and ND inspection are the counterpart of DAI.
- Encryption is the backstop. Assume the local network can be poisoned and make sure that doing so yields nothing useful.
Exercise
A user reports that the gateway's MAC address in their ip neigh show output changed this morning, and the connection is slow. Name two checks that help decide whether this is ARP spoofing or a legitimate change.
Show answer
First, compare the new MAC with the one on the router's label or its own interface listing (and with the switch's MAC table for the router's port). If the new MAC belongs to another host or port, it is probably spoofing. Second, look for the same MAC appearing for other IP addresses in the neighbor table, or for the entry flipping back and forth between two MACs. Both indicate a host answering ARP for addresses it does not own. A planned router replacement or failover event in the change log would point to a legitimate change.
Exercise
Why does Dynamic ARP Inspection need DHCP snooping, and what must you configure for hosts that use static IP addresses?
Show answer
DAI needs a trusted record of which IP address and MAC address belong on which port. DHCP snooping builds that record by observing DHCP exchanges. A host with a static IP never takes part in DHCP, so it has no binding, and DAI would drop its ARP packets. You must add static bindings (or an ARP ACL) for those hosts, or mark their ports as trusted.
Exercise
An attacker on a different subnet wants to poison your ARP cache. Why can't they do it directly?
Show answer
ARP messages are sent in frames limited to one broadcast domain, and routers do not forward them. A host on another subnet cannot deliver ARP packets to your link, so poisoning requires a presence on the same LAN or VLAN, for example through a compromised device there.