Guided buildadvanced7 steps~25 min5 devices
Steer OSPF with link cost
Give OSPF two paths between two sites, watch it choose the cheaper one over the shorter one, then re-rate a link and watch the route move.
What you'll be able to do: Three routers and two working paths between head office and the branch: OSPF sends traffic over the lowest total cost, re-rating one circuit moved the route onto it in both directions, and the detour through the data centre stays in every router's map as the backup.
Topics: OSPF · OSPF cost · Link-state routing · Routing tables · WAN links
What you'll build
- HQ — a router, the head-office router
- PC-HQ — a pc, a workstation at head office
- Branch — a router, the branch-office router
- PC-Branch — a pc, a workstation at the branch
- DC — a router, the data-centre router both sites have fibre to
Step by step
1. Stand up head office
Drag a router and a PC onto the canvas, cable the PC into Gi0/0, name the router HQ and give that port the head-office gateway address. The sites in this build are deliberately plain: the lesson is how OSPF chooses between two working paths, not how to build a LAN.
- Cable PC-HQ Eth0 ↔ HQ Gi0/0
On HQ — Name the router and address the head-office LAN port
enable configure terminal hostname HQ interface Gi0/0 ip address 192.168.10.1 255.255.255.0 no shutdown exit endOn PC-HQ — Name the workstation and set address, mask and gateway
hostname PC-HQ ipconfig Eth0 192.168.10.10 255.255.255.0 192.168.10.1Check: run
show ip routeon HQ and look forC 192.168.10.0/24 is directly connected, Gi0/0.Why: A connected network is the one kind of route a router never has to learn: the port is in the subnet, so the subnet is in the table. It still carries an OSPF cost — the cost of that port — and by the end of this build that number decides where traffic goes.
2. Stand up the branch
The same again at the branch: a second router named Branch, a PC on Gi0/0, and a different subnet. Two islands for now — each router knows only the network plugged into it.
- Cable PC-Branch Eth0 ↔ Branch Gi0/0
On Branch — Name the branch router and address its LAN port
enable configure terminal hostname Branch interface Gi0/0 ip address 192.168.20.1 255.255.255.0 no shutdown exit endOn PC-Branch — Name the branch workstation and point it at its gateway
hostname PC-Branch ipconfig Eth0 192.168.20.10 255.255.255.0 192.168.20.1Check: run
show ip routeon Branch and look forC 192.168.20.0/24 is directly connected, Gi0/0.Why: Routers move packets between subnets, so each site gets its own. Neither router knows the other site exists yet — that knowledge is exactly what OSPF is about to supply.
3. Join the sites with a leased line and start OSPF
Run a serial cable between the two routers' Se0/0/0 ports — the leased line, a direct circuit between the sites — and number it 10.0.12.0/30. Start OSPF on both routers with both of their networks in area 0. The route to the other site appears marked O, with a cost of 65.
- Cable HQ Se0/0/0 ↔ Branch Se0/0/0 (serial)
On HQ — Address HQ's end of the leased line and advertise both networks
enable configure terminal interface Se0/0/0 ip address 10.0.12.1 255.255.255.252 no shutdown exit router ospf 1 router-id 1.1.1.1 network 192.168.10.0 0.0.0.255 area 0 network 10.0.12.0 0.0.0.3 area 0 endOn Branch — Address the branch end and advertise its networks into the same area
enable configure terminal interface Se0/0/0 ip address 10.0.12.2 255.255.255.252 no shutdown exit router ospf 1 router-id 2.2.2.2 network 192.168.20.0 0.0.0.255 area 0 network 10.0.12.0 0.0.0.3 area 0 endOn PC-HQ — Cross the leased line
ping 192.168.20.10Check: run
show ip routeon HQ and look forO 192.168.20.0/24 [110/65] via 10.0.12.2, Se0/0/0.Why: OSPF's metric is cost, and each interface's cost is a 100 Mbps reference divided by the interface's bandwidth. A serial port assumes it is a 1.544 Mbps T1, so it costs 64 (100000 / 1544, with the fraction dropped); a path's total is the sum of the costs of every interface the traffic leaves by, the last one being the port onto the destination LAN.
4. Add the data centre — and watch the route leave the direct link
Both sites also have gigabit fibre to a regional data centre. Place a third router named DC, cable HQ Gi0/1 to DC Gi0/0 and DC Gi0/1 to Branch Gi0/1, and bring both new /30s into OSPF. Then read HQ's table: the route to the branch has moved off the direct line and onto the two-hop path through DC.
- Cable HQ Gi0/1 ↔ DC Gi0/0
- Cable DC Gi0/1 ↔ Branch Gi0/1
On DC — Name the data-centre router, address both fibre links and run OSPF on them
enable configure terminal hostname DC interface Gi0/0 ip address 10.0.13.2 255.255.255.252 no shutdown exit interface Gi0/1 ip address 10.0.23.1 255.255.255.252 no shutdown exit router ospf 1 router-id 3.3.3.3 network 10.0.13.0 0.0.0.3 area 0 network 10.0.23.0 0.0.0.3 area 0 endOn HQ — Bring HQ's fibre link to DC into OSPF
enable configure terminal interface Gi0/1 ip address 10.0.13.1 255.255.255.252 no shutdown exit router ospf 1 network 10.0.13.0 0.0.0.3 area 0 endOn Branch — Bring Branch's fibre link to DC into OSPF
enable configure terminal interface Gi0/1 ip address 10.0.23.2 255.255.255.252 no shutdown exit router ospf 1 network 10.0.23.0 0.0.0.3 area 0 endCheck: run
show ip routeon HQ and look forO 192.168.20.0/24 [110/3] via 10.0.13.2, Gi0/1.Why: Every OSPF router in the area holds the same map and runs a shortest-path calculation over it, keeping only the cheapest path to each prefix. Hop count plays no part: two gigabit hops at a total of 3 beat one T1 hop at 65, which is why adding a link can move traffic you never touched.
5. Read the costs before you change them
Change nothing yet — look. `show ip ospf interface` on HQ lists every OSPF interface with the cost it adds to a path: Se0/0/0 says 64, Gi0/1 says 1. The leased line still has a FULL neighbour on it; OSPF knows that path perfectly well, it just is not the cheapest.
On HQ — Read the cost of every OSPF interface on HQ
enable show ip ospf interfaceCheck: run
show ip ospf interfaceon HQ and look forRouter ID 1.1.1.1, Cost: 64.Why: The per-interface cost is the knob. Change it and every path that leaves through that interface gets cheaper or dearer, on every router whose shortest path crosses it — no route is ever typed by hand.
6. The leased line got faster — tell HQ
The carrier has upgraded the leased line to 100 Mbps, but a serial port keeps assuming 1.544 Mbps until it is told otherwise. On HQ, label the circuit and set its real bandwidth in kilobits per second. SPF reruns at once, the port's cost drops from 64 to 1, and HQ's route to the branch moves back onto the direct link at a total of 2.
On HQ — Label HQ's end of the circuit and give it its real bandwidth
enable configure terminal interface Se0/0/0 description Leased line to Branch - 100 Mbps bandwidth 100000 endCheck: run
show ip routeon HQ and look forO 192.168.20.0/24 [110/2] via 10.0.12.2, Se0/0/0.Why: `bandwidth` is what the router's protocols believe a link is worth, and OSPF divides its 100 Mbps reference by it: 100,000 kbps gives cost 1. Until the far end is re-rated too, traffic to the branch leaves by the leased line while replies return through DC — asymmetric routing, which works but makes captures confusing and trips up stateful firewalls.
7. Tell Branch the same thing
Re-rate the far end so both routers price the line the same way. Branch's route to head office moves onto the leased line as well, and traffic now leaves and returns on the same path. DC keeps both of its FULL neighbours: the detour is still in every router's map, ready if the leased line fails.
On Branch — Label Branch's end of the circuit and give it the same bandwidth
enable configure terminal interface Se0/0/0 description Leased line to HQ - 100 Mbps bandwidth 100000 endOn PC-Branch — Reach head office over the re-rated line
ping 192.168.10.10Check: run
show ip routeon Branch and look forO 192.168.10.0/24 [110/2] via 10.0.12.1, Se0/0/0.Why: A tidy OSPF design gives each link the same cost at both ends, so a path is chosen once and used in both directions. Nothing was deleted to move the traffic: the path through DC is still costed at 3 in every table's calculation, which is what makes it an instant backup.
The theory behind it
More in Routing
- Static routes across a WAN — Join three sites with point-to-point WAN links and route between them by hand, one line at a time.
- RIP: routing by counting hops — Chain three routers over two serial links and let RIP version 2 teach every router the way to every network, counting the hops as it goes.
- Two routers that learn the network — Join two sites over a WAN link, then let OSPF fill in the routing tables that you would otherwise type by hand.
- A backup link that waits its turn — Run two sites over a fast primary link, park a floating static route on a slow standby line, then pull the primary and watch the backup carry the traffic.
- Share one default route with OSPF — Give the edge router a default route to the provider, then let OSPF hand it to the rest of the campus instead of typing it on every router.
- EIGRP across three routers — Join two sites through a hub with EIGRP, find why one router learns nothing, then add a direct link and watch EIGRP choose speed over hop count.
Build it for real
The lab walks you through these steps and ticks each one off as your network starts working.
Open in the lab