OSPF Routing
OSPF automatically exchanges routes between routers - routers learn the network topology and calculate the best path using cost (based on bandwidth).
Why Use OSPF?
Section titled “Why Use OSPF?”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).
Enable OSPF
Section titled “Enable OSPF”Router(config)# router ospf 10Router(config-router)# router-id 1.1.1.1Parameters:
- 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.
Add Networks to OSPF
Section titled “Add Networks to OSPF”Using network statements with wildcard mask:
Router(config-router)# network 10.1.1.0 0.0.0.255 area 0Router(config-router)# network 192.168.10.0 0.0.0.255 area 0Format: 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 0Router(config-router)# network 192.168.10.1 0.0.0.0 area 0Wildcard 0.0.0.0 means “exact match” - only that specific IP.
Add Networks via Interface
Section titled “Add Networks via Interface”Alternative method - configure OSPF directly on the interface.
Router(config)# interface GigabitEthernet0/0/0Router(config-if)# ip ospf 10 area 0Passive Interfaces
Section titled “Passive Interfaces”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/0Make all interfaces passive, then enable only needed ones:
Router(config-router)# passive-interface defaultRouter(config-router)# no passive-interface GigabitEthernet0/0/1Router(config-router)# no passive-interface Serial0/1/0OSPF Cost
Section titled “OSPF Cost”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 10000Value 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 50Hello and Dead Intervals
Section titled “Hello and Dead Intervals”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 5Router(config-if)# ip ospf dead-interval 20⚠️ Timers must match on both sides of the link, or neighbors won’t form.
Default Route Propagation
Section titled “Default Route Propagation”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.1Then propagate it into OSPF:
Router(config-router)# default-information originateNow all OSPF routers learn the default route pointing to this router.
DR/BDR Election (Multi-Access Networks)
Section titled “DR/BDR Election (Multi-Access Networks)”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:
- Highest priority (default is 1)
- Highest Router ID (tiebreaker)
Change interface priority to influence DR election:
Router(config-if)# ip ospf priority 255Priority 0 = never become DR/BDR.
Force DR election (after changing priorities):
Router# clear ip ospf processVerify Configuration
Section titled “Verify Configuration”Router# show ip ospf neighborRouter# show ip ospf interface briefRouter# show ip ospf interface GigabitEthernet0/0/0Router# show ip ospf databaseRouter# show ip route ospfRouter# show ip protocolsRouter# show ip ospfTroubleshooting Common Issues
Section titled “Troubleshooting Common Issues”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 neighborNeighbor states:
FULL= Fully adjacent (good)2-WAY= Normal for DROTHERs on multi-access networksINIT,EXSTART,EXCHANGE,LOADING= Transitional states (should resolve quickly)
Example Full Configuration
Section titled “Example Full Configuration”Router(config)# router ospf 10Router(config-router)# router-id 1.1.1.1Router(config-router)# network 10.1.1.0 0.0.0.255 area 0Router(config-router)# network 192.168.10.0 0.0.0.255 area 0Router(config-router)# passive-interface GigabitEthernet0/0/0Router(config-router)# auto-cost reference-bandwidth 10000Router(config-router)# exit
Router(config)# interface GigabitEthernet0/0/1Router(config-if)# ip ospf hello-interval 5Router(config-if)# ip ospf dead-interval 20