1. Home
  2. Explore
  3. Computer Science
  4. Routing Fundamentals

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Routing Fundamentals

Routing Fundamentals

What routing does

Routing is the process routers use to determine the path IP packets should take across a network to reach their destinations. When a router receives a packet, it examines the packet’s destination IP address and consults its routing table to choose what to do next.

A routing table is a set of instructions about destinations the router knows how to reach. A route may tell the router to:

  • Send a packet toward a next hop, meaning the next router along the path to the destination.

  • Send a packet directly out an interface when the destination network is directly connected.

  • Keep a packet for itself when the destination is one of the router’s own IP addresses.

A router’s routing table is similar in broad purpose to a switch’s MAC address table: both help determine where traffic should go. However, they contain different information and are used differently. Switches use MAC address entries to forward Ethernet frames; routers use routes to forward IP packets.


How routers learn routes

Routes are commonly learned in two ways:

  • Dynamic routing: Routers use routing protocols, such as OSPF, to exchange routing information automatically and build their routing tables.

  • Static routing: A network administrator manually configures routes on the router.

Connected and local routes are a separate category: they are added automatically when an interface has an IP address and is enabled. They are neither static routes nor routes learned through a dynamic routing protocol.


Example network and addressing

The example network contains four routers connected across a WAN, or Wide Area Network. A WAN spans a large geographical area; its routers might be in different cities or countries. R1 and R4 also connect to LANs, or Local Area Networks, which represent networks in individual locations.

The example uses simple addresses in which each router’s address ends in a number corresponding to its router name. This makes the topology easier to follow, but real networks do not necessarily use this pattern.

LANs and router connections

  • R1 LAN: The network is 192.168.1.0/24192.168.1.0/24192.168.1.0/24. R1’s G0/2 interface is 192.168.1.1192.168.1.1192.168.1.1, and PC1 is 192.168.1.10192.168.1.10192.168.1.10.

  • R1–R2 WAN link: The network is 192.168.12.0/24192.168.12.0/24192.168.12.0/24. R1’s G0/1 interface is 192.168.12.1192.168.12.1192.168.12.1, and R2’s G0/0 interface is 192.168.12.2192.168.12.2192.168.12.2.

  • R1–R3 WAN link: The network is 192.168.13.0/24192.168.13.0/24192.168.13.0/24. R1’s G0/0 interface is 192.168.13.1192.168.13.1192.168.13.1, and R3’s G0/0 interface is 192.168.13.3192.168.13.3192.168.13.3.

  • R2–R4 WAN link: The network is 192.168.24.0/24192.168.24.0/24192.168.24.0/24. R2’s G0/1 interface is 192.168.24.2192.168.24.2192.168.24.2, and R4’s G0/0 interface is 192.168.24.4192.168.24.4192.168.24.4.

  • R3–R4 WAN link: The network is 192.168.34.0/24192.168.34.0/24192.168.34.0/24. R3’s G0/1 interface is 192.168.34.3192.168.34.3192.168.34.3, and R4’s G0/1 interface is 192.168.34.4192.168.34.4192.168.34.4.

  • R4 LAN: The network is 192.168.4.0/24192.168.4.0/24192.168.4.0/24. R4’s G0/2 interface is 192.168.4.4192.168.4.4192.168.4.4, and PC4 is 192.168.4.10192.168.4.10192.168.4.10.

The example is later used to illustrate static routes that allow PC1 and PC4 to communicate. The main focus here is how routers create and use connected and local routes.


Viewing the routing table

On a Cisco router, the show ip route command displays the routing table. The output includes a codes legend, which identifies route sources and the abbreviations used for them, followed by the routes themselves.

Two important codes are:

  • C — Connected: A route to the network attached to a router interface.

  • L — Local: A route to the exact IP address configured on a router interface.

When an interface has an IP address and is enabled, the router automatically adds two routes for it: one connected route and one local route. A shut-down interface does not provide these routes in the routing table. Interface configuration commonly includes assigning an IP address and enabling the interface with no shutdown.

For example, configuring R1’s G0/2 interface as 192.168.1.1/24192.168.1.1/24192.168.1.1/24 creates:

  • A connected route to 192.168.1.0/24192.168.1.0/24192.168.1.0/24.

  • A local route to 192.168.1.1/32192.168.1.1/32192.168.1.1/32.

With three configured, enabled interfaces, R1 has three connected routes and three local routes, even before any static or dynamic routes have been configured.


Connected routes

A connected route identifies the network attached to a router interface. The router derives the network address by keeping the network portion of the interface address and setting the host portion to zero.

For an interface address of 192.168.1.1/24192.168.1.1/24192.168.1.1/24:

  • The first 24 bits are the network portion, corresponding to the first three octets.

  • The remaining 8 bits are the host portion.

  • Setting the host portion to zero gives the network address 192.168.1.0/24192.168.1.0/24192.168.1.0/24.

The connected route tells the router that destinations within this network are reached through the attached interface. For R1’s G0/2, a route to 192.168.1.0/24192.168.1.0/24192.168.1.0/24 means that packets for destinations in that network should be sent out G0/2 toward the destination.

