A file on a server in another office
PC1 sits in the main office. It needs a file from a server in the branch office. The two offices are different networks: PC1 is in 192.168.1.0/24 and the server is in 192.168.3.0/24. A Layer 2 switch can't help here, because it only moves frames within one network. Something has to carry the packet from one network to the other. That something is a router.
A Layer 3 device between networks
A router is a device that connects different IP networks and moves packets between them. It works at Layer 3 of the OSI model, the network layer, which is the layer that deals with IP addresses.
Each router interface is in a different network. When a packet arrives, the router looks at its destination IP address, checks its routing table (its list of known networks) and sends the packet out of the interface that leads closer to that address. This choice is called the forwarding decision.
| Switch | Router | |
|---|---|---|
| Works at | Layer 2 (data link) | Layer 3 (network) |
| Looks at | Destination MAC address | Destination IP address |
| Uses | MAC address table | Routing table |
| Moves traffic | Within one network (one VLAN) | Between different networks |
| Unknown destination | Floods the frame within the VLAN | Drops the packet (unless a default route exists) |
The default gateway: PC1's way out
PC1 doesn't know anything about other networks. It only knows its own IP address and subnet mask, which are enough to tell whether a destination is local (same network) or remote. For remote destinations, it sends the packet to its default gateway: the router interface on its own network, here R1's 192.168.1.1.
One next-hop decision per router
No single router decides the whole path. Each router only decides the next hop: the next router to pass the packet to. That router then makes its own decision, and so on. Watch the packet cross this three-router network:
Device key: PC1, PC2 (computer) · ISP (network / service) · R1, R2, R3 (router)
Lines show the example’s network connections. Thick links: uplinks/WAN, as labelled. The coloured path and envelope follow the current step; its text identifies the sender, receiver and traffic type.
Reading the addresses
IP labels identify interfaces or destinations. Subnet labels identify networks; /n is the prefix length. A router ID (RID) identifies a routing process and need not be a reachable interface.
An IP address alone is not a URL. A web URL includes a scheme such as https://; an address on a router or printer does not imply a website.
- PC1: IP 192.168.1.10
- ISP: IP 203.0.113.1
- PC2: IP 192.168.2.10
- Server: IP 192.168.3.10
- 1. PC1: not local. 192.168.3.10 is outside 192.168.1.0/24, so PC1 sends the packet to its default gateway, R1.
- 2. R1 decides: its routing table says 192.168.3.0/24 is reached through R2 (10.0.12.2), so it sends the packet out of Gi0/1.
- 3. R2 decides: 192.168.3.0/24 is reached through R3 (10.0.23.2), so R2 forwards the packet to R3.
- 4. R3 delivers: 192.168.3.0/24 is directly connected, so R3 delivers the packet straight to the server.
Why local decisions let routing scale
Keeping each decision local is what lets routing scale. A router doesn't need to know every device on the internet. It only needs to know which neighbour is closer to each network. Along the way, one thing stays the same and two things change at every router:
- The IP addresses stay the same. Source
192.168.1.10and destination192.168.3.10from start to end (as long as no NAT is involved). - The Ethernet frame is rebuilt. Each router removes the old frame and wraps the packet in a new one, with new source and destination MAC addresses for the next link.
- The TTL goes down by one. TTL (time to live) is a counter in the IP header. If it reaches zero, the router drops the packet. This stops a packet from looping forever if the routes are wrong.
The TTL is also what makes traceroute (tracert on Windows) work: it sends probes with a TTL of 1, 2, 3 and so on, and each router that drops one reports back, so you get one line per hop.
- PC1Src 192.168.1.10
- R1Default gateway · TTL 64 → 63
- R2Next hop 10.0.23.2 · TTL → 62
- R3Directly connected · TTL → 61
- ServerDst 192.168.3.10
PC1 — Src 192.168.1.10
- PC1: Src 192.168.1.10
- R1: Default gateway · TTL 64 → 63
- R2: Next hop 10.0.23.2 · TTL → 62
- R3: Directly connected · TTL → 61
- Server: Dst 192.168.3.10
Follow the labelled stages in order. The moving marker shows progress through this explanation; connectors do not imply separate physical cables or a time scale.
Checking interfaces and the gateway
A router can only route through interfaces that are up and have an IP address, so check that first. The output below is based on Cisco documentation, not captured from a lab device.
R1#show ip interface brief Interface IP-Address OK? Method Status Protocol GigabitEthernet0/0 192.168.1.1 YES manual up up GigabitEthernet0/1 10.0.12.1 YES manual up up GigabitEthernet0/2 203.0.113.2 YES manual up up GigabitEthernet0/3 unassigned YES unset administratively down down
On PC1, ipconfig (Windows) or ip route (Linux, the default via line) shows the default gateway. If it is missing or wrong, PC1 can reach its own network but nothing beyond it.
Test yourself on what routers do
PC1 (192.168.1.10/24) sends data to 192.168.1.50. Where does it send the packet?
As the packet from PC1 passes through R1, R2 and R3, what stays the same?
A router has no route for a packet's destination and no default route. What happens?