Unit

IP Routing Explained: Route Selection and Forwarding

Learn how routers select routes, use longest-prefix matching, forward packets, and troubleshoot static, dynamic, default, and looping routes.

IP routing is the process of selecting a path and forwarding IP packets toward a destination network. It allows devices on different IP networks to communicate. A host can deliver traffic directly within its local subnet, but it needs a router to reach a remote subnet.

This lesson assumes familiarity with subnetting, IPv4 and IPv6 addressing, Ethernet frames, MAC addresses, and basic router interfaces.

Purpose of IP routing

An IP network is identified by a network address and prefix length, such as 192.168.10.0/24 or 2001:db8:10::/64. When a device sends a packet, it compares the destination IP address with its own network information.

  • Local-subnet delivery: the destination is on the same local network or IPv6 link. The sender resolves the destination's Layer 2 address and transmits directly.
  • Remote-network delivery: the destination is on another IP network. The sender transmits the frame to a router called the default gateway.

A router is a Layer 3 forwarding device. It examines the destination IP address, selects an appropriate route, and sends the packet through an interface toward the next network. Routers separate broadcast domains and normally do not forward an Ethernet frame unchanged from one network to another.

Local delivery versus remote delivery

ConditionIP DestinationLayer 2 DestinationRouter Required
Same IPv4 subnetThe other host's IPv4 addressThe other host's MAC address, resolved with ARPNo
Different IPv4 subnetThe remote host's IPv4 addressThe default gateway's MAC addressYes
Same IPv6 linkThe other host's IPv6 addressThe other host's link-layer address, resolved with Neighbor DiscoveryNo
Different IPv6 networkThe remote host's IPv6 addressThe local router's link-layer addressYes

Routing-table fundamentals

A routing table is a set of route entries used to determine where packets should be sent. A route is a path entry for a destination prefix, together with the forwarding information needed to reach it.

FieldPurposeExample
Destination prefixNetwork matched against the packet's destination address192.168.20.0
Prefix length or subnet maskDefines how specific the destination network is/24 or 255.255.255.0
Next hopAdjacent router or device to receive the packet next192.168.12.2
Outgoing interfaceInterface used to transmit the packetGigabitEthernet0/1
Route sourceHow the route entered the tableConnected, static, OSPF, or BGP
Administrative distanceLocal preference between different sources for the same prefixA lower value is generally preferred
MetricCost used to compare paths from the same routing source or protocolOSPF cost or RIP hop count

Types of routes

Route TypeHow It Is LearnedTypical UseAdvantagesLimitations
ConnectedCreated when an interface has an address, prefix, and operational linkNetworks directly attached to the routerAutomatic and accurate for local interfacesOnly describes directly connected networks
StaticManually configured by an administratorSmall, stable, stub, or specially controlled networksPredictable and low overheadRequires manual changes after topology changes
DynamicLearned through a routing protocolMedium and large networks with changing pathsCan adapt to failures and new pathsUses protocol resources and requires correct operation

When an interface is configured with an address and prefix and becomes operational, the router can install a connected route for that directly attached network. It can also install a local route for the interface address itself, depending on the platform.

Route lookup and route selection

For every forwarded packet, the router performs a lookup using the packet's destination IP address. The basic process is:

  1. Read the destination IP address from the packet.
  2. Find every routing-table entry whose destination prefix contains that address.
  3. Choose the matching route with the longest prefix, also called the most specific route.
  4. If multiple usable routes have the same destination prefix, compare route preference or administrative distance when their sources differ.
  5. Among routes from the same source or protocol, compare the protocol's metric when applicable.
  6. Resolve the next hop at Layer 2, then transmit through the selected interface.
  7. If no route matches, use a default route if one exists. Otherwise, discard the packet and report an unreachable result when appropriate.

Longest-prefix match

Longest-prefix match selects the most specific matching route. A longer prefix contains more fixed network bits and therefore describes a smaller destination range.

RouteAddresses coveredMatches 10.1.2.50?
10.0.0.0/8All 10.x.x.x addressesYes
10.1.0.0/1610.1.x.xYes
10.1.2.0/2410.1.2.xYes

The router selects 10.1.2.0/24 because /24 is longer than /16 and /8. This rule takes priority over a route's metric when the prefixes are different.

Administrative distance and metrics