A /24/24/24 prefix covers the addresses from 192.168.1.0192.168.1.0192.168.1.0 through 192.168.1.255192.168.1.255192.168.1.255. Thus, destinations such as 192.168.1.2192.168.1.2192.168.1.2, 192.168.1.7192.168.1.7192.168.1.7, and 192.168.1.89192.168.1.89192.168.1.89 belong to that network. A destination such as 192.168.2.1192.168.2.1192.168.2.1 does not.


Local routes

A local route identifies the exact IP address configured on a router interface. It uses a /32/32/32 prefix, which fixes all 32 bits of the address and therefore represents just one IP address.

For an interface address of 192.168.1.1/24192.168.1.1/24192.168.1.1/24, the local route is 192.168.1.1/32192.168.1.1/32192.168.1.1/32. It matches 192.168.1.1192.168.1.1192.168.1.1 only; it does not match another address such as 192.168.1.2192.168.1.2192.168.1.2.

A local route tells the router that a packet addressed to that IP is meant for the router itself. The router receives the packet rather than forwarding it out an interface toward another device.


Route matching

A route matches a packet when the packet’s destination IP address belongs to the network specified by that route. The route’s prefix length determines how much of the destination address must match.

For example:

  • A route to 192.168.1.0/24192.168.1.0/24192.168.1.0/24 matches 192.168.1.60192.168.1.60192.168.1.60, because that address belongs to the 192.168.1.0/24192.168.1.0/24192.168.1.0/24 network.

  • The same route does not match 192.168.2.1192.168.2.1192.168.2.1, because that address belongs to a different network.

  • A route to 192.168.1.1/32192.168.1.1/32192.168.1.1/32 matches only 192.168.1.1192.168.1.1192.168.1.1.

A packet may match more than one route. For example, a packet destined for 192.168.1.1192.168.1.1192.168.1.1 matches both the connected route 192.168.1.0/24192.168.1.0/24192.168.1.0/24 and the local route 192.168.1.1/32192.168.1.1/32192.168.1.1/32.


Route selection: the longest-prefix match

When multiple routes match a packet’s destination, the router selects the most specific matching route. The most specific route is the matching route with the longest prefix length.

A longer prefix identifies a narrower range of addresses:

  • 192.168.1.0/24192.168.1.0/24192.168.1.0/24 represents 256 possible addresses.

  • 192.168.1.1/32192.168.1.1/32192.168.1.1/32 represents exactly one address.

Therefore, for a packet destined for 192.168.1.1192.168.1.1192.168.1.1, R1 selects the local /32/32/32 route rather than the connected /24/24/24 route. R1 receives the packet for itself instead of forwarding it out G0/2.

Both parts of the selection rule matter: a route must first match the packet’s destination, and then it must have the longest prefix among the matching routes.

Route-selection examples on R1

  • Destination 192.168.1.1192.168.1.1192.168.1.1: The packet matches both 192.168.1.0/24192.168.1.0/24192.168.1.0/24 and 192.168.1.1/32192.168.1.1/32192.168.1.1/32. The /32/32/32 local route is more specific, so R1 receives the packet.

  • Destination 192.168.13.3192.168.13.3192.168.13.3: The matching route is the connected route to 192.168.13.0/24192.168.13.0/24192.168.13.0/24. R1 sends the packet out G0/0 toward the directly connected destination.

  • Destination 192.168.1.244192.168.1.244192.168.1.244: The matching route is the connected route to 192.168.1.0/24192.168.1.0/24192.168.1.0/24. R1 sends the packet out G0/2.

  • Destination 192.168.12.1192.168.12.1192.168.12.1: The matching local route is 192.168.12.1/32192.168.12.1/32192.168.12.1/32. R1 receives the packet for itself.

  • Destination 192.168.4.10192.168.4.10192.168.4.10: If R1 has no route matching this destination, it drops the packet.

A router does not flood packets when it has no matching route. This differs from a switch, which floods an unknown unicast frame when it does not have a matching destination MAC address entry. Routers drop packets for which they have no matching route; they do not flood them.


Informational subnet lines in routing-table output

Cisco routing-table output may include lines such as “variably subnetted” followed by a count of subnets and masks. These lines are summaries, not routes. They indicate that the routing table contains multiple subnet entries associated with a broader network grouping and that those entries use different prefix lengths.

For example, a grouping line may accompany a connected route with a /24/24/24 prefix and a local route with a /32/32/32 prefix. The actual forwarding instructions are the route entries themselves; the summary lines can generally be distinguished from those entries and ignored when identifying the route to use.


Key points to remember

  • A routing table stores routes the router uses to decide how to handle IP packets.

  • A route is an instruction about how to reach a destination, either by forwarding toward a next hop, sending directly through a connected interface, or receiving the packet locally.

  • An enabled interface with an IP address automatically adds a connected route to its network and a local route to its exact address.

  • Connected routes use the network prefix configured on the interface; local routes use a /32/32/32 prefix.

  • A route matches a packet when the destination IP belongs to the route’s network.

  • If several routes match, the router uses the matching route with the longest prefix length.

  • If no route matches, the router drops the packet rather than flooding it.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent