Course contents

Module 6: Advanced OSPFLesson 6.1 (1 of 8 in this module)22 of 29 in the OSPF course

Beyond CCNA (optional). This topic is not on the CCNA 200-301 exam. It is useful at work and in later study; skip it if you are preparing for the exam. (The exam covers single-area OSPFv2 (3.4); authentication is not listed.)

OSPF authentication

What stops another device on a shared link from joining your routing conversation? Let's protect the R2–R3 link, then check what authentication does and does not prove.

Advanced · 10 min read

A router link that runs through a shared building

R2 Gi0/1, 10.0.23.1/30, connects to R3 Gi0/0, 10.0.23.2/30, through a switch. R2 and R3 need to exchange OSPF routing information, so this link cannot be passive. Another device with access to the same VLAN could try to join that conversation. Without authentication, compatible OSPF settings and access to the link may let it form a neighbour relationship.

Without and with authentication
Without and with authenticationWithout authentication any device on the link can form a neighbour and inject routes.No authenticationAny router can joinRoutes can be injectedWith authenticationOnly routers with the keyform adjacenciesvs

On small screens, swipe sideways or focus the diagram and use the arrow keys.

Authentication proves the sender knows the key.

OSPF authentication adds a receiver check before OSPF accepts a packet. With cryptographic authentication, both routers hold a shared key, a secret value configured locally. The sender calculates a digest, a check value derived from the packet and key. The receiver calculates the expected value and compares it.

Null, plain text and cryptographic authentication

OSPFv2 offers three authentication types, chosen per interface (or per area):

Authentication types
Authentication typesOSPFv2 has three types.Type 0: nullNo authenticationType 1: plain textPassword sent as text; protects only against mistakesType 2: cryptographicMD5 or HMAC-SHA digest with a key ID

On small screens, swipe sideways or focus the diagram and use the arrow keys.

Use cryptographic authentication.
Null, plain text and cryptographic authentication
Null, plain text and cryptographic authenticationType; What is sent; Key length; Use it?. 0 Null: Nothing - Default 1 Plain text: The key itself, in every packet Up to 8 characters No: anyone capturing traffic sees it 2 MD5: Key ID + a keyed digest + a sequence number Up to 16 characters with this IOS command Recognise existing designs; check local policy 2 HMAC-SHA (key chain): Key ID + an HMAC-SHA digest + a sequence number Key-chain key strings Prefer an approved SHA-2 option where both ends support itTypeWhat is sentKey lengthUse it?0 NullNothing-Default1 Plain textThe key itself, in everypacketUp to 8 charactersNo: anyone capturingtraffic sees it2 MD5Key ID + a keyed digest +a sequence numberUp to 16 characters withthis IOS commandRecognise existingdesigns; check localpolicy2 HMAC-SHA (keychain)Key ID + an HMAC-SHAdigest + a sequencenumberKey-chain key stringsPrefer an approved SHA-2option where both endssupport it

On small screens, swipe sideways or focus the diagram and use the arrow keys.

Read each row across: the left box names the item, the others describe it.

The authentication type and key are part of the hello check, like the area and timers. If they don't match for a key the receiver accepts, neighbour formation fails. Authentication also applies to later OSPF packets, not only Hellos.

R2key 1 = Lab-Key-23
R3key 1 = Lab-Key-23
  1. Auth type 2, key ID 1, sequence 1739, hash of (packet + Lab-Key-23).Hello from R2 to R3.Hello
  2. R3 checksLook up key ID 1, verify the digest with the local key and apply the sequence-number checks. Accept only if the required checks pass.
  3. HelloAuth type 2, key ID 1, sequence 902, hash of (packet + Lab-Key-23).Hello from R3 to R2.
  4. NeighboursBoth checks pass and the adjacency forms as normal. Every later DBD, LSR, LSU and LSAck carries a hash too.
  5. HelloFrom a laptop: no authentication, or a guessed key.Hello from R3 to R2.
  6. DroppedType or hash doesn't match: R2 ignores the packet. The laptop never becomes a neighbour.

Device key: R2, R3 (router)

The top line is the shared network link; port labels name its interfaces. Read message rows from top to bottom and follow each arrow from sender to receiver. Rows show protocol order, not additional cables or timing to scale.

Reading the addresses

IP labels identify interfaces or destinations. Subnet labels identify networks; /n is the prefix length. A router ID (RID) identifies a routing process and need not be a reachable interface.

An IP address alone is not a URL. A web URL includes a scheme such as https://; an address on a router or printer does not imply a website.

  • R2: key 1 = Lab-Key-23 · 10.0.23.1
  • R3: key 1 = Lab-Key-23 · 10.0.23.2
MD5 authentication between R2 and R3. The key never crosses the wire; each side recalculates the hash with its own copy and compares.

What the digest and sequence number actually check

