Skip to content

OSPF Routing

OSPF automatically exchanges routes between routers - routers learn the network topology and calculate the best path using cost (based on bandwidth).

You need OSPF when:

  • You have a medium to large network (more than 5-10 routers)
  • You want automatic route discovery and failover
  • Your network topology changes frequently
  • You need fast convergence (quick recovery from failures)
  • You need a hierarchical design with multiple areas

When to use OSPF vs EIGRP: OSPF is an open standard (works with any vendor). EIGRP is Cisco proprietary (but faster convergence).

Router(config)# router ospf 10
Router(config-router)# router-id 1.1.1.1

Parameters:

  • 10 - OSPF process ID. Can be 1-65535 (only matters on this router).
  • 1.1.1.1 - Router ID. Replace with a unique ID for each router (use loopback IP or sequential IDs like 1.1.1.1, 2.2.2.2, etc.).

Process ID (10): Locally significant only - doesn’t need to match other routers. Can be 1-65535.

Router ID: Uniquely identifies this router in OSPF. Can be any IP format, but typically uses loopback or highest IP.

Using network statements with wildcard mask:

Router(config-router)# network 10.1.1.0 0.0.0.255 area 0
Router(config-router)# network 192.168.10.0 0.0.0.255 area 0

Format: network [network address] [wildcard mask] area [area ID]

Add a specific IP address (interface-based):

Router(config-router)# network 10.1.1.5 0.0.0.0 area 0
Router(config-router)# network 192.168.10.1 0.0.0.0 area 0

Wildcard 0.0.0.0 means “exact match” - only that specific IP.

Alternative method - configure OSPF directly on the interface.

Router(config)# interface GigabitEthernet0/0/0
Router(config-if)# ip ospf 10 area 0

Stop OSPF from sending hello packets on interfaces where no OSPF neighbors exist (like LANs with only end devices).

Make specific interface passive:

Router(config-router)# passive-interface GigabitEthernet0/0/0

Make all interfaces passive, then enable only needed ones:

Router(config-router)# passive-interface default
Router(config-router)# no passive-interface GigabitEthernet0/0/1
Router(config-router)# no passive-interface Serial0/1/0

OSPF uses cost to determine the best path. Lower cost = better path.

Default formula: Cost = Reference Bandwidth / Interface Bandwidth

Change reference bandwidth (for Gigabit+ networks):

Router(config-router)# auto-cost reference-bandwidth 10000

Value in Mbps. Default is 100 (Mbps), which makes Fast Ethernet and Gigabit both cost 1. Use 10000 for accurate Gigabit costs.

⚠️ Set the same reference bandwidth on all routers in the OSPF domain.

Manually set cost on interface:

Router(config-if)# ip ospf cost 50

OSPF routers send hello packets to detect neighbors. If hellos stop, the neighbor is considered dead.

Default timers:

  • Hello: 10 seconds
  • Dead: 40 seconds

Change timers:

Router(config-if)# ip ospf hello-interval 5
Router(config-if)# ip ospf dead-interval 20

⚠️ Timers must match on both sides of the link, or neighbors won’t form.

Advertise a default route into OSPF (useful for internet connectivity).

First, create a default static route:

Router(config)# ip route 0.0.0.0 0.0.0.0 203.0.113.1

Then propagate it into OSPF:

Router(config-router)# default-information originate

Now all OSPF routers learn the default route pointing to this router.

In networks with multiple routers on the same segment (e.g., Ethernet LAN), OSPF elects a Designated Router (DR) and Backup DR (BDR) to reduce OSPF traffic.

Election criteria:

  1. Highest priority (default is 1)
  2. Highest Router ID (tiebreaker)

Change interface priority to influence DR election:

Router(config-if)# ip ospf priority 255

Priority 0 = never become DR/BDR.

Force DR election (after changing priorities):

Router# clear ip ospf process
Router# show ip ospf neighbor
Router# show ip ospf interface brief
Router# show ip ospf interface GigabitEthernet0/0/0
Router# show ip ospf database
Router# show ip route ospf
Router# show ip protocols
Router# show ip ospf

Neighbors not forming? Check:

  • Subnet masks match on both sides
  • Hello/Dead timers match
  • Area IDs match
  • Network types match (broadcast, point-to-point, etc.)

Verify neighbor states:

Router# show ip ospf neighbor

Neighbor states:

  • FULL = Fully adjacent (good)
  • 2-WAY = Normal for DROTHERs on multi-access networks
  • INIT, EXSTART, EXCHANGE, LOADING = Transitional states (should resolve quickly)
Router(config)# router ospf 10
Router(config-router)# router-id 1.1.1.1
Router(config-router)# network 10.1.1.0 0.0.0.255 area 0
Router(config-router)# network 192.168.10.0 0.0.0.255 area 0
Router(config-router)# passive-interface GigabitEthernet0/0/0
Router(config-router)# auto-cost reference-bandwidth 10000
Router(config-router)# exit
Router(config)# interface GigabitEthernet0/0/1
Router(config-if)# ip ospf hello-interval 5
Router(config-if)# ip ospf dead-interval 20