Router Basics

Understanding Layer 3 Forwarding and Routing Tables

A Router is a Layer 3 device designed to connect different networks together (e.g., connecting a LAN to the Internet or connecting different VLANs). While switches use MAC addresses, routers use IP Addresses to make forwarding decisions.

The Routing Table (RIB)

The router maintains a Routing Table (Routing Information Base) which contains the best paths to destination networks.

Packet Forwarding Process

When a router receives a packet, it performs the following steps:

  1. De-encapsulation: It removes the Layer 2 header (Ethernet frame) to inspect the Layer 3 packet.
  2. Destination Lookup: It checks the Destination IP address against its Routing Table.
  3. Longest Match Rule: If multiple routes match, the router selects the one with the longest subnet mask (most specific match).
  4. Encapsulation: It encapsulates the packet in a new Layer 2 frame appropriate for the outgoing interface (e.g., new Source/Dest MAC addresses).
  5. Forwarding: The frame is sent out the exit interface.
Router# show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area

Gateway of last resort is not set

      192.168.10.0/24 is variably subnetted, 2 subnets, 2 masks
C        192.168.10.0/24 is directly connected, GigabitEthernet0/0
L        192.168.10.1/32 is directly connected, GigabitEthernet0/0
S     10.0.0.0/8 [1/0] via 192.168.20.2
Key Difference: Switches connect devices in the same network. Routers connect different networks.