Administrative distance, also called route preference on some platforms, is a local value used when different sources offer routes to the same prefix. For example, a router might have both a static route and an OSPF route to 192.168.20.0/24. The platform compares their preferences and normally installs the source with the better value.

A metric is a cost used to compare paths within the same routing source or protocol. A routing protocol might calculate cost from bandwidth, count hops, delay, or another algorithm. Do not compare metrics from unrelated protocols as though they used the same scale.

Route-selection order

Decision StepRuleExample Outcome
Find matching prefixesIdentify every route containing the destination addressThree routes match 10.1.2.50
Choose longest prefixSelect the most specific matching prefixChoose /24 over /16 and /8
Compare route preference for identical prefixesPrefer the better administrative distance or local preferenceChoose a preferred static route over an alternate source
Compare metric where applicableChoose the lower or otherwise preferred protocol costChoose the lower-cost OSPF path
Use default route only if necessaryUse 0.0.0.0/0 or ::/0 only when no more-specific route matchesSend unknown Internet traffic upstream
Return unreachable if no route existsDiscard traffic when there is no usable matching routeReport network unreachable or destination unreachable

Packet forwarding from host to host

Example: two hosts on the same subnet

Assume host A is 192.168.10.10/24 and host B is 192.168.10.20/24. Host A determines that both addresses belong to 192.168.10.0/24. It uses ARP to resolve 192.168.10.20 to host B's MAC address, places the IP packet inside an Ethernet frame addressed directly to B, and transmits it. The default gateway is not used.

Example: a remote IPv4 subnet

Now assume host A is 192.168.10.10/24, its default gateway is 192.168.10.1, and the destination is host B at 192.168.20.10/24. Host A recognizes that the destination is remote. It uses ARP to resolve the gateway's MAC address and sends the first Ethernet frame to that MAC address.

The IP packet still has 192.168.10.10 as its source and 192.168.20.10 as its destination. The router receives the frame, removes the Ethernet encapsulation, decrements the IPv4 TTL, consults its routing table, and finds its connected route for 192.168.20.0/24. It then resolves host B's MAC address on the outgoing interface, creates a new Ethernet frame, and transmits it.

IPv6 next-hop resolution

IPv4 uses ARP to resolve a local IPv4 address to a MAC address. IPv6 uses Neighbor Discovery, which is carried in ICMPv6 messages. The forwarding concept is the same: before sending on a local link, the device must discover the link-layer address for the destination host or next-hop router.

Connected and static routing

A static route is a manually configured route. It is useful for a small network, a stable path, a stub network with one exit, a backup route, or a deliberately controlled forwarding policy.

Static-route forms

  • Next-hop static route: specifies the adjacent router's IP address. The device then determines which interface can reach that next hop.
  • Exit-interface static route: specifies the interface through which the packet should leave. This is common on point-to-point links but may require additional resolution on multiaccess networks.
  • Default static route: matches all destinations when no more-specific route exists. IPv4 uses 0.0.0.0/0; IPv6 uses ::/0.

A next-hop route may require recursive lookup. The router first looks up the next-hop address, determines the outgoing interface needed to reach that next hop, and then forwards the original packet through that interface. If the next hop cannot itself be reached, the route may not be usable.

Cisco IOS-style examples

ip route 192.168.20.0 255.255.255.0 192.168.12.2
ip route 0.0.0.0 0.0.0.0 192.168.12.2

ipv6 route 2001:db8:20::/64 2001:db8:12::2
ipv6 route ::/0 2001:db8:12::2

These examples add a route to an internal network and a default route toward an upstream router. Syntax and route-preference behavior can vary by vendor and operating system.

Dynamic routing overview

Dynamic routing protocols allow routers to learn, exchange, and update routes. When a link fails or a better path becomes available, routers recalculate their routing information. The time required for routers to agree on the new state is called convergence.

  • Interior routing operates within one administrative routing domain or organization. Examples include RIP, OSPF, EIGRP, and IS-IS.
  • Exterior routing exchanges reachability between separate administrative domains. BGP is the primary example.

Dynamic protocols do not eliminate the need to understand route selection. They provide candidate routes, calculate metrics, and install selected routes in the routing table. The forwarding process still uses destination matching and the best installed route.

Default routes and routing boundaries

