Free tech learning for everyone, from basics to pro

Routing & SwitchingNetworking SecurityIntermediate

OSPF authentication: plain text, MD5, HMAC-SHA and TTL security

In short: OSPF authentication makes sure routers only accept routing information from neighbours that know a shared key. Plain text sends the key itself and MD5 sends a digest; both are legacy. Current IOS supports HMAC-SHA through key chains, which also make key rotation easy. TTL security adds a check that packets came from a directly connected router.

Why authenticate OSPF

OSPF trusts its neighbours. Any device that can send valid hellos on an OSPF-enabled segment can become a neighbour and inject routes, whether that is a misconfigured lab router or an attacker trying to redirect traffic. Passive interfaces close most user-facing ports, but on links between routers you also want proof that a neighbour is one of yours. OSPF authentication adds a shared secret to every packet.

OSPF authentication optionsLegacyType 0: noneType 1: plain text, key visibleType 2: MD5 digestMD5 is no longer considered strongCurrentHMAC-SHA with a key chainKey rotation with lifetimesTTL security on topOSPFv3: IPsec or auth trailer
Figure 1. Plain text and MD5 still appear in exams and old configurations. New designs should use HMAC-SHA through a key chain.

Plain text and MD5

OSPFv2 defines three authentication types in its packet header: 0 (none), 1 (simple password) and 2 (cryptographic, originally MD5).

  • Plain text puts the password itself in every packet. Anyone capturing traffic can read it. It only protects against accidents.
  • MD5 sends a hash of the packet and key, plus a sequence number that guards against simple replay. The key never crosses the wire, but MD5 is now considered weak.
! Plain text on one interface (legacy)
interface GigabitEthernet0/1
 ip ospf authentication
 ip ospf authentication-key Lab0nly1
!
! MD5 on one interface (legacy)
interface GigabitEthernet0/2
 ip ospf authentication message-digest
 ip ospf message-digest-key 1 md5 Str0ngKey!2026
!
! Or turn MD5 on for every interface in an area
router ospf 1
 area 0 authentication message-digest

Area-wide authentication only sets the type; each interface still needs its key. Both ends of a link must agree on type, key ID and key, or the adjacency drops and a log message reports an authentication mismatch.

HMAC-SHA with key chains

Current IOS and IOS XE releases support HMAC-SHA authentication for OSPFv2 (described in RFC 5709) through a key chain. Key chains hold several keys with start and end times, so you can roll to a new key without an outage.

key chain OSPF-CORE
 key 1
  key-string C0re-Key-A
  cryptographic-algorithm hmac-sha-256
 key 2
  key-string C0re-Key-B
  cryptographic-algorithm hmac-sha-256
  send-lifetime 00:00:00 Jan 1 2027 infinite
!
interface GigabitEthernet0/1
 ip ospf authentication key-chain OSPF-CORE

To rotate keys, add the new key to every router first, set when it starts being sent, and remove the old key after all routers have moved. Keep router clocks in sync with NTP, otherwise key lifetimes start at different moments.

For OSPFv3 (IPv6), authentication uses IPsec or the newer authentication trailer instead of fields in the header.

TTL security and virtual links

OSPF packets between neighbours are sent with a TTL of 1 for multicast, but unicast packets can travel further. TTL security tells the router to accept OSPF packets only if their TTL shows they came from at most a set number of hops away. A forged packet from across the network arrives with a lower TTL and is dropped before it reaches the OSPF process.

router ospf 1
 ttl-security all-interfaces hops 1

Virtual links belong to area 0. If area 0 uses authentication, the virtual link must be configured with matching authentication too, or it will not come up.

Real-world example: a school trust's shared core

A trust of four schools shared one core network, and each school had a local technician with access to its own router. During a project, a technician connected a spare router to a core VLAN to test something, and it formed an OSPF adjacency and advertised an old default route. Half of one school lost internet access for an hour. The network manager then enabled HMAC-SHA-256 authentication through a key chain on every core link, stored the key in the trust's password vault, and added passive-interface default everywhere. A test router plugged in later simply logged an authentication mismatch and was ignored.

Practice

Why is plain text OSPF authentication not a real security control?
The password travels in clear text in every packet, so anyone who captures traffic on the link can read it.
What is the main operational advantage of key chains?
They hold several keys with lifetimes, so you can introduce a new key and retire the old one without dropping adjacencies.
Area 0 uses MD5 authentication. A new virtual link through area 5 does not come up. What should you check?
That the virtual link has matching area 0 authentication configured, because virtual links belong to area 0.

Key takeaways

  • Authentication stops unknown devices from becoming OSPF neighbours.
  • Plain text and MD5 are legacy; prefer HMAC-SHA through a key chain.
  • Type, key ID and key must match on both ends of a link.
  • Key chains with lifetimes allow key rotation without outages; keep NTP working.
  • TTL security drops OSPF packets from routers that are too far away.
Tracks your learning on this device only. See your progress on the learning paths.

About the author

Mohamed Fayas

Founder of FM TecHub. CCNA certified, with a BTEC HND in Network Engineering, and BEng (Hons) in Computer Networking and Cloud Security. He writes practical, plain-English guides on networking, security and cloud.

More about the author

Original content written by Mohamed Fayas for FM TecHub. © 2026 FM TecHub. You're welcome to share a link to this page; please don't copy the text elsewhere without permission.

Stay up to date by email

New notes, tools and security news from FM TecHub, explained simply. Free.

We only use your email to send these updates. See our privacy policy.