Computer Networking Cheatsheet

Ethernet and Switching

Use this Computer Networking reference while you build software engineering projects, review code, or refresh the syntax you reach for most.

MAC addresses

48 bits, written as six hex bytes. The first three bytes are the OUI (organizationally unique identifier, the vendor), the last three are assigned by that vendor.

  b8:27:eb : 4a:1c:7f
  \______/   \______/
    OUI       NIC
  Raspberry   serial

Two bits in the first byte carry meaning:

BitName0 means1 means
least significant of byte 0I/Gunicastmulticast group
second least significantU/Lglobally unique (OUI)locally administered

ff:ff:ff:ff:ff:ff is broadcast. 01:00:5e:... is IPv4 multicast, 33:33:... is IPv6 multicast. Randomized Wi-Fi MACs set the U/L bit, which is why they never match a vendor lookup.

Ethernet II frame layout

+----------+---------+---------+-----------+----------------+-----+
| Preamble | Dst MAC | Src MAC | EtherType |    Payload     | FCS |
|  8 bytes |    6    |    6    |     2     |    46-1500     |  4  |
+----------+---------+---------+-----------+----------------+-----+
                              802.1Q tag inserts 4 bytes here
EtherTypeProtocol
0x0800IPv4
0x0806ARP
0x86DDIPv6
0x8100802.1Q VLAN tag
0x88A8802.1ad QinQ
0x8847MPLS unicast
0x8863 / 0x8864PPPoE discovery / session

Minimum frame is 64 bytes including FCS, so short payloads get padded. Maximum untagged frame is 1518 bytes, and 1522 with a VLAN tag.

How a switch learns

A switch is a layer 2 device with one collision domain per port. It builds a MAC address table (also called the CAM table) mapping MAC → port.

1. A frame arrives on port 3 with source aa:bb:cc:00:00:01. The switch records aa:bb:cc:00:00:01 → port 3 with an aging timer, 300 s by default on Cisco. 2. The switch looks up the destination MAC. 3. Known unicast: forward out that one port. 4. Unknown unicast, broadcast, or multicast: flood out every port in the VLAN except the one it arrived on. 5. The destination replies, the switch learns its port, and the conversation stops flooding.

bridge fdb show                    # Linux bridge forwarding database
bridge fdb show br br0
ip -s link show dev eth0           # per-interface counters, errors, drops

Cisco equivalents: show mac address-table and show interfaces status.

Hub vs switch vs router vs L3 switch

DeviceLayerForwards onCollision domainsBroadcast domains
Hub1nothing, repeats bits1 shared1
Bridge · switch2destination MAC1 per port1 per VLAN
L3 switch2 and 3MAC in VLAN, IP between1 per port1 per VLAN, routes between
Router3destination IP1 per port1 per interface
Firewall3, 4, 7policy on flowsper portper interface

The line to remember: switches separate collision domains, routers separate broadcast domains.

Duplex, autonegotiation, and speed

Modern links autonegotiate. A duplex mismatch (one side full, one side half) still happens when someone hardcodes one end, and it shows up as a link that works at low load and collapses under load, with late collisions and CRC errors on the counters.

ethtool eth0                       # speed, duplex, link, advertised modes
ethtool -S eth0 | grep -iE 'err|drop|crc'
ethtool -s eth0 speed 1000 duplex full autoneg on
ip link set eth0 up
ip link show eth0                  # LOWER_UP means carrier is present
Counter climbingUsual cause
CRC / FCS errorsbad cable, bad SFP, duplex mismatch
Late collisionsduplex mismatch
Input dropsring buffer too small, CPU starved
Carrier transitionsflapping link, dying transceiver