The digest lets the receiver detect packet changes and reject packets without valid shared-key proof. The key is not carried as a plain-text field in cryptographic authentication. Routing records remain visible, and weak keys still need protection. The sequence number helps identify old packets replayed by a device that recorded an earlier exchange. It is not a blanket guarantee against every replay attack: RFC 7474 adds protections for weaknesses in older manually keyed OSPFv2 mechanisms.

How a cryptographic check works
How a cryptographic check worksThe sender adds a digest. The receiver recomputes it and checks the sequence number.Senderpacket + keymakes a digestPacketdigest andsequence numberReceiverrecomputes andcomparesResultaccept or drop

On small screens, swipe sideways or focus the diagram and use the arrow keys.

The key is never sent. The sequence number blocks replays.

This is the trade-off of shared-key authentication: it avoids a separate login exchange for every routing packet, but distributing and replacing the same secret on several devices takes care. It proves possession of a key, not a unique device identity. The older MD5 method remains below so you can understand existing configurations; the key-chain example shows a supported HMAC-SHA-256 alternative.

Turning on authentication on Cisco IOS

Use an isolated Cisco IOS or IOS XE lab with OSPFv2 already working in area 0 on this /30 link. R2 and R3 use point-to-point network type and unique router IDs, 2.2.2.2 and 3.3.3.3. Commands start in global configuration mode unless stated otherwise. Treat MD5, key-chain and plain-text blocks as alternatives, not steps to paste together. All displayed keys are public teaching examples; do not reuse them as real secrets.

Enable authentication on a link
Enable authentication on a linkSet the key, then turn the mode on.Keymessage-digest-key 1md5 secretModeauthenticationmessage-digestOther endsame key and IDCheckshow ip ospf interface

On small screens, swipe sideways or focus the diagram and use the arrow keys.

Both ends must use the same key ID and key.

MD5 on one interface

interface GigabitEthernet0/1 ip ospf authentication message-digest ip ospf message-digest-key 1 md5 Lab-Key-23

