Day 3: Neighbors and Layer 2
Goal: You read the neighbor table and the switch table, find a duplicate IP address through its MAC address, understand why a fix only takes effect after the ARP cache catches up, and recognize a port in the wrong VLAN · Duration: approx. 70 min · Prerequisite: Day 2 including clean-up
Briefing
- Route found, gateway known – now the kernel needs a MAC address for the gateway (or for the target in the local network). It asks for it via ARP (“Who has 10.1.0.1?”) and remembers it in the neighbor table. The switch (in our case the bridge) in turn remembers which MAC address sits behind which port.
- Both tables are caches. Caches make faults non-deterministic: the same fault takes effect sometimes immediately, sometimes only after a minute, and a fix only takes effect once the cache notices it.
- Today: reading neighbor states,
arping, the switch table, a duplicate IP address and a port in the wrong VLAN – the fault from Day 1 where all the lights are green.
Drill 1: Read the Neighbor Table
# on netz
# Generate traffic so that entries are created
# >/dev/null throw away the output, only the effect counts
sudo ip netns exec client ping -c1 -W1 -q 10.2.0.10 >/dev/null
# Neighbor table of client and router
# neigh object neighbor table (ARP for IPv4, NDP for IPv6), without subcommand: show
sudo ip -n client neigh
sudo ip -n router neighExpected (MAC addresses and states differ):
10.1.0.1 dev eth0 lladdr ea:2b:4d:cf:88:59 DELAY
10.1.0.10 dev eth-a lladdr f6:bb:48:d1:4b:b9 REACHABLE
192.168.100.1 dev wan0 lladdr a6:44:c7:04:31:98 STALE
10.2.0.10 dev eth-b lladdr 4a:86:c1:de:45:34 DELAY
10.2.0.20 dev eth-b lladdr 36:4b:cb:79:ef:3a STALE
The client only knows its gateway, not web: for targets behind the
router it only needs the router’s MAC address. The router knows the
hosts at both sites. lladdr is the MAC address (link layer
address). The states:
| State | Meaning |
|---|---|
REACHABLE |
confirmed recently (reply seen), used without asking |
STALE |
older than approx. 30 seconds, still used, but checked with the next packet |
DELAY / PROBE |
currently being checked: first wait briefly, then ask specifically |
FAILED |
nobody answered – the target is not there on layer 2 (Day 2, Drill 3) |
INCOMPLETE |
request in progress, no reply yet |
So STALE is not an error, but the normal state of an
entry that has not been needed for a while. FAILED and
INCOMPLETE are the two you are looking for.
Which machine is behind a MAC address? Compare with the link level:
# on netz
# show eth0 only this interface (short form -br, see Day 1)
sudo ip -n web -br link show eth0
sudo ip -n db -br link show eth0Expected:
eth0@if31 UP 4a:86:c1:de:45:34 <BROADCAST,MULTICAST,UP,LOWER_UP>
eth0@if32 UP 36:4b:cb:79:ef:3a <BROADCAST,MULTICAST,UP,LOWER_UP>
4a:86:… is web, 36:4b:… is the db. Remember
both, you will need them in Drill 4.
Save your progress? Sign up for free
Drill 2: arping – Ask Layer 2 Directly
ping tests IP, arping tests one level
deeper: does anyone on this interface answer ARP for this address? This
also works when a firewall blocks ICMP.
# on netz
# ARP request from the client to its gateway
# -c2 two requests
# -I eth0 through this interface (ARP never leaves the local network)
sudo ip netns exec client arping -c2 -I eth0 10.1.0.1Expected:
ARPING 10.1.0.1
42 bytes from ea:2b:4d:cf:88:59 (10.1.0.1): index=0 time=115.987 usec
42 bytes from ea:2b:4d:cf:88:59 (10.1.0.1): index=1 time=16.972 usec
--- 10.1.0.1 statistics ---
2 packets transmitted, 2 packets received, 0% unanswered (0 extra)
rtt min/avg/max/std-dev = 0.017/0.066/0.116/0.050 ms
Watch out, there are two programs called arping with
different options. Ubuntu 24.04 installs Thomas Habets’ program with the
package arping (here version 2.24); Debian and RHEL often
install the one from iputils. The output above comes from
the Habets arping. The most dangerous mix-up:
| Option | Habets arping |
iputils arping |
|---|---|---|
-D |
show replies as ! and misses as . |
duplicate address detection (DAD) |
-d |
find duplicates: exit code 1 on replies from two MAC addresses | duplicate detection in the background (debug) |
-U |
send an unsolicited ARP announcement (gratuitous ARP) | the same |
arping --help 2>&1 | head -1 shows which one you
have. If you type in instructions written for the other program, you get
no error message, but a wrong result.
Save your progress? Sign up for free
Drill 3: The Switch Table
From every packet that comes in through a port, the bridge learns the sender MAC and remembers the port. That way it sends later packets only to this one port.
# on netz
# Learned MAC addresses on br-b
# fdb show forwarding database: MAC address → port
# br br-b only this bridge
# grep -v permanent hide the fixed entries of the bridge itself
bridge fdb show br br-b | grep -v permanentExpected:
3a:00:5b:1e:86:79 dev b-router master br-b
4a:86:c1:de:45:34 dev b-web master br-b
36:4b:cb:79:ef:3a dev b-db master br-b
Three hosts, three ports. On a physical switch the command is
show mac address-table; the question is the same: which
port is this MAC address on? When you have a suspicious MAC address from
the neighbor table, this table leads you to the cable.
Save your progress? Sign up for free
Drill 4: One IP Address, Two Hosts
A colleague sets up a second address on the db for a test service and
makes a typo: he uses 10.2.0.10, the address of web.
# on netz
# Inject the fault: web's address additionally on the db
# addr add 10.2.0.10/24 dev eth0 additional address on eth0
sudo ip -n db addr add 10.2.0.10/24 dev eth0
# The router forgets its entry (in everyday life: on its own after a few minutes)
# neigh flush dev eth-b delete all neighbor entries on eth-b
sudo ip -n router neigh flush dev eth-b
# Symptom
sudo ip netns exec client curl -sS -m3 http://10.2.0.10/Expected:
curl: (7) Failed to connect to 10.2.0.10 port 80 after 1 ms: Couldn't connect to server
Rejected after 1 ms: someone answered, but not a web server. The
service on web is running (systemctl is-active web-http
says active). Hypothesis: the packets arrive at a different
host.
# on netz
# Which MAC address does the router have for 10.2.0.10?
# neigh show 10.2.0.10 only this entry
sudo ip -n router neigh show 10.2.0.10
# Do several hosts answer? Habets arping with -d
# -d find duplicates, exit code 1 on two different MAC addresses
sudo ip netns exec router arping -d -c2 -I eth-b 10.2.0.10
echo "Exit-Code: $?"Expected:
10.2.0.10 dev eth-b lladdr 36:4b:cb:79:ef:3a REACHABLE
ARPING 10.2.0.10
42 bytes from 36:4b:cb:79:ef:3a (10.2.0.10): index=0 time=17.828 usec
42 bytes from 4a:86:c1:de:45:34 (10.2.0.10): index=1 time=62.096 usec
42 bytes from 36:4b:cb:79:ef:3a (10.2.0.10): index=2 time=16.049 usec
42 bytes from 4a:86:c1:de:45:34 (10.2.0.10): index=3 time=76.821 usec
--- 10.2.0.10 statistics ---
2 packets transmitted, 4 packets received, 0% unanswered (2 extra)
rtt min/avg/max/std-dev = 0.016/0.043/0.077/0.027 ms
Exit-Code: 1
Two requests, four replies (2 extra) from two MAC
addresses. According to Drill 1, 36:4b:… is the db. Whoever
answers ARP first ends up in the router’s cache – here the db, it is
slightly faster. Had the router still had its old entry for web,
everything would have kept working until the entry expired. That is
exactly what makes duplicate addresses so nasty: they get noticed by
chance.
And it gets even better: look again now.
# on netz
sudo ip -n router neigh show 10.2.0.10
sudo ip netns exec client curl -sS -m3 http://10.2.0.10/Expected:
10.2.0.10 dev eth-b lladdr 4a:86:c1:de:45:34 REACHABLE
hallo von web
Suddenly it works again. The replies to the router’s
arping overwrote its cache, and this time the last reply
came from web. Your measurement (temporarily) “fixed” the fault. This
happens all the time with layer 2 faults: if you are hunting a flapping
fault, first write down the state (ip neigh show) and only
then measure actively.
Cause found. Fix? That is the exercise.
Save your progress? Sign up for free
Exercise
First restore the fault state in which the router has the db in its cache:
# on netz
sudo ip -n router neigh flush dev eth-b
sudo ip netns exec client curl -sS -m3 http://10.2.0.10/Expected:
curl: (7) Failed to connect to 10.2.0.10 port 80 after 0 ms: Couldn't connect to server
Now remove the wrong address from the db. Check right afterwards with
curl whether the client reaches web again. Explain the
result with a command from Drill 1 and get the router to use the right
host without changing anything on the router.
Solution
# on netz
# Fix, part 1: remove the wrong address
# addr del 10.2.0.10/24 dev eth0 remove this address from eth0
sudo ip -n db addr del 10.2.0.10/24 dev eth0
# Check immediately
sudo ip netns exec client curl -sS -m3 http://10.2.0.10/
sudo ip -n router neigh show 10.2.0.10Expected:
curl: (28) Connection timed out after 3002 milliseconds
10.2.0.10 dev eth-b lladdr 36:4b:cb:79:ef:3a REACHABLE
“Rejected” has turned into “timeout” – worse, not better. The router
keeps sending the packets to the db’s MAC address. The db no longer has
the address and silently drops them. The entry only becomes invalid when
the check from STALE/DELAY fails, and
depending on traffic that can take a minute. During that time “the fix
does not help”, and someone might undo it.
The right host can announce itself: with an unsolicited ARP announcement (gratuitous ARP). Everyone in the network who already has an entry for the address updates it.
# on netz
# Fix, part 2: web announces itself with its MAC address
# -U unsolicited ARP announcement (gratuitous ARP)
# -c1 one announcement
# -I eth0 via eth0 of web
# -S 10.2.0.10 sender address in the announcement
# 10.2.0.10 target address: with gratuitous ARP the same as the sender
# >/dev/null throw away the output (“Timeout”): nobody answers an announcement
sudo ip netns exec web arping -U -c1 -I eth0 -S 10.2.0.10 10.2.0.10 >/dev/null
# Proof
sudo ip -n router neigh show 10.2.0.10
sudo ip netns exec client curl -sS -m3 http://10.2.0.10/Expected:
10.2.0.10 dev eth-b lladdr 4a:86:c1:de:45:34 STALE
hallo von web
The MAC address in the router is now 4a:86:…, the one of
web. keepalived, Pacemaker and MetalLB in layer 2 mode use exactly this
mechanism: when a virtual IP moves to another host, the new owner sends
gratuitous ARPs immediately, otherwise everyone would keep talking to
the old host for another minute. On a router where you have permissions,
ip neigh flush 10.2.0.10 would also work – but you can
rarely flush your customers’ routers yourself.
Save your progress? Sign up for free
Challenge
Inject the fault:
# on netz
# Inject the fault: br-b becomes a VLAN-aware switch, b-db ends up in VLAN 20
# type bridge vlan_filtering 1 turn on the bridge's VLAN filter
sudo ip link set br-b type bridge vlan_filtering 1
# vlan add dev b-db vid 20 pvid untagged port b-db: VLAN 20, default VLAN for untagged packets, egress without tag
sudo bridge vlan add dev b-db vid 20 pvid untagged
# vlan del dev b-db vid 1 remove VLAN 1 from this port
sudo bridge vlan del dev b-db vid 1web no longer reaches the db. Use the commands from Day 1 to show
that link, carrier and bridge membership are fine, and then find the
cause with a new command. Fix it so that b-db is in the
same VLAN as the other ports again.
Solution
# on netz
# Symptom
sudo ip netns exec web ping -c2 -W1 -q 10.2.0.20 | tail -2
# Day 1: all green
sudo ip -n db -br link show eth0
ip -br link show master br-b | grep -c b-db
# VLANs per port
# vlan show which VLANs are allowed on which port; PVID = VLAN for untagged packets
bridge vlan showExpected (shortened):
2 packets transmitted, 0 received, 100% packet loss, time 1006ms
eth0@if32 UP 36:4b:cb:79:ef:3a <BROADCAST,MULTICAST,UP,LOWER_UP>
1
port vlan-id
…
b-router 1 PVID Egress Untagged
b-web 1 PVID Egress Untagged
b-db 20 PVID Egress Untagged
…
All other ports are in VLAN 1, b-db is in VLAN 20. The
bridge forwards nothing between different VLANs – just like a switch on
which the server’s port was configured into the wrong VLAN.
Egress Untagged means: packets leave the port without a
VLAN tag, so the db itself notices nothing.
# on netz
# Fix: b-db back into VLAN 1, VLAN 20 gone
sudo bridge vlan add dev b-db vid 1 pvid untagged
sudo bridge vlan del dev b-db vid 20
# Proof
# dev b-db only this port
bridge vlan show dev b-db
sudo ip netns exec web ping -c2 -W1 -q 10.2.0.20 | tail -2Expected:
port vlan-id
b-db 1 PVID Egress Untagged
2 packets transmitted, 2 received, 0% packet loss, time 1025ms
rtt min/avg/max/mdev = 0.119/0.126/0.134/0.007 ms
Save your progress? Sign up for free
Checkpoint
# on netz
# 10.2.0.10 exists exactly once
sudo ip netns exec router arping -d -c2 -I eth-b 10.2.0.10 >/dev/null; echo "Duplikat-Exit: $?"
# Router knows web under web's MAC address
sudo ip -n router neigh show 10.2.0.10 | grep -c "$(sudo ip -n web link show eth0 | awk '/ether/{print $2}')"
# all ports of br-b in VLAN 1
bridge vlan show | grep -c '^b-.* 1 PVID'
# web answers
sudo ip netns exec client curl -s -m3 http://10.2.0.10/$( … ) inserts the output of a command.
awk '/ether/{print $2}' takes the second field, the MAC
address, from the line containing ether.
Expected:
Duplikat-Exit: 0
1
3
hallo von web
Clean up
# on netz
# VLAN filter off again, as on Day 0
sudo ip link set br-b type bridge vlan_filtering 0
# grep -o print only the matching part of the line
ip -d link show br-b | grep -o 'vlan_filtering [0-9]'Expected:
vlan_filtering 0
Interview note
“A service is sometimes reachable, sometimes not, and after a router
restart it works again.” That sounds like a duplicate IP address or a
stale ARP entry. Measure: ip neigh show <ip> on the
gateway, map the MAC address to a host with ip link or the
switch table, arping -d (Habets) for duplicates. If you can
explain why removing the duplicate address first leads to a timeout and
how gratuitous ARP solves that, you have understood how VIP failover
works with keepalived and MetalLB.
Enterprise note
Duplicate addresses almost always arise outside IP address management: a static address from an old wiki, a cloned VM with a fixed configuration, a test device in the server network. The remedy is an IPAM source of truth (NetBox, phpIPAM) plus a check before assignment. Kubernetes nodes with MetalLB in L2 mode should show the number of gratuitous ARPs and changes of a service IP’s MAC address in monitoring; switches can use Dynamic ARP Inspection and DHCP snooping to prevent a wrong host from claiming other hosts’ addresses.