basforge

Search titles, text and the “If it doesn’t work” cases.

    RU

    Local networks: MAC, switches, ARP, and VLANs

    Inside a local network, hosts deliver frames using 48-bit MAC addresses rather than IPs. Learn how the ip neigh table tracks peers, how switches learn MAC addresses, how broadcast ARP resolves IPs, and how 802.1Q VLAN tags split one cable into isolated networks.

    New hereMAC, Ethernet, ARP and VLAN

    What you’ll get

    Inspect your interface MAC addresses, view the local neighbor table, and capture a live ARP request with its Ethernet header:

    ip -br link show eth0
    # eth0             UP             bc:24:11:af:27:2b <BROADCAST,MULTICAST,UP,LOWER_UP>
    
    ip neigh show dev eth0
    # 10.0.0.1 lladdr e2:a1:e8:41:67:85 REACHABLE
    # 10.0.0.12 FAILED
    
    sudo tcpdump -nn -e -i eth0 arp

    Before sending the first IP packet to a local peer, the kernel needs its MAC address. It broadcasts an ARP frame that shows every L2 field:

    tcpdump -nn -e -i eth0 arp · Pick a segment
    On virtual and outbound interfaces, tcpdump often prints ARP frames as 42 bytes: the NIC adds padding up to Ethernet’s 60-byte minimum (+ 4-byte FCS) just before putting it on the wire.

    MAC addresses: structure and why they stop at the router

    Every Ethernet NIC and virtual interface has a MAC address — 48 bits written as six colon-separated hex pairs, such as bc:24:11:af:27:2b.

    bc : 24 : 11  :  af : 27 : 2b
    ├─── OUI ───┤    ├─ NIC ID ──┤
    vendor prefix     unique part
    (24 bits)         (24 bits)

    The first three bytes (OUI) identify the hardware vendor or hypervisor — for example bc:24:11 belongs to Proxmox and 52:54:00 to QEMU/KVM. The vendor assigns the last three bytes per interface. The first byte carries two flag bits that reveal an address’s origin and type at a glance:

    First-byte bit Value 0 Value 1 Example
    Least significant bit (0x01, I/G) Unicast — one NIC Multicast / Broadcast — a group or all hosts ff:ff:ff:ff:ff:ff (broadcast), 33:33:… (IPv6 multicast)
    Second bit (0x02, U/L) Factory address from IEEE registry Locally administered — set manually, by a hypervisor, or by Wi-Fi randomization 02:00:00:…, e2:a1:e8:… (second hex digit 2, 6, a, or e for unicast)

    MAC addresses are flat: unlike IPs, they encode no hierarchy of networks or providers. A switch could never hold a table of billions of internet devices, so MAC addresses work only within one L2 segment (broadcast domain). When a packet reaches a router, the router strips the Ethernet header and wraps the IP packet in a new frame with the next hop’s MAC (Packets and encapsulation).

    How a switch works: learning, forwarding, and flooding

    A standard L2 switch (and a Linux software bridge like vmbr0 or docker0) never looks at IP addresses. Inside, it keeps a MAC table (FDB / CAM table) mapping each MAC address to the port where it was seen and its VLAN ID.

      web1 (02:00:00:00:00:0a) ── veth-a ─┐
      db1  (02:00:00:00:00:0b) ── veth-b ─┼─ switch / bridge lab-br0
      app1 (02:00:00:00:00:0c) ── veth-c ─┘

    On a Linux bridge, bridge fdb show prints this table:

    bridge fdb show br lab-br0 | grep -v permanent
    # 02:00:00:00:00:0a dev veth-a vlan 1 master lab-br0
    # 02:00:00:00:00:0b dev veth-b vlan 1 master lab-br0
    # 02:00:00:00:00:0c dev veth-c vlan 1 master lab-br0

    Three rules describe all switch behavior:

    • Learning. Whenever any frame with Src MAC = 02:00:00:00:00:0a enters veth-a, the switch records that port mapping and resets its aging timer (300 s by default on Linux).
    • Forwarding. If Dst MAC is already in the table (for example 02:00:00:00:00:0b on veth-b), the frame leaves only out of that single port. No other port receives it.
    • Flooding. If Dst MAC is broadcast (ff:ff:ff:ff:ff:ff) or unknown, the switch sends a copy to every port in the same VLAN except the ingress port.

    That second rule has a direct debugging consequence: running tcpdump on app1 will not show traffic between web1 and db1 because the switch never sends it there. app1 sees only its own frames and broadcasts like ARP. To inspect another port on a managed switch, enable port mirroring (SPAN).

    Connecting two switches with two cables without loop protection (STP) sends broadcast frames spinning in circles, saturating the link in fractions of a second (a broadcast storm).

    ARP: turning an IP into a MAC

    When 10.0.10.10 runs ping 10.0.10.20, the subnet mask tells the kernel that the target is on the same LAN. Building the Ethernet header still requires Dst MAC. If it is missing from the neighbor table (ip neigh), the kernel queues the IP packet for milliseconds and runs ARP:

    sudo tcpdump -nn -e -i veth-a -c 4 'arp or icmp'
    # 18:17:18.307640 02:00:00:00:00:0a > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Request who-has 10.0.10.20 tell 10.0.10.10, length 28
    # 18:17:18.307682 02:00:00:00:00:0b > 02:00:00:00:00:0a, ethertype ARP (0x0806), length 42: Reply 10.0.10.20 is-at 02:00:00:00:00:0b, length 28
    # 18:17:18.307686 02:00:00:00:00:0a > 02:00:00:00:00:0b, ethertype IPv4 (0x0800), length 98: 10.0.10.10 > 10.0.10.20: ICMP echo request, id 3011, seq 1, length 64
    # 18:17:18.307710 02:00:00:00:00:0b > 02:00:00:00:00:0a, ethertype IPv4 (0x0800), length 98: 10.0.10.20 > 10.0.10.10: ICMP echo reply, id 3011, seq 1, length 64

    The request goes to everyone (ff:ff:ff:ff:ff:ff), while Reply … is-at comes back unicast (02:00:00:00:00:0b > 02:00:00:00:00:0a). Both hosts now know each other’s MAC, and microseconds later the ICMP packet goes out.

    ARP behaves differently depending on where the target sits — switch scenarios below to see who answers and what shows up in tcpdump and ip neigh:

    1. 10.0.10.10✓ Request (broadcast)
    2. L2 switch✓ flooded in VLAN
    3. 10.0.10.20✓ Reply (unicast)
    4. ip neigh✓ REACHABLE
    18:17:18.307640 02:00:00:00:00:0a > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Request who-has 10.0.10.20 tell 10.0.10.10, length 28
    18:17:18.307682 02:00:00:00:00:0b > 02:00:00:00:00:0a, ethertype ARP (0x0806), length 42: Reply 10.0.10.20 is-at 02:00:00:00:00:0b, length 28
    What happened

    The target is in the same /24 subnet. The host learned the peer’s MAC in one round trip and cached it in the kernel.

    Check with

    ip neigh show 10.0.10.20

    1. 10.0.0.11✓ asks for gw 10.0.0.1
    2. Gateway 10.0.0.1✓ Reply is-at e2:a1:…
    3. L2 frame✓ gateway Dst MAC
    4. 203.0.113.10✓ Dst IP untouched
    18:16:39.631100 bc:24:11:af:27:2b > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Request who-has 10.0.0.1 tell 10.0.0.11, length 28
    18:16:39.631220 e2:a1:e8:41:67:85 > bc:24:11:af:27:2b, ethertype ARP (0x0806), length 42: Reply 10.0.0.1 is-at e2:a1:e8:41:67:85, length 28
    18:16:39.632013 bc:24:11:af:27:2b > e2:a1:e8:41:67:85, ethertype IPv4 (0x0800), length 74: 10.0.0.11.45232 > 203.0.113.10.443: Flags [S]
    What happened

    For a remote IP, the kernel never sends ARP for 203.0.113.10 — it resolves the gateway 10.0.0.1 and addresses the Ethernet frame to that gateway.

    Check with

    ip route get 203.0.113.10 and ip neigh show 10.0.0.1

    1. 10.0.0.11✓ Request (×3)
    2. L2 switch✓ flooded in VLAN
    3. 10.0.0.99✕ silent / powered off
    4. ip neigh✕ INCOMPLETE / FAILED
    18:16:40.668128 bc:24:11:af:27:2b > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Request who-has 10.0.0.99 tell 10.0.0.11, length 28
    18:16:41.698333 bc:24:11:af:27:2b > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Request who-has 10.0.0.99 tell 10.0.0.11, length 28
    Cause

    The host retries who-has once per second (three tries by default). With no reply, the entry turns FAILED and ping prints Destination Host Unreachable.

    Check with

    ip neigh show dev eth0 and sudo tcpdump -nn -e -i eth0 arp

    1. Client✓ sends to old MAC
    2. Old NIC✕ gone from LAN
    3. ip neigh✕ stale REACHABLE
    # Old cache entry on client:
    10.0.10.20 dev eth0 lladdr 02:00:00:00:00:0b REACHABLE
    # After flush or Gratuitous ARP from the new host:
    10.0.10.20 dev eth0 lladdr 02:00:00:00:00:99 REACHABLE
    Cause

    After a NIC swap or floating-IP failover (VRRP/Keepalived), peers keep sending frames to the old MAC for 15–45 s unless the new host sends Gratuitous ARP.

    Check with

    sudo ip neigh flush to 10.0.10.20

    Neighbor table states in ip neigh

    Linux tracks the freshness of every neighbor entry with a state machine. Base timers live under sysctl net.ipv4.neigh.default.* (base_reachable_time_ms = 30000, delay_first_probe_time = 5, gc_stale_time = 60):

    State Meaning What the kernel does next
    REACHABLE Peer recently replied to ARP or confirmed reachability via TCP Sends frames without re-probing for 15–45 s (randomized 0.5×–1.5× of 30 s)
    STALE Timer expired, entry still cached Waits for cleanup if idle; on the next packet, reuses the old MAC and moves to DELAY
    DELAY Packet sent via a STALE entry, awaiting confirmation If upper layers (such as TCP ACK) do not confirm within 5 s, moves to PROBE
    PROBE Re-verifying the cached MAC Sends unicast ARP requests straight to the known MAC; no reply moves it to FAILED
    INCOMPLETE Broadcast who-has sent, no reply yet Retries the request; once retries exhaust, switches to FAILED
    FAILED Peer did not answer ARP Reports host unreachable; starts a fresh lookup on the next attempt
    PERMANENT Static entry (ip neigh replace … nud permanent) Never ages out and never triggers ARP probes

    Seeing STALE in ip neigh is normal for a peer you have not talked to recently — not a fault. INCOMPLETE and FAILED are the warning signs.

    Who does ARP ask when reaching the internet?
    # On web1: eth0 = 10.0.0.11/24, default gateway = 10.0.0.1
    # ip neigh table is empty
    ping -c 1 203.0.113.10
    Who does ARP ask when reaching the internet?
    Answer:
    Request who-has 10.0.0.1 tell 10.0.0.11, length 28

    ARP operates only inside one L2 segment and never crosses routers. The kernel checks the routing table, sees that 203.0.113.10 is outside 10.0.0.0/24, and uses ARP only to find the MAC of the next-hop gateway 10.0.0.1.

    VLAN (802.1Q): multiple networks over one cable

    When home computers, guest Wi-Fi, and cameras share one switch yet need separate broadcast domains and firewall isolation, you do not need separate cables and switches for each network. IEEE 802.1Q inserts a 4-byte tag into the Ethernet header carrying a VLAN ID (1–4094; 0 and 4095 are reserved).

    Ethernet frame with 802.1Q tag (VLAN 20) · 1522 bytes on the wirePick a layer
    Destination and source MACChanges at every router
    Dst MAC · 6 Bff:ff:ff:ff:ff:ffFlooded only to ports belonging to VLAN 20
    Src MAC · 6 B02:00:00:00:00:0aSwitch learns the (MAC, VLAN 20) pair on the ingress port
    802.1Q tag sits right before EtherTypeAdded and stripped by switch ports
    TPID · 2 B0x8100Tells the NIC and switch that the next 2 bytes are an 802.1Q tag
    PCP · 3 bits0 (p 0)Class-of-service priority (L2 QoS, 0 to 7)
    DEI · 1 bit0Whether the frame may be dropped under congestion
    VID · 12 bits20 (vlan 20)VLAN ID 1–4094; the switch keeps a separate MAC table per VID
    Original EtherType shifts 4 bytes rightRead by the receiver
    EtherType · 2 B0x0806 / 0x0800Followed by the usual ARP (0x0806), IPv4 (0x0800), or IPv6 (0x86DD) code
    Payload and checksumMTU 1500 preserved

    Modern NICs and switches expand max frame size from 1518 to 1522 bytes to fit the 4-byte 802.1Q tag, keeping MTU 1500 intact inside VLANs (Packets and encapsulation).

    Access, Trunk, and Native VLAN (PVID)

    On a managed switch, router, or Linux bridge, every port runs in one of three modes:

    Port mode Connected device Frames on the wire What the switch port does
    Access PC, printer, camera, VLAN-unaware server Untagged Tags ingress frames with PVID (e.g. VLAN 30) and strips the tag on egress. The endpoint stays unaware of VLANs
    Trunk Another switch, router, Wi-Fi AP, Proxmox host Tagged (802.1Q) Carries frames for multiple allowed VLANs while preserving their IDs
    Hybrid (Trunk + PVID) AP with untagged management and guests on VLAN 20 One untagged VLAN (PVID), rest tagged Places untagged ingress frames into PVID (often VLAN 1) and forwards tagged frames by VID

    On a Linux bridge with filtering enabled (vlan_filtering 1), bridge vlan show makes the difference between a hybrid trunk and an access port obvious:

    bridge vlan show
    # port              vlan-id
    # veth-a            1 PVID Egress Untagged
    #                   20
    # veth-c            30 PVID Egress Untagged

    Port veth-a accepts untagged traffic into VLAN 1 and passes tagged VLAN 20 frames. Port veth-c is a pure access port in VLAN 30: untagged ingress frames get tagged as 30, and tag 30 is stripped before frames leave veth-c (Egress Untagged).

    To give a Linux host (or a server behind a trunk) access to VLAN 20, create a subinterface eth0.20 on top of the physical NIC:

    sudo ip link add link eth0 name eth0.20 type vlan id 20
    sudo ip addr add 10.0.20.10/24 dev eth0.20
    sudo ip link set eth0.20 up

    Running tcpdump -nn -e on the parent port shows the 802.1Q (0x8100) tag, vlan 20, and the exact 4-byte frame increase (ARP grows from 42 to 46 bytes, ICMP ping from 98 to 102):

    sudo tcpdump -nn -e -i veth-a -c 3 'vlan 20'
    # 18:17:19.090691 02:00:00:00:00:0a > ff:ff:ff:ff:ff:ff, ethertype 802.1Q (0x8100), length 46: vlan 20, p 0, ethertype ARP (0x0806), Request who-has 10.0.20.20 tell 10.0.20.10, length 28
    # 18:17:19.090720 02:00:00:00:00:0b > 02:00:00:00:00:0a, ethertype 802.1Q (0x8100), length 46: vlan 20, p 0, ethertype ARP (0x0806), Reply 10.0.20.20 is-at 02:00:00:00:00:0b, length 28
    # 18:17:19.090723 02:00:00:00:00:0a > 02:00:00:00:00:0b, ethertype 802.1Q (0x8100), length 102: vlan 20, p 0, ethertype IPv4 (0x0800), 10.0.20.10 > 10.0.20.20: ICMP echo request, id 3047, seq 1, length 64

    The switch’s MAC table is also isolated per VLAN: the same MAC in VLAN 1 and VLAN 20 gets separate entries, and broadcast ARP in VLAN 20 never leaks into VLAN 30 ports. Traffic between different VLANs must pass through an L3 router where firewall rules apply. Home-router VLAN setup is covered in Wired on MikroTik, and hypervisor bridge VLANs in Proxmox networking.

    Will ping succeed between VLAN 20 and VLAN 30 using IPs from the same subnet?
    lab-a (10.0.20.10/24, VLAN 20) ──► switch (no router) ──► lab-c (10.0.20.30/24, VLAN 30)
    Will ping succeed between VLAN 20 and VLAN 30 using IPs from the same subnet?
    Answer:
    2 packets transmitted, 0 received, 100% packet loss · 10.0.20.30 INCOMPLETE

    VLANs partition the network at L2 — below IP. Even if both hosts get addresses in 10.0.20.0/24, broadcast ARP tagged vlan 20 never exits a vlan 30 port. Without a router bridging the two VLANs, the hosts cannot see each other.

    If it doesn’t work

    ip neigh shows a peer as INCOMPLETE or FAILED, and ping loses 100% of packets

    Cause
    The host sent a broadcast ARP who-has request and got no answer on this L2 segment: the peer is off, unplugged, given the wrong IP, or placed in a different VLAN.
    Fix
    Check link status (ip -br link) and watch traffic with sudo tcpdump -nn -e -i eth0 arp: if only Request who-has appears with no Reply, inspect the peer, switch port, or VLAN tags.

    A device swapped NICs or an IP failed over to a standby server, and traffic drops for half a minute

    Cause
    The kernel keeps the old IP-to-MAC mapping in the neighbor table (REACHABLE lasts 15–45 s) until it receives Gratuitous ARP or re-probes the peer.
    Fix
    Flush the stale entry with sudo ip neigh flush to 10.0.10.20 (or sudo ip neigh del 10.0.10.20 dev eth0). On the new server, send Gratuitous ARP (arping -U -c 3 -I eth0 10.0.10.20) to update peers immediately.

    Two hosts in the same subnet (10.0.20.10/24 and 10.0.20.30/24) on the same switch cannot ping each other

    Cause
    Their switch ports belong to different VLANs (such as 20 and 30), or one side sends 802.1Q-tagged frames while the other expects untagged traffic.
    Fix
    Compare tags on both ends: bridge vlan show on a Linux bridge, ip -d link show eth0.20 on a subinterface, or sudo tcpdump -nn -e -i eth0 vlan on the wire.

    A host connects over Wi-Fi, and VMs behind a bridge (vmbr0) fail to get an address from the router

    Cause
    A standard Wi-Fi client can only transmit frames using its own MAC address; the access point drops frames from guest MACs behind the bridge.
    Fix
    Move the host to Ethernet, or place guests on a separate NAT network (Proxmox networking).

    tcpdump -nn -e -i eth0 shows no VLAN tags even though the port runs as a trunk

    Cause
    Capture is running on a subinterface like eth0.20 where the kernel already stripped the tag, or the NIC removed it via rx-vlan-offload.
    Fix
    Capture on the parent eth0 interface and inspect offload flags with ethtool -k eth0 | grep vlan-offload.