Cost
OSPF's metric is cost. Each interface has a cost; a route's cost is the total of the outgoing interfaces along the path. By default:
cost = reference bandwidth / interface bandwidth, with a reference of 100 Mb/s
| Interface | Bandwidth | Cost (reference 100) | Cost (reference 10000) |
|---|---|---|---|
| FastEthernet | 100 Mb/s | 1 | 100 |
| GigabitEthernet | 1 Gb/s | 1 (can't go below 1) | 10 |
| 10 Gigabit | 10 Gb/s | 1 | 1 |
With the default reference, every link of 100 Mb/s or faster costs 1, so OSPF can't tell them apart. Raise the reference on every router: auto-cost reference-bandwidth 10000 (in Mb/s). Or set a cost on one interface: ip ospf cost 50.
Equal-cost paths
If two paths have the same total cost, OSPF installs both and shares the traffic (up to 4 paths, maximum-paths). Here R1 reaches R3's LAN directly (cost 2). Make that link expensive and the path goes round through R2:
In NetLab
▶ R1 R1>enable R1#show ip route 192.168.3.10 Routing entry for 192.168.3.0/24 Known via "ospf 1", distance 110, metric 2, type intra area Last update from 10.0.13.2 on GigabitEthernet0/2, 00:00:02 ago Routing Descriptor Blocks: * 10.0.13.2, from 3.3.3.3, 00:00:02 ago, via GigabitEthernet0/2 Route metric is 2, traffic share count is 1 R1#configure terminal Enter configuration commands, one per line. End with CNTL/Z. R1(config)#interface g0/2 R1(config-if)#ip ospf cost 50 R1(config-if)#end *Mar 1 00:00:06.000: %SYS-5-CONFIG_I: Configured from console by console R1#show ip route 192.168.3.10 Routing entry for 192.168.3.0/24 Known via "ospf 1", distance 110, metric 3, type intra area Last update from 10.0.12.2 on GigabitEthernet0/1, 00:00:02 ago Routing Descriptor Blocks: * 10.0.12.2, from 3.3.3.3, 00:00:02 ago, via GigabitEthernet0/1 Route metric is 3, traffic share count is 1
Sharing a default route
R1 is the only router with an internet link, and it has a static default route to the ISP. default-information originate tells OSPF to advertise that default route to everyone. The others learn it as O*E2 (an external route, type 2):
In NetLab
▶ R1 R1>enable R1#configure terminal Enter configuration commands, one per line. End with CNTL/Z. R1(config)#router ospf 1 R1(config-router)#default-information originate R1(config-router)#end *Mar 1 00:00:05.000: %SYS-5-CONFIG_I: Configured from console by console ▶ R2 R2>enable R2#show ip route ospf | begin Gateway Gateway of last resort is 10.0.12.1 to network 0.0.0.0 O*E2 0.0.0.0/0 [110/1] via 10.0.12.1, 00:00:03, GigabitEthernet0/0 1.0.0.0/32 is subnetted, 1 subnets O 1.1.1.1 [110/2] via 10.0.12.1, 00:00:07, GigabitEthernet0/0 3.0.0.0/32 is subnetted, 1 subnets O 3.3.3.3 [110/2] via 10.0.23.2, 00:00:07, GigabitEthernet0/1 10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks O 10.0.13.0/30 [110/2] via 10.0.12.1, 00:00:07, GigabitEthernet0/0 [110/2] via 10.0.23.2, 00:00:07, GigabitEthernet0/1 O 192.168.1.0/24 [110/2] via 10.0.12.1, 00:00:07, GigabitEthernet0/0 O 192.168.3.0/24 [110/2] via 10.0.23.2, 00:00:07, GigabitEthernet0/1 R2#ping 8.8.8.8 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 8.8.8.8, timeout is 2 seconds: ..!!! Success rate is 60 percent (3/5), round-trip min/avg/max = 1/1/1 ms
Remember: Lower cost wins. Cost = reference / bandwidth, so raise the reference on all routers.
default-information originateshares a default route; addalwaysto send it even when the router has none itself.