Sub topic 10
Looking at MAC Addresses and Neighbor Tables on Your Machine
This chapter assumes you know how a MAC address is laid out (OUI plus device part, with the group and locally administered bits) and that ARP maps IPv4 addresses to MAC addresses. You will use standard Linux tools to read your own interface addresses, view the neighbor table, and decode what you find.
Reading interface MAC addresses
The ip link show command lists every network interface. The MAC address appears on the link/ether line.
# Show the MAC address (link/ether) of every interface
ip link show
# Show the IPv4/IPv6 neighbor table (IP to MAC mappings)
ip neigh showTypical output for ip link show looks like this:
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP mode DEFAULT
link/ether 02:00:5e:10:00:01 brd ff:ff:ff:ff:ff:ffThree details matter here:
link/etheris the interface's own MAC address.brd ff:ff:ff:ff:ff:ffis the broadcast address used on this link.- The loopback interface
loshowslink/loopback 00:00:00:00:00:00. It has no real MAC because its traffic never leaves the host.
Reading the neighbor table
ip neigh show prints the IP-to-MAC entries your host has learned through ARP (IPv4) or Neighbor Discovery (IPv6). Example output:
192.168.1.1 dev eth0 lladdr 02:00:5e:10:00:aa REACHABLE
192.168.1.20 dev eth0 lladdr 02:00:5e:10:00:bb STALE
fe80::1 dev eth0 lladdr 02:00:5e:10:00:aa router REACHABLE
192.168.1.30 dev eth0 FAILEDEach line holds an IP address, the interface, the learned MAC (lladdr), and a state. The common states are:
| State | Meaning |
|---|---|
| REACHABLE | The entry was confirmed recently. |
| STALE | The entry is old. It is still used, but the kernel will re-check it when traffic is sent. |
| DELAY / PROBE | The kernel is verifying the entry with a unicast probe. |
| INCOMPLETE | A request was sent and no reply has arrived yet. |
| FAILED | Resolution gave up. No host answered. |
The table only holds hosts you have talked to recently. An empty or short table is normal. Entries expire after a few minutes without use.
Watching an entry appear
You can see ARP work by clearing an entry and then generating traffic to that host. Replace the address with a real neighbor on your network.
# Remove a cached entry (requires root)
sudo ip neigh del 192.168.1.1 dev eth0
# Send one ping so the kernel has to resolve the address again
ping -c 1 192.168.1.1
# The entry is back, freshly learned
ip neigh show 192.168.1.1Decoding a MAC address with code
Reading raw addresses by eye is slow. This function splits an address into its parts and tests the group and locally administered bits.
def describe_mac(mac: str) -> dict:
parts = mac.replace('-', ':').split(':')
if len(parts) != 6:
raise ValueError('a MAC address has 6 octets')
octets = bytes(int(p, 16) for p in parts)
first = octets[0]
return {
'oui': ':'.join(f'{b:02x}' for b in octets[:3]),
'device_part': ':'.join(f'{b:02x}' for b in octets[3:]),
'is_group': bool(first & 0x01),
'is_locally_administered': bool(first & 0x02),
'is_broadcast': octets == b'\xff' * 6,
}
print(describe_mac('02:00:5e:10:00:01'))
print(describe_mac('ff:ff:ff:ff:ff:ff'))For 02:00:5e:10:00:01, the first octet is 0x02. The group bit is 0, so it is a unicast address. The locally administered bit is 1, so the address was assigned by software or an administrator and does not identify a manufacturer. Looking up its OUI in a vendor database would give no useful answer. For ff:ff:ff:ff:ff:ff, both bits are set and the function reports a broadcast.
Common errors and gotchas
- Empty neighbor table. The host has not recently contacted anyone on the link. Ping the gateway, then check again.
- A FAILED entry. The IP address is on your subnet but nobody answered the ARP request. Check for a wrong address, a powered-off host, or a VLAN mismatch.
- Remote hosts never appear. The table lists only hosts on your own link. For a server on another network, you see the MAC of your gateway, not the server.
- Same MAC on several IPs. This is usually normal: a router answers for many addresses, and a virtualization host can too. It can also point to ARP spoofing, covered in a later chapter.
- MAC changes after reboot or reconnect. Many systems use randomized or per-network addresses on Wi-Fi. Check the locally administered bit before assuming something is wrong.
- Older tools.
ifconfigandarp -agive similar data but are deprecated on many Linux distributions. On macOS and Windows, useifconfigorarp -a, andipconfig /allon Windows.
Exercise
Your neighbor table shows 10.0.0.5 dev eth0 FAILED, and ping 10.0.0.5 reports "Destination Host Unreachable". Is the host on a different network? What would you check first?
Show answer
No. The kernel only sends ARP requests for addresses in a subnet attached to the interface, so the address is on your local network, but nothing answered the ARP request. Check that the host is powered on and connected, that the IP address is correct, and that both machines are in the same VLAN and subnet. Running ip addr show confirms your own subnet and mask.
Exercise
What do describe_mac('02:00:5e:10:00:01') and describe_mac('01:00:5e:00:00:fb') report for is_group and is_locally_administered?
Show answer
The first address has 0x02 as its first octet, so is_group is False and is_locally_administered is True. The second has 0x01, so is_group is True (a multicast address) and is_locally_administered is False.