Certopolis

CompTIA Network+ (V9)

Longest prefix match vs administrative distance (Network+)

A router forwards each packet using the most specific matching route, the one with the longest prefix. Administrative distance only decides which source's route is installed when two sources offer the same prefix, and the metric breaks ties within one protocol. AD never overrides a longer prefix.

Step 1 at forwarding time: longest prefix wins

RFC 1812 describes the Longest Match rule. Of all routes that match the destination, the router keeps only those with the longest prefix. Its example: for 10.144.2.5, with 10.144.2.0/24, 10.144.0.0/16 and 10.0.0.0/8 in the table, only the /24 is kept.

The default route is by definition the route whose prefix length is zero. Any explicit route that covers the destination is therefore more specific and is used instead, whatever its metric.

Step 2 when installing: administrative distance

Cisco defines administrative distance as a value used to rank the trustworthiness of routing information sources. When two sources offer the same prefix, the lower AD is installed. Defaults: connected 0, static 1, EIGRP summary 5, external BGP 20, internal EIGRP 90, OSPF 110, IS-IS 115, RIP 120, external EIGRP 170, internal BGP 200, unknown 255.

A floating static route uses this. Cisco's example sets a static route to AD 250. Because 250 is higher than OSPF's 110, the static route stays out of the table while the OSPF route exists, and takes over if the OSPF route is removed.

Cisco also states that AD and routing metrics are not evaluated during forwarding, so AD does not override longest prefix match. If 192.168.0.0/16 comes from a low-AD source and 192.168.1.0/24 from a higher-AD source, both are installed because the prefixes differ, and a packet to 192.168.1.10 uses the /24.

Step 3 within one protocol: metric

When one protocol offers two routes to the same prefix and length, AD is equal, so the protocol's own metric decides; for OSPF that is the lowest total cost. When different protocols offer the same prefix, AD decides, because their metrics measure different things.

Where the exam catches people

  • Believing a lower administrative distance beats a longer prefix: AD only chooses between sources for the same prefix; forwarding uses longest match.
  • Believing a static route always wins over OSPF: a static route set to AD 250 loses to OSPF's 110 and floats as a backup.
  • Believing the default route can win because its metric is better: its prefix length is zero, so any covering explicit route is preferred.
  • Believing administrative distance is used while forwarding each packet: Cisco says AD and metrics are not evaluated during forwarding; they only decide what is installed.

Written from CompTIA's documentation

Try 3 questions on this

Pick an answer to see why each option is right or wrong.

  1. A packet's destination is covered by both a router's default route and a more specific route that has a worse metric. Which of the following decides which route is used?

    Right. In the game that’s Renown for your Network Implementation building.

    Not that one: C is right. In the game your Network Implementation building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    Routes are selected in order of decreasing prefix length, so any explicit route covering the destination is more specific than the default route and is used, whatever its metric.

    Written from www.rfc-editor.org/rfc/rfc1812.html

  2. A router installs 192.168.0.0/16 from a source with a low administrative distance and 192.168.1.0/24 from a source with a higher one. Which of the following routes forwards a packet to 192.168.1.10?

    Right. In the game that’s Renown for your Network Implementation building.

    Not that one: C is right. In the game your Network Implementation building would lose a little Renown, and this question would come back later.

  3. A router has a static route with an administrative distance of 250 and an OSPF-learned route to the same prefix. Which of the following does the router install while both exist?

    Right. In the game that’s Renown for your Network Implementation building.

    Not that one: A is right. In the game your Network Implementation building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    OSPF's default distance is 110, below the static route's 250, so the OSPF route is installed; the page's own example sets a static route to 250 so it stays out of the table until the OSPF route fails.

    Written from www.cisco.com/c/en/us/support/docs/ip/border-gateway-protocol-bgp/15986-admin-distance.html