The IPv4 default route is 0.0.0.0/0. It matches every IPv4 destination, but it is selected only when no more-specific route matches. The IPv6 equivalent is ::/0. A default route commonly points from an internal router or host toward an upstream router, Internet edge, or service-provider connection.

Routing must work in both directions. Suppose Router A forwards a request from LAN A to LAN B, but Router B has no route back to LAN A. The request can arrive while the reply is discarded or sent along the wrong path. This is a missing return route, not a successful end-to-end connection.

Static routes in both directions

For two LANs connected through separate routers, configure a route from Router A to LAN B and a route from Router B to LAN A. Test both directions. Removing the return route demonstrates why one-way packet delivery does not guarantee bidirectional communication.

Routing outcomes and failure conditions

  • No route: no matching route exists and no usable default route is installed. The packet is discarded and an unreachable message may be generated.
  • Incorrect next hop: the selected router address is wrong or is not reachable through the expected interface.
  • Unavailable interface: the route exists, but its outgoing link is down or otherwise unusable.
  • Overlapping routes: multiple prefixes cover the same address. Longest-prefix matching may select a more-specific route than an administrator expected.
  • Routing loop: inconsistent routes cause routers to forward a packet back and forth. Each IPv4 router decrements TTL, and each IPv6 router decrements Hop Limit. When the value reaches zero, the packet is discarded, limiting the loop's lifetime.

Routing is not every networking problem

A failed ping or application connection may result from routing, but it may also result from DNS name resolution, a firewall or ACL, NAT, an incorrect VLAN, a failed physical link, a host service, or a wrong address. A route proves only that the device has a forwarding decision; it does not prove that the next hop is reachable, that filtering permits the traffic, or that the application is listening.

Inspecting routes and testing forwarding

Use commands appropriate to the device and operating system:

Cisco IOS-style:
show ip route
show ipv6 route

Linux:
ip route show
ip -6 route show
ip route get 192.168.20.10
ping 192.168.20.10
traceroute 192.168.20.10

Windows:
route print
ping 192.168.20.10
tracert 192.168.20.10

ip route get is especially useful on Linux because it displays the route and interface selected for one destination. Route tables on Cisco IOS-style devices commonly show route source, prefix, administrative distance, metric, next hop, and interface.

Troubleshooting a routing problem

Local access works, remote access fails

  • Verify the host IP address, prefix length, and default gateway.
  • Ping the local gateway.
  • Check that the gateway interface is operational.
  • Inspect the router's route to the remote network.
  • Use traceroute or tracert to identify where forwarding stops.
  • Check firewall or ACL policy if the routes are correct.

Requests arrive but replies do not

  • Inspect routes in both directions.
  • Confirm that the destination host has the correct default gateway.
  • Look for asymmetric routing combined with stateful filtering.
  • Verify source addresses and subnet masks.
  • Capture traffic or inspect interface counters on both routers.

An unexpected path is selected

  • Perform a lookup for the exact destination address.
  • Compare all matching prefixes and their prefix lengths.
  • Review route source, administrative distance, and metric.
  • Look for an unintended static route or a more-specific prefix.

Traceroute repeats addresses or reports TTL expiration

  • Suspect a routing loop, inconsistent static routes, or incomplete dynamic-protocol convergence.
  • Trace from multiple points to locate the repeating routers.
  • Inspect the affected prefix on every involved router.
  • Correct the forwarding next hops and verify that routing information converges.

A route exists but forwarding fails

  • Verify that the outgoing interface is up.
  • Inspect ARP for IPv4 or Neighbor Discovery entries for IPv6.
  • Confirm the next hop is reachable at Layer 2.
  • Check VLAN, link-layer, ACL, and firewall configuration.

Exam-relevant summary

  • Routing connects different IP networks; switching handles local Layer 2 delivery.
  • Hosts send off-subnet traffic to their default gateway.
  • Routers select the longest matching prefix first.
  • Administrative distance or route preference compares different sources for the same prefix.
  • Metrics compare candidate paths within a routing source or protocol.
  • The default route is a last-resort match, not a preferred replacement for specific routes.
  • Connected routes describe active directly attached networks; static routes are manual; dynamic routes are learned through protocols.
  • Each routed hop replaces the Layer 2 frame, while the IP destination normally remains the same.
  • TTL and IPv6 Hop Limit protect against indefinite routing loops.
  • Successful forward delivery requires a return route for replies.