On R2 (and the same on R3's Gi0/0). The first line turns MD5 on for this interface; the second sets key ID 1. Both the key ID and the key must match the neighbour's.

MD5 for a whole area

router ospf 1 area 0 authentication message-digest ! interface GigabitEthernet0/0 ip ospf message-digest-key 1 md5 Lab-Key-12 interface GigabitEthernet0/1 ip ospf message-digest-key 1 md5 Lab-Key-23

area 0 authentication turns MD5 on for every interface in area 0. The keys are still set per interface, so each link can have its own. An interface-level ip ospf authentication command overrides the area setting.

HMAC-SHA with a key chain

key chain OSPF-KEYS key 1 key-string Lab-Key-23-Long-Secret cryptographic-algorithm hmac-sha-256 ! interface GigabitEthernet0/1 ip ospf authentication key-chain OSPF-KEYS

R2 example for a release that supports OSPFv2 HMAC-SHA-256. On R3, define the matching key/algorithm and apply the chain to Gi0/0. Local chain names can differ; the on-wire key ID, algorithm and accepted key must agree. Check valid send and accept lifetimes on both routers.

A key chain stores keys and their validity periods. The send lifetime controls which key can sign outgoing packets; the accept lifetime controls which received keys can be verified. These periods let you prepare a replacement before removing the old key. Check the platform's selection rules and clock before a timed rollover. On the documented IOS XE implementation, applying an OSPF key chain causes previously configured interface MD5 keys to be ignored.

Plain text (for recognition only)

interface GigabitEthernet0/1 ip ospf authentication ip ospf authentication-key Secret12

Type 1. The key is sent in clear text; avoid it outside labs.

Note: service password-encryption can obfuscate supported password fields as type 7. Type 7 is easily reversed. It is not encryption for OSPF packets or a safe way to publish a configuration file.

Confirming which authentication is active

Confirming the mode
Confirming the modeInterface output shows the mode in use.show ip ospf interfaceShows the authentication mode enabledshow run interfaceShows the key and mode linesshow ip ospf neighborFULL means the exchange works

On small screens, swipe sideways or focus the diagram and use the arrow keys.

A key that exists but is not enabled does nothing.
Example output · based on Cisco documentation; exact format varies by platform and software version
R2#show ip ospf interface GigabitEthernet0/1
GigabitEthernet0/1 is up, line protocol is up
  Internet Address 10.0.23.1/30, Area 0, Attached via Network Statement
  Process ID 1, Router ID 2.2.2.2, Network Type POINT_TO_POINT, Cost: 10
  ...
  Neighbor Count is 1, Adjacent neighbor count is 1
    Adjacent with neighbor 3.3.3.3
  Suppress hello for 0 neighbor(s)
  Cryptographic authentication enabled
    Youngest key id is 1
Cryptographic authentication enabled and the key ID in use. Plain text shows "Simple password authentication enabled"; with a key chain the output names the chain and the algorithm.
Example output · based on Cisco documentation; exact format varies by platform and software version
R2#show ip ospf | include BACKBONE|authentication
    Area BACKBONE(0)
        Area has message digest authentication
Area-level authentication is listed per area in show ip ospf.

Reading an authentication mismatch

First compare interface authentication type, active key ID, algorithm and lifetimes on both ends. Check logs before enabling debug. The following is a short lab-only diagnostic example; output and CPU load vary. Finish with undebug all, and do not publish output that contains real keys.

Reading a mismatch
Reading a mismatchA mismatch shows in the neighbour table and the debug.MismatchDifferent typeone end null, onecryptographicDifferent keysame type, wrongsecretDifferent key IDsame secret, wrongID

On small screens, swipe sideways or focus the diagram and use the arrow keys.

Debug output names the type or key that failed.
Example output · based on Cisco documentation; exact format varies by platform and software version
R2#debug ip ospf adj
OSPF-1 ADJ   Gi0/1: Rcv pkt from 10.0.23.2 : Mismatched Authentication Key - Message Digest Key 1
Same key ID, different key. Other variants report a mismatched authentication type (one side not configured) or an unknown key ID. Exact wording varies by IOS version.
  • Type mismatch: authentication on one end only, or MD5 on one end and plain text on the other.
  • Key ID mismatch: key 1 on one router, key 2 on the other.
  • Key mismatch: a typo, or trailing spaces copied into the key.
  • Area setting missed on one router: area 0 authentication message-digest configured on some routers only.

Change keys carefully: adding authentication to one end of a live link drops the adjacency until the other end matches. MD5 lets you configure a second key ID on both routers first, then remove the old one.

If the key ID is correct but digest verification fails, use the approved secret source to restore the intended value on both ends. Do not compare keys by posting running configurations into tickets. Type 7 obfuscation is reversible, and different stored strings alone do not reliably explain the active authentication state.

Half-configured authentication and other slips

Half configured
Half configuredIf one end has the key and not the mode, or only one end is configured, adjacency fails.One end onlyThe other drops thepacketsBoth endsSame type, ID and keyvs

On small screens, swipe sideways or focus the diagram and use the arrow keys.

Check both routers.
  • Setting the key but not turning authentication on (or the reverse).
  • Expecting area-level authentication to set the keys too. Keys are set per interface (or on the virtual-link command).
  • Using plain text outside a lab.
  • Thinking authentication encrypts the LSAs.

Authentication rules to remember

What has to match
  • Cryptographic authentication rejects packets that cannot pass the configured shared-key checks.
  • Types: 0 none, 1 plain text (avoid), 2 cryptographic (MD5 or HMAC-SHA).
  • Enable per interface (ip ospf authentication message-digest) or per area (area 0 authentication message-digest); keys are per interface.
  • The receiver needs an accepted key ID, matching secret and compatible method; check lifetimes during a rollover.

Short lab: prove the check before trusting the result

Start with the healthy R2–R3 lab. Record the Full adjacency and the route to LAN 3, 192.168.3.0/24, on R2. Configure the matching MD5 example on both lab interfaces. A one-sided change can interrupt the adjacency, so do not use this exercise on a live network.

show ip ospf interface GigabitEthernet0/1 show ip ospf neighbor show ip route 192.168.3.0

R2, privileged EXEC: confirm authentication and key ID, then Full with router ID 3.3.3.3, then the learned LAN route. On R3 inspect Gi0/0 instead.

Change only R3's lab key text while keeping key ID 1. Observe the mismatch and loss of adjacency. Restore Lab-Key-23 on R3, wait for Full, and recheck the route and a PC-to-server test. Explain why a link can remain up while routing fails. Do not disable authentication as the repair.

References: Cisco OSPFv2 key-chain configuration, RFC 5709 HMAC-SHA and RFC 7474 replay-protection extensions. Commands and outputs are documentation-based examples, not captures from a tested router image.

Test yourself on OSPF authentication

Predict · scenario 1

R2 uses MD5 key 1 on Gi0/1. R3 has no authentication on Gi0/0. What happens?

Predict · scenario 2

With MD5 authentication, what crosses the link?

Predict · scenario 3

R2 has ip ospf message-digest-key 1 md5 Lab-Key-23; R3 has ip ospf message-digest-key 2 md5 Lab-Key-23. Both have MD5 enabled. Result?

FAQ

Does OSPF authentication encrypt the routing information?
No. Cryptographic authentication checks that a packet passes a shared-key integrity check; it does not hide routing information or uniquely identify a person or router. A device with the same key can also generate valid packets. Encryption needs a separate protection mechanism, such as an appropriately designed IPsec tunnel.
Is passive-interface enough on LANs?
A passive OSPF interface forms no neighbours, which suits a user LAN with no OSPF router. It does not replace switch access controls or protect every service on that LAN. Use authentication on active routing links where neighbours are intended, together with the rest of the network's security policy.
Is MD5 still acceptable?
Recognise keyed MD5 because existing configurations use it. For a new design, prefer a mutually supported HMAC-SHA-2 option under the organisation's policy, and check the exact platform release. Do not assume that every IOS or IOS XE image supports the same key-chain commands. Plain-text authentication exposes its password to packet capture.