Course contents

Unit 2: Network DevicesLesson 2.4 (4 of 10 in this unit)9 of 104 in the Network Fundamentals course

What a router does

Why traffic between networks needs a router, and the forwarding decision it makes for every packet.

Beginner · 6 min read

Covers Routing vs. switching, Default gateway and Hop-by-hop forwarding.

Technical definition

Router is a Layer 3 device that connects different IP networks and forwards packets between them. For each packet, it compares the destination IP address with its routing table and sends the packet out of the interface towards the best matching route.

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.

Diagram
A Layer 3 device between networks
A Layer 3 device between networks
SwitchRouter
Works atLayer 2 (data link)Layer 3 (network)
Looks atDestination MAC addressDestination IP address
UsesMAC address tableRouting table
Moves trafficWithin one network (one VLAN)Between different networks
Unknown destinationFloods the frame within the VLANDrops the packet (unless a default route exists)
Read each row across: the left box names the item, the others describe it.

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:

Diagram
PC1 sends a packet to the server, one hop at a time
PC1 sends a packet to the server, one hop at a time
192.168.1.0/24203.0.113.0/3010.0.12.0/3010.0.23.0/30192.168.2.0/24192.168.3.0/24PC1IP 192.168.1.10ISPIP 203.0.113.1R1R2R3PC2IP 192.168.2.10ServerIP 192.168.3.10

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. 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. 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. 3. R2 decides: 192.168.3.0/24 is reached through R3 (10.0.23.2), so R2 forwards the packet to R3.
  4. 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.10 and destination 192.168.3.10 from 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.

Step 1 of 5
  1. PC1Src 192.168.1.10
  2. R1Default gateway · TTL 64 → 63
  3. R2Next hop 10.0.23.2 · TTL → 62
  4. R3Directly connected · TTL → 61
  5. ServerDst 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.

The same journey as a simple path: each router makes its own next-hop decision.

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.

Example output · based on Cisco documentation; exact format varies by platform and software version
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
What to look for: each working interface needs an IP-Address and up in both the Status and Protocol columns. Gi0/3 is administratively down (shut down) and has no address, so R1 can't route through it.

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

Predict · scenario 1

PC1 (192.168.1.10/24) sends data to 192.168.1.50. Where does it send the packet?

Predict · scenario 2

As the packet from PC1 passes through R1, R2 and R3, what stays the same?

Predict · scenario 3

A router has no route for a packet's destination and no default route. What happens?