A real-life situation
In the Routing course you connected three sites with static routes. It worked, but every new LAN meant typing routes on every router, in both directions. Now the company is adding a fourth site, and you decide to replace the static routes with OSPF. In this lesson you configure the whole lab: three routers, one area, a default route to the ISP, and costs that make sense on gigabit links.
The OSPF overview showed a short example. This lesson looks at each command properly, the choices you have, and how to check every step.
- 1. Neighbours on the two router links. OSPF runs on 10.0.12.0/30 and 10.0.23.0/30. Both links are set to point-to-point: no DR election.
- 2. LANs advertised, but no hellos. The three LAN interfaces are in OSPF so their subnets are advertised, but they are passive: no routers live there.
- 3. R1 shares its default route. R1 has a static default to the ISP (203.0.113.1) and advertises it into OSPF with default-information originate.
- 4. R3 reaches LAN 1 with cost 30. With a reference bandwidth of 10 Gbps, each gigabit interface costs 10: R3 Gi0/0 + R2 Gi0/0 + R1 Gi0/0 = 30.
| Router | Interface | Address | Connects to | OSPF role |
|---|---|---|---|---|
| R1 (1.1.1.1) | Gi0/0 | 192.168.1.1/24 | LAN 1 | Passive |
| Gi0/1 | 10.0.12.1/30 | R2 | Point-to-point neighbour | |
| Gi0/2 | 203.0.113.2/30 | ISP | Not in OSPF | |
| R2 (2.2.2.2) | Gi0/0 | 10.0.12.2/30 | R1 | Point-to-point neighbour |
| Gi0/1 | 10.0.23.1/30 | R3 | Point-to-point neighbour | |
| Gi0/2 | 192.168.2.1/24 | LAN 2 | Passive | |
| R3 (3.3.3.3) | Gi0/0 | 10.0.23.2/30 | R2 | Point-to-point neighbour |
| Gi0/1 | 192.168.3.1/24 | LAN 3 | Passive |
What you are configuring
Single-area OSPFv2 needs only a few decisions:
Why it works this way
Enabling OSPF on an interface does two separate things: the router starts sending hellos out of it, and the interface's subnet goes into the router's LSA, so every other router learns it. Usually you want both on router-to-router links, but only the second on LANs full of PCs. Sending hellos there wastes a little effort and, worse, lets anyone who plugs in a device running OSPF try to become a neighbour and inject routes. That is what passive interfaces fix.
Cost is OSPF's metric, the number it adds up to compare paths. It is calculated per outgoing interface as reference bandwidth ÷ interface bandwidth, rounded down and never below 1. With the default 100 Mbps reference, a FastEthernet, gigabit and 10-gigabit link all cost 1, so OSPF cannot tell them apart. Raising the reference (here to 10 000 Mbps) fixes that.
How to configure it on Cisco IOS
Option 1: network statements
network <address> <wildcard-mask> area <area-id>Router configuration mode. Every interface whose IP address matches the address and wildcard is enabled for OSPF in that area.
A wildcard mask is the inverse of a subnet mask: a 0 bit means "must match" and a 1 bit means "don't care". Subtract the subnet mask from 255.255.255.255 to get it.
| Statement | Matches |
|---|---|
network 192.168.1.0 0.0.0.255 area 0 | Any interface with an address 192.168.1.0 to 192.168.1.255 |
network 10.0.12.0 0.0.0.3 area 0 | Any interface with an address 10.0.12.0 to 10.0.12.3 |
network 10.0.12.1 0.0.0.0 area 0 | Only the interface with exactly 10.0.12.1. Very precise. |
network 10.0.0.0 0.255.255.255 area 0 | Every interface in 10.0.0.0/8. Quick, but easy to include too much. |
network 0.0.0.0 255.255.255.255 area 0 | Every interface on the router, including one facing the ISP. Avoid. |
The full R1 configuration, using network statements:
ip route 0.0.0.0 0.0.0.0 203.0.113.1
!
interface GigabitEthernet0/1
ip ospf network point-to-point
!
router ospf 1
router-id 1.1.1.1
auto-cost reference-bandwidth 10000
passive-interface GigabitEthernet0/0
network 192.168.1.0 0.0.0.255 area 0
network 10.0.12.0 0.0.0.3 area 0
default-information originateR1. Gi0/2 (203.0.113.2, towards the ISP) matches no network statement, so OSPF never runs there. The static default route is what default-information originate advertises.
Option 2: enabling OSPF on the interface
ip ospf <process-id> area <area-id>Interface configuration mode. Enables exactly this interface, no wildcards needed. The process is created if it does not exist.
router ospf 1
router-id 2.2.2.2
auto-cost reference-bandwidth 10000
passive-interface GigabitEthernet0/2
!
interface GigabitEthernet0/0
ip ospf 1 area 0
ip ospf network point-to-point
!
interface GigabitEthernet0/1
ip ospf 1 area 0
ip ospf network point-to-point
!
interface GigabitEthernet0/2
ip ospf 1 area 0R2. Each interface says for itself which process and area it belongs to.
Passive by default
On a router with many LANs it is safer to make every interface passive and switch hellos on only where a neighbour is expected:
interface GigabitEthernet0/0
ip ospf network point-to-point
!
router ospf 1
router-id 3.3.3.3
auto-cost reference-bandwidth 10000
passive-interface default
no passive-interface GigabitEthernet0/0
network 10.0.23.2 0.0.0.0 area 0
network 192.168.3.1 0.0.0.0 area 0R3. Gi0/1 (LAN 3) is passive because of passive-interface default. Only Gi0/0 towards R2 sends hellos. The 0.0.0.0 wildcards match single interface addresses.
Cost and reference bandwidth
router ospf 1
auto-cost reference-bandwidth 10000The value is in Mbps. 10000 = 10 Gbps, so a 1 Gbps interface costs 10 and a 100 Mbps interface costs 100. IOS reminds you to set the same value on all routers; otherwise their costs are not comparable.
interface GigabitEthernet0/1
ip ospf cost 50Sets the cost of this one interface directly, overriding the calculation. Cost applies to traffic leaving through this interface only; the router on the other end has its own cost for the reverse direction.
interface GigabitEthernet0/1
bandwidth 100000The bandwidth command (in kbps) changes the value OSPF divides by, so it changes the cost too. It does not change the real speed of the link.
| Cost is decided by (highest priority first) | Example |
|---|---|
1. ip ospf cost on the interface | ip ospf cost 50 → 50 |
2. reference bandwidth ÷ bandwidth if set | 10 000 Mbps ÷ 100 Mbps → 100 |
| 3. reference bandwidth ÷ real interface speed | 10 000 Mbps ÷ 1 000 Mbps → 10 |
If two paths to the same network have the same total cost, OSPF installs both and shares traffic between them (equal-cost multi-path, up to 4 paths by default, changed with maximum-paths).
Advertising a default route
R1 has a static default route to the ISP. default-information originate under router ospf tells R1 to advertise a default route into OSPF, but only while R1 has a default route in its own routing table. If the ISP link fails and the static route disappears, R1 stops advertising it, which is usually what you want. Adding always advertises it regardless.
How to verify it
R1#show ip protocols *** IP Routing is NSF aware *** Routing Protocol is "ospf 1" Outgoing update filter list for all interfaces is not set Incoming update filter list for all interfaces is not set Router ID 1.1.1.1 It is an autonomous system boundary router Number of areas in this router is 1. 1 normal 0 stub 0 nssa Maximum path: 4 Routing for Networks: 10.0.12.0 0.0.0.3 area 0 192.168.1.0 0.0.0.255 area 0 Passive Interface(s): GigabitEthernet0/0 Routing Information Sources: Gateway Distance Last Update 2.2.2.2 110 00:04:51 3.3.3.3 110 00:04:47 Distance: (default is 110)
ip ospf area appear in a separate "Routing on Interfaces Configured Explicitly" list instead.R2#show ip ospf interface brief Interface PID Area IP Address/Mask Cost State Nbrs F/C Gi0/2 1 0 192.168.2.1/24 10 DR 0/0 Gi0/1 1 0 10.0.23.1/30 10 P2P 1/1 Gi0/0 1 0 10.0.12.2/30 10 P2P 1/1
P2P with one Full neighbour each. The LAN shows DR with no neighbours: on a broadcast segment with no other routers, the router is simply DR on its own.R2#show ip ospf neighbor Neighbor ID Pri State Dead Time Address Interface 3.3.3.3 0 FULL/ - 00:00:34 10.0.23.2 GigabitEthernet0/1 1.1.1.1 0 FULL/ - 00:00:39 10.0.12.1 GigabitEthernet0/0
R3#show ip route ospf Gateway of last resort is 10.0.23.1 to network 0.0.0.0 O*E2 0.0.0.0/0 [110/1] via 10.0.23.1, 00:03:02, GigabitEthernet0/0 10.0.0.0/8 is variably subnetted, 3 subnets, 2 masks O 10.0.12.0/30 [110/20] via 10.0.23.1, 00:03:12, GigabitEthernet0/0 O 192.168.1.0/24 [110/30] via 10.0.23.1, 00:03:12, GigabitEthernet0/0 O 192.168.2.0/24 [110/20] via 10.0.23.1, 00:03:12, GigabitEthernet0/0
show ip ospf interface GigabitEthernet0/1Full detail for one interface: area, network type, cost, timers, DR/BDR and neighbour count.
What goes wrong and how to troubleshoot it
- An interface is missing from
show ip ospf interface brief. No network statement matches its address (check the wildcard arithmetic), or theip ospf areacommand is missing. - A LAN is missing from other routers' tables. Same cause: if the interface is not in OSPF, its subnet is not advertised. Making it passive does not stop advertising.
- No neighbour on a router link. The interface is passive (common after
passive-interface default), or the two ends disagree on area, subnet or timers. - No default route on R2 and R3. R1 has
default-information originatebut no default route of its own, for example because the ISP interface is down. - Strange path choices. Reference bandwidth set on some routers but not others, so their costs don't add up consistently.
Verifying and troubleshooting OSPF goes through these in a structured way.
Common mistakes
- Writing a subnet mask instead of a wildcard in the network command, for example
network 10.0.12.0 255.255.255.252 area 0. - Believing the network command must match the subnet exactly. It only needs to match the interface address.
- Forgetting that
router ospf 1needs a unique router ID; two routers built from one template end up with the same one. - Expecting
passive-interfaceto hide a network. It still advertises the subnet; it only stops hellos. - Changing the reference bandwidth on one router only.
- Thinking
ip ospf coston one end also changes the cost in the other direction.
💡 Exam tip: be quick at matching network statements to interfaces (wildcard maths), and know both ways to enable OSPF. Expect to read show ip route lines like O 192.168.1.0/24 [110/30] and work out the cost from interface costs, to compute cost from reference bandwidth, and to know that passive-interface stops hellos but keeps advertising. default-information originate produces an O*E2 route on the other routers.
Key takeaways
router ospf <id>starts OSPF; the process ID is local, the router ID must be unique.- Enable interfaces with
network <addr> <wildcard> area 0orip ospf <id> area 0. - Passive interfaces advertise their subnet but send no hellos; use them on LANs.
- Cost = reference bandwidth ÷ interface bandwidth; raise the reference on every router.
default-information originateshares a default route, shown as O*E2 elsewhere.
Check yourself
R1 has Gi0/1 10.0.12.1/30 and the command network 10.0.12.0 0.0.0.3 area 0. Which prefix does R1 advertise for that link?
The reference bandwidth is 10000 Mbps. What is the OSPF cost of a FastEthernet (100 Mbps) interface?
R2's LAN interface Gi0/2 is configured as passive. What happens to 192.168.2.0/24?
R3 has passive-interface default and network statements for both interfaces, but no other commands. What happens with R2?
R1 has default-information originate, but its static default route was removed. What do R2 and R3 see?