The most surprising thing about OSPF and BGP is that they are fundamentally about trust, not just efficiency.
Imagine you’re building a massive city-wide network. You’ve got neighborhoods (Autonomous Systems - ASes) connected by highways (BGP peering). Within each neighborhood, you need local roads (OSPF) to get around.
Here’s OSPF in action:
Let’s say we have two routers, R1 and R2, in the same AS. They’re running OSPF.
R1# show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
192.168.1.2 1 FULL/DR 00:00:35 192.168.1.2 GigabitEthernet0/0
This output tells us R1 sees R2 (Neighbor ID 192.168.1.2) and they’re in the FULL state. This means they’ve exchanged all their Link State Advertisements (LSAs) and have a complete, synchronized view of their local OSPF "neighborhood." DR means R2 is the Designated Router for this segment, a common OSPF optimization to reduce the number of adjacencies.
Now, let’s look at BGP. We have two ASes, AS 100 and AS 200, peering with each other.
AS100-Router# show ip bgp summary
BGP router identifier 1.1.1.1, local AS number 100
BGP table version is 5, main routing table version 5
1 network entries using 144 bytes of memory
3 path entries using 288 bytes of memory
1/1 BGP path/bestpath attribute entries using 80 bytes of memory
1 BGP community entries using 40 bytes of memory
1 BGP extended community entries using 80 bytes of memory
1 BGP route-refresh messages received/sent
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
203.0.113.2 4 65000 10 12 5 0 0 00:15:00 5
This shows AS100-Router is peering with 203.0.113.2 in AS 200. They’ve exchanged 10 and 12 messages, respectively. The Up/Down time indicates they’ve been stable for 15 minutes, and importantly, State/PfxRcd shows 5. This means the neighbor has advertised 5 distinct network prefixes to our router. The AS column shows 65000, indicating the neighbor is in AS 65000.
The Problem They Solve:
OSPF is designed for intra-AS routing. Its goal is to find the fastest path within a single administrative domain. It does this by flooding Link State Advertisements (LSAs) to build a complete map of the network and then running Dijkstra’s shortest path algorithm.
BGP is designed for inter-AS routing. Its goal is not necessarily the fastest path, but the best path based on administrative policies. It’s the glue that holds the internet together, allowing different organizations to exchange reachability information. BGP routers exchange network reachability information (prefixes) and attributes (like AS-Path, MED, Local Preference) that allow for complex policy decisions.
Internal Workings:
- OSPF: Uses Link State Advertisements (LSAs) to describe network topology. Routers flood these LSAs to all other OSPF routers in the same area. Each router builds an identical Link State Database (LSDB) and runs Dijkstra’s algorithm to compute shortest paths. Key concepts: Areas, Router IDs, Network Types, DR/BDR election.
- BGP: Uses TCP port 179. Routers establish peering sessions (neighbors) and exchange network prefixes with their attributes. It’s a path-vector protocol; routers don’t have a full map of the entire internet, but they know the sequence of ASes a prefix has traversed (
AS-Path). Key concepts: eBGP vs. iBGP, AS-Path, Local Preference, MED, Communities, Route Reflectors, Confederations.
Your Levers:
- OSPF:
- Area Design: Splitting a large OSPF domain into multiple areas (e.g., Area 0 as backbone, other areas connecting to it) reduces LSDB size and SPF calculation overhead.
- Cost: Manually setting interface costs influences path selection. Higher cost means less preferred.
ip ospf cost <value> - Timers: Adjusting hello and dead intervals (must match for adjacency).
ip ospf hello-interval <seconds>,ip ospf dead-interval <seconds> - Network Types: Configuring interfaces as broadcast, point-to-point, etc., impacts neighbor discovery and DR/BDR election.
- Summarization: Aggregating routes at area boundaries to reduce the size of routing tables.
- BGP:
- AS-Path Prepending: Artificially lengthening the AS-Path to make a path less preferred for inbound traffic.
set as-path prepend <AS-number> <AS-number> - Local Preference: Influences outbound traffic path selection within an AS (higher is better).
set local-preference <value> - MED (Multi-Exit Discriminator): Influences inbound traffic path selection from a neighboring AS (lower is better).
set metric <value> - Communities: Tagging routes for policy application.
- iBGP Full Mesh/Route Reflectors/Confederations: Scalability solutions for iBGP within an AS.
- AS-Path Prepending: Artificially lengthening the AS-Path to make a path less preferred for inbound traffic.
The real power of BGP lies in its ability to carry policy, not just reachability. When you see a BGP advertisement, you’re not just seeing "this network is available," you’re seeing "this network is available, and here’s the journey it took, and here are the implicit or explicit rules it should follow." A common BGP trick is to use the LOCAL_PREF attribute to influence outbound traffic from your AS to a specific neighbor, making one path more attractive than another, even if both paths have the same AS-Path length. This is often done by setting a higher LOCAL_PREF on routes learned from a preferred peer.
The next challenge is understanding how iBGP scales and the solutions to its inherent limitations.