Sub topic 14
Configuring OSPF on a Small Network
This chapter assumes you know IPv4 addressing and subnet masks, basic router interface configuration, and the difference between static and dynamic routing. It also assumes you have met router IDs, Hello packets, and network types from earlier chapters. Here you put them together in a working configuration.
The Lab Topology
Three routers run a single OSPF area. R1 connects to R2 and R3 over /30 point-to-point links and also serves a user LAN. The configuration below is for R1.
All interfaces are in area 0, so this is a single-area design. Every router is an internal router and also a backbone router.
What You Must Decide Before Typing
Each OSPF configuration answers five questions:
| Decision | Why it matters | Example value |
|---|---|---|
| Process ID | Local only. It does not need to match between routers. | `1` |
| Router ID | Identifies the router in the LSDB. A change requires restarting the process. | `1.1.1.1` |
| Which interfaces run OSPF | An interface sends Hellos and has its subnet advertised only if OSPF is enabled on it. | Gi0/0, Gi0/1, Gi0/2 |
| Area | Must match on both ends of a link. | `0` |
| Cost | Drives path selection. | Default, or manual |
A Complete R1 Configuration
router ospf 1
router-id 1.1.1.1
auto-cost reference-bandwidth 10000
passive-interface GigabitEthernet0/2
!
interface GigabitEthernet0/0
ip address 10.0.12.1 255.255.255.252
ip ospf 1 area 0
ip ospf network point-to-point
!
interface GigabitEthernet0/1
ip address 10.0.13.1 255.255.255.252
ip ospf 1 area 0
ip ospf cost 20
!
interface GigabitEthernet0/2
ip address 192.168.1.1 255.255.255.0
ip ospf 1 area 0Router ID
router-id 1.1.1.1 fixes the ID by hand. Without it, the router uses the highest loopback address, then the highest active interface address. That choice can change when interfaces change, so a fixed ID keeps the LSDB stable. The ID does not need to be a reachable address, but it must be unique in the domain.
Enabling OSPF per interface
ip ospf 1 area 0 under each interface does two things: it starts Hellos on the interface, and it advertises the interface's connected subnet. This is the interface-level method. The older method uses network statements with wildcard masks, such as network 10.0.12.0 0.0.0.3 area 0. The router matches each interface address against those statements. That method is easier to get wrong, because a wildcard that is too broad enables OSPF on more interfaces than you intended.
Cost and the reference bandwidth
OSPF cost is the reference bandwidth divided by the interface bandwidth. The default reference is 100 Mbps. At that value, Fast Ethernet, Gigabit, and 10 Gigabit links all get cost 1, so OSPF cannot tell them apart.
auto-cost reference-bandwidth 10000 sets the reference to 10 Gbps, expressed in Mbps. A Gigabit interface then costs 10. Gi0/0 therefore costs 10 automatically. Gi0/1 has ip ospf cost 20, which overrides the calculation and makes the R1–R3 link less preferred.
Network type
ip ospf network point-to-point on Gi0/0 tells OSPF the link has exactly two routers. No DR or BDR is elected, and adjacency forms faster. Configure the same type on R2's end of the link. Ethernet interfaces default to broadcast, which runs a DR/BDR election even when only two routers are present.
Passive interface
Gi0/2 faces user PCs. passive-interface GigabitEthernet0/2 stops OSPF from sending Hellos there, so no one can form an adjacency through that port. The ip ospf 1 area 0 command on the same interface still advertises 192.168.1.0/24 to the rest of the network. A passive interface advertises its subnet but forms no neighbors.
The Same Design in FRRouting
FRRouting uses a different syntax. The concepts carry over unchanged.
router ospf
ospf router-id 1.1.1.1
network 10.0.12.0/30 area 0
network 192.168.1.0/24 area 0
passive-interface eth2Here network statements use prefix lengths instead of wildcard masks. Any interface whose address falls inside a listed prefix joins the area.
What Must Match for an Adjacency
Two routers on a shared link become neighbors only if these values agree:
- Subnet and mask on the connecting interfaces.
- Area ID.
- Hello and dead timers (defaults: 10 and 40 seconds on broadcast and point-to-point links).
- Authentication type and key, if configured.
- Stub area flags.
Router IDs must be different. Duplicate IDs cause neighbors to flap or LSAs to be rejected. The next chapters cover how to verify these conditions and troubleshoot them.
Applying and Checking the Configuration
Configure R2 and R3 in the same pattern, each with its own router ID, and the matching ip ospf network point-to-point on R2's end of its link to R1. After the Hellos exchange, check the neighbor table and the routes OSPF installed:
show ip ospf neighbor
show ip route ospfOn R1 you should see R2 and R3 as neighbors in state FULL. With point-to-point links, no DR/BDR role appears in that output. The route table lists OSPF routes with code O, each showing the administrative distance 110 and the calculated metric.
Common Configuration Mistakes
- Forgetting the passive interface on the LAN. The router sends Hellos to user devices. This wastes bandwidth and lets an attacker attempt to form an adjacency.
- Making the LAN interface passive but not enabling OSPF on it. The adjacency problem goes away, but the LAN subnet never gets advertised.
- Changing the router ID and expecting immediate effect. The new ID applies only after the OSPF process restarts, for example with
clear ip ospf process. - Mismatched network types. Broadcast on one end and point-to-point on the other can still form an adjacency. The two ends then behave differently, which leads to missing or unstable routes.
- Mixing
ip ospfinterface commands andnetworkstatements and losing track of which one enabled an interface.
Exercise
R1's Gi0/2 is passive and has ip ospf 1 area 0. A user plugs a laptop running OSPF into that port. Will R1 form an adjacency with it, and will R2 learn the 192.168.1.0/24 subnet?
Show answer
R1 will not form an adjacency, because a passive interface sends no Hellos and ignores received ones. R2 will still learn 192.168.1.0/24, because OSPF is enabled on the interface and the subnet is advertised in R1's router LSA.
Exercise
R1's Gi0/0 and Gi0/1 are both Gigabit. With the reference bandwidth set to 10000 and the configuration above, what cost does R1 use for each link? Which link do R1's routes prefer if R2 and R3 each also have a direct link to a destination at equal cost beyond them?
Show answer
Gi0/0 costs 10 (10000 / 1000 Mbps). Gi0/1 costs 20 because of the manual ip ospf cost 20. The R1–R2 link is preferred, since the path through it has the lower total cost.