OSPF External Metrics: E1 vs E2 Explained - 夜莺博客

OSPF External Metrics: E1 vs E2 Explained

Redistribute a static route into OSPF and every router in the domain shows the same metric for it, no matter how far away it is. That is external metric type 2, OSPF's default, and it is correct more often than people assume. But when two ASBRs inject the same prefix from different places in the network, E2 makes them look identical and every router picks the same exit — sometimes on the far side of the backbone. This article explains what the two metric types actually compute and when each one is the right tool.

What redistribution produces by default

router ospf 1
 redistribute static subnets
!
show ip route ospf | include E2
! O E2  10.99.1.0/24 [110/20] via 10.0.12.2, 00:00:13, Ethernet0/0

Two things to read in that output. The code is O E2, and the metric is 20 — OSPF's default seed metric for anything redistributed except BGP, which seeds at 1. Nobody configured 20; it is what you get when you do not set a metric.

E2: the metric stays flat

show ip route 10.99.1.0
! Routing entry for 10.99.1.0/24
!  Known via "ospf 1", distance 110, metric 20, type extern 2, forward metric 20

The route metric is exactly the seed value on every router in the domain. The internal cost to reach the ASBR is tracked separately as the forward metric, and it is used only as a tiebreaker between equal E2 routes. That is the whole philosophy of E2: the external cost is assumed to dwarf anything internal.

E1: seed metric plus internal cost

router ospf 1
 redistribute static subnets metric-type 1 metric 50
!
show ip route ospf | include E1
! O E1  10.99.1.0/24 [110/70] via 10.0.12.2, 00:00:16, Ethernet0/0

Metric 70 is the seed of 50 plus the local router's internal cost of 20 to reach the ASBR. E1 routes accumulate internal cost as they propagate, so a router close to the ASBR sees a lower total than one further away — which is exactly what you want when there are several possible exits.

Choosing between them

  • One ASBR, or several co-located ASBRs — leave the default E2. Internal cost does not change the decision, so E1 adds nothing but arithmetic.
  • Multiple ASBRs in different parts of the network — set E1. Each router then picks the genuinely closest exit instead of all of them pointing at the same ASBR because its seed metric happens to be lower.
  • Equalising traffic — E1 with matching seeds lets internal costs decide and naturally spreads load; E2 with matching seeds gives you a per-router tiebreak on forward metric only.

One hard rule worth memorising: when an E1 and an E2 route exist for the same prefix, E1 is always preferred, regardless of the E2 metric. Mixing metric types across ASBRs for the same prefix therefore gives you a deterministic but surprising outcome.

Under the hood: the type-5 LSA

show ip ospf database external 10.99.1.0
! LS Type: AS External Link
! Link State ID: 10.99.1.0
! Metric Type: 2 (Larger than any link state path)
! Metric: 20
! Forward Address: 0.0.0.0
! External Route Tag: 0

The LSA carries the metric type, the seed metric and a forward address. A forward address of 0.0.0.0 means "send traffic to the ASBR that originated this LSA". A non-zero forward address appears when the external network is directly reachable on a shared segment: it tells every router to forward via that address rather than through the ASBR, and it introduces a classic failure — the route will not install unless the forward address itself is reachable through OSPF. That is a frequent cause of "the LSA is in the database but no route appears".

Tags and loops

route-map STATIC-TO-OSPF permit 10
 set tag 100
!
router ospf 1
 redistribute static subnets route-map STATIC-TO-OSPF
!
! never redistribute back into the routing protocol the route came from
route-map FROM-OSPF deny 10
 match tag 100

Two routers mututally redistributing each other's routing protocols is the standard recipe for a routing loop, and the standard defence is tagging on the way in and filtering on the way out.

NSSA and type-7

In a not-so-stubby area, there is no type-5 flooding; external routes are carried as type-7 LSAs, translated to type-5 by the ABR. The same E1/E2 logic applies inside the NSSA, and redistribute ... nssa-only keeps a redistribution local to the NSSA — see OSPF stub and NSSA area types for that configuration. For the multicast-free alternative of summarising externals at an ABR, see OSPF LSA types explained.

Verification commands that answer the common questions in one pass: show ip ospf database external (what the ASBR injected), show ip route ospf (what you installed), show ip ospf border-routers (who the ASBRs are and how you reach them), and show ip ospf (whether redistribution actually made this router an ASBR — look for It is an autonomous system boundary router).

原文链接:https://networkacademy.io/ccna/ospf/external-route-types-e1-and-e2