How switches and routers differ

A switch forwards frames by MAC address inside one network, a router forwards packets by IP address between networks. Check it with arp -a and ip route.

You plug your laptop into the switch at home, print a document to a printer on the same switch, and it’s done. Then you open a browser, type thomas-labs.com, and the page doesn’t load. The lights on the switch are still green, the cable is still plugged in. The broken thing isn’t the cable, it’s the connection point: a switch only forwards between machines on the same network, and getting outside the network needs a router. The two devices look alike (both are boxes with network ports) but they read two different kinds of addresses to make decisions. This post points out that difference, and how you can see it on your own machine with a few commands.

One frame, one MAC address

A switch is a box with many network ports, and it does exactly one thing: take a frame in on one port and push it out the port that has the destination machine. It decides based on the MAC address, the 48-bit address burned into the network card, written like 00:00:5e:00:53:01. The switch learns which MAC is behind which port by reading the source address of frames passing through, then writes it into the MAC table. There’s nothing to configure: plug in the cable, and a few seconds later it knows.

Why need that table? Without it, the switch would have to copy every frame to every port, like an old hub. With 8 ports that’s annoying, with 48 ports the network chokes because every frame gets duplicated 47 times. The MAC table turns that into sending out exactly one port. The cost is a bit of memory for the table and a few seconds of learning for each new machine.

The cut-off point: the MAC table knows nothing about IP. It only says “this MAC address is on port 4”.

Router: deciding by IP address

The computer browsing the web doesn’t send to the MAC address of thomas-labs.com, it sends to the IP address. But inside the LAN, the frame still needs a destination MAC address for the switch to push it along. So how does the computer handle it? It asks: “Which MAC goes with this IP?” and the router answers on behalf of the machine outside the network, with the MAC of its own router port. The router receives that frame, strips the outer layer, reads the destination IP address, looks up its routing table, and re-encapsulates for the next hop.

This is where the two devices really differ. The switch reads the layer 2 header (MAC) and doesn’t care whether inside is IP or something else. The router has to open the frame, read the layer 3 header (IP), so it’s slower per packet, but in exchange it connects different networks: your home network, your provider’s network, and the Internet.

A real home example: your ISP’s modem router is usually already a router plus switch. Its LAN ports are a 4-port switch, and it also holds the IP address for the whole house, usually 192.168.1.1. You plug an extra 8-port switch into one LAN port. The link between the two devices uses one port on each side: the router has 3 LAN ports free, the switch has 7 free, 10 ports total you can plug machines into. They’re all still on the same network 192.168.1.0/24, and all machines talk to each other through the switch, not the router.

Seeing the MAC table on your machine

Run arp -a on Windows, Linux or macOS. Here’s an example, not run on my machine; yours might use a different range, like 192.168.0.x or 10.0.0.x. The MAC in the example comes from the range reserved for documentation (RFC 7042), so it doesn’t belong to any device sold on the market:

? (192.168.1.1) at 00:00:5e:00:53:01 [ether] on wlan0

Read it as: IP 192.168.1.1 has MAC 00:00:5e:00:53:01. That’s the router in this example. Every frame sent to the Internet carries this destination MAC, even if the destination IP is thomas-labs.com’s. ARP is the protocol that asks “which MAC is this IP”, and the ARP table is the cache of answers, usually lasting a few minutes.

If there’s also a printer plugged into the switch, arp -a will have another line with IP 192.168.1.x and its own MAC. That’s the switch moving frames straight from your machine to the printer, without the router.

Seeing the routing table

Run ip route on Linux (macOS uses netstat -rn). This is also an example:

default via 192.168.1.1 dev wlan0 proto dhcp metric 600
192.168.1.0/24 dev wlan0 proto kernel scope link src 192.168.1.42

These two lines explain everything. The second line says: the network 192.168.1.0/24 is right on the card wlan0, send directly, no one needed. The first line says: any address that doesn’t match another line goes to 192.168.1.1. That’s the default router, or gateway.

When you open thomas-labs.com, the destination IP isn’t in 192.168.1.0/24, so the machine picks the default line: send the frame to the router. When you print to the printer 192.168.1.50, the destination IP matches the second line, so the machine sends directly, the switch forwards, the router isn’t involved.

The diagram below shows how the paths of the two frames differ, following exactly the routing table above.

graph LR
    L["Laptop<br/>192.168.1.42"] -->|"Destination IP 192.168.1.50"| S["Switch<br/>reads MAC"]
    S --> P["Printer<br/>192.168.1.50"]
    L -->|"Destination IP 203.0.113.9<br/>Destination MAC is router's MAC"| R["Router<br/>192.168.1.1"]
    R --> W["Internet"]

Note the second arrow: the machine doesn’t know the MAC of 203.0.113.9. It only knows the router’s MAC. The switch is still the final carrier of frames in the LAN, so in your home network these two devices work together, not as replacements for each other.

Before sending its first frame to the router, the machine has to know the router’s MAC. It asks with ARP, the protocol that turns an IP address into a MAC address within one network. The diagram below is one such question; the answer is kept, and it is the line you see when you run arp -a.

sequenceDiagram
    participant L as Laptop 192.168.1.42
    participant S as Switch
    participant R as Router 192.168.1.1
    L->>S: ARP to the whole network: who has 192.168.1.1?
    S->>R: sent out of every port
    R->>S: 192.168.1.1 is at MAC 00:00:5e:00:53:01
    S->>L: sent straight back to the laptop's port
    L->>R: first frame, destination MAC is the router's

Why not merge them into one

Modern devices combine both: home routers usually have a switch chip inside, and “layer 3” switches in server rooms can route IP too. But combining in one box doesn’t mean the same job. Each frame through a switch is handled in microseconds on dedicated hardware. Each packet that must be routed has to open the IP header, look up the table, which is slower and needs costlier hardware (TCAM) to keep up. Splitting the roles makes switches cheap and fast for the local network, while routers handle the complicated part of connecting different networks.

The cost of splitting: you have to configure IP addresses on the router and plug cables correctly. Plugging two routers’ LAN ports into each other is the start of duplicate addresses and a flaky network. A switch has nothing to misconfigure at the basic level.

Common homelab cases

You set up a Proxmox server and want it on a separate network 10.0.0.0/24, apart from your personal computer. The right way: create a network interface on the router (or a virtual router), assign 10.0.0.1, enable DHCP for that range. The switch just needs a cable plugged into the right port, and you can use VLANs to divide ports on the same physical switch. If you only have a plain switch and no router for the new network, the two IP ranges won’t talk: the computer still has a default route so packets still go to the router, but the router has no path to 10.0.0.0/24 so it usually reports Request timeout or returns “Destination Host Unreachable”.

Quick checks on your machine

Three commands, each answers one question:

  • arp -a: what’s my router’s MAC? Which machines on the same network are remembered?
  • ip route (Linux) or netstat -rn (macOS): which networks go direct, which go through the gateway?
  • ping 192.168.1.1 then ping 1.1.1.1: the first says the switch and LAN are okay, the second says the router can get out.

If ping 192.168.1.1 works but ping 1.1.1.1 doesn’t, you’re in exactly the situation from the start of this post: switch fine, router or the outside path has a problem.

Switch forwards frames by MAC within one network, router forwards packets by IP between networks. In your home, the switch delivers data to the router, and the router is what opens the door to the Internet.