OSPF Made Simple: What It Is, How It Works, and How to Configure It

PitsPits
43 min read

If you’re learning networking and starting to dive into dynamic routing protocols, OSPF can feel a bit overwhelming at first. It’s not as straightforward as RIP, and it comes with a bunch of new terms like LSAs, LSDB, areas, and cost metrics. But once you break it down and get some hands-on practice, it all starts to click.

In this post, I’ll walk you through the basics of OSPF in a way that’s easy to understand even if you're just getting started. We’ll cover what OSPF is, how it forms neighbor relationships, what those LSAs actually mean, how to configure it on Cisco routers, and how to verify that everything's working.

This isn’t a professional guide. It’s just me sharing what I’ve learned while studying for CCNA. So if you’re looking for a simple, practical explanation of OSPF without the fluff, you’re in the right place.

Let’s get into it.


Before we get into OSPF itself, it helps to understand what kind of routing protocol it is. Routing protocols are generally grouped into two types: distance vector and link-state. You might have already seen or worked with RIP, which is a distance vector protocol. It makes decisions based on how many hops away a destination is.

OSPF, on the other hand, is a link-state routing protocol. That means instead of just counting hops, it looks at the overall state of the network like the speed of links and how everything is connected to figure out the best path. This gives OSPF a more complete view of the network, which leads to faster, more efficient routing decisions.


Link-state routing protocols, like OSPF and IS-IS, work by having routers share information about their direct connections (or links) with every other router in the network. Each router builds a complete map of the network in its memory and then uses an algorithm (like Dijkstra’s) to calculate the shortest path to every destination.

  • Faster convergence: When there's a change in the network (like a link going down), link-state protocols update quickly. Routers re-calculate the best path right away, which helps avoid downtime.

  • More accurate routing: Since each router has a full picture of the network, it can make smarter decisions based on real link costs not just hop counts.

  • Scalability: Link-state protocols are better at handling larger and more complex networks. That’s one reason why OSPF is used in many enterprise environments.

  • More resource usage: Because each router keeps a full map of the network and processes more detailed info, it needs more CPU and memory compared to distance vector protocols.

  • More complex to configure: There’s a bit more to learn and set up with link-state protocols, especially when dealing with areas and design decisions in larger networks.

  • Initial flooding: When a router first joins the network, it has to flood its link-state information to others and receive the same from them, which can cause a temporary spike in bandwidth use.

Still, despite these downsides, the benefits often outweigh the cons especially when you need a stable and efficient network.


Open Shortest Path First

Now that we know what link-state routing protocols are and why they’re useful, let’s talk about one of the most popular ones; OSPF.

So, what exactly is OSPF?

OSPF, or Open Shortest Path First, is a link-state routing protocol used to help routers find the best path for data within a network. It's designed for use inside a single organization or autonomous system (AS) and is a big step up from older protocols like RIP. OSPF doesn’t just count how many hops away a network is, it looks at the actual cost of each link, usually based on bandwidth, to make smarter routing decisions.

OSPF Versions

There are three versions of OSPF:

  1. OSPFv2 – Used for IPv4 networks. This is the most common version.

  2. OSPFv3 – Made for IPv6, but it works in a similar way to OSPFv2.

  3. OSPF for MPLS/Traffic Engineering – A more advanced version used in specialized networks. Not something you need to worry about when starting out.

How OSPF Shares and Stores Information

Routers running OSPF don’t just send route updates, they actually share detailed information about the state of their network connections. Here’s how that works:

Each OSPF router creates small pieces of information called LSAs, or Link-State Advertisements. You can think of an LSA like a report card a router sends out to its neighbors. It says things like:

  • “I’m connected to these networks”

  • “These are my neighbor routers”

  • “Here’s the cost of reaching those networks from my end”

These LSAs are then shared, or flooded, throughout the OSPF area so that every router ends up with the same complete view of the network.

All the LSAs that a router receives are stored in a database called the Link-State Database, or LSDB. This is basically the router’s map of the network. Each router has its own LSDB, but if everything is working right, all routers in the same area will have identical copies of it.

Once the LSDB is built, OSPF uses the Shortest Path First (SPF) algorithm, also known as Dijkstra’s algorithm, to calculate the best paths through the network. The results of this calculation go into the routing table, which the router uses to forward traffic.

So, to sum it up:

  • Routers share LSAs to tell each other what they see

  • All LSAs are stored in the LSDB

  • OSPF uses that database to calculate the best paths using the SPF algorithm


Example: LSA Flooding in Action

Let’s use the same network diagram we used in the RIP and EIGRP blogs. Imagine three routers; R1, R2, and R3 connected in a triangle. Each router is connected to a different network, and they all run OSPF in the same area (Area 0).

Network Diagram shows 2 PCs, 2 Switches, and 3 Routers connected to each other.

When OSPF starts up, each router sends out LSAs to let the others know what networks it's directly connected to and who its neighbors are.

Here’s what happens step-by-step:

  1. Flooding the LSAs:
    Let’s say R1 starts first. It creates a Type 1 LSA (also called a Router LSA), which includes info like:

    • “I’m R1.”

    • “I’m connected to network 192.168.1.0/24.”

    • “I have a neighbor connection to R2.”

R1 sends this LSA to R2. Once R2 receives it, it adds it to its LSDB and immediately forwards it to R3. That’s how flooding works. Each router passes the LSAs to its neighbors except the one it got it from. This continues until all routers have the same set of LSAs in their LSDB.

  1. Building the LSDB:
    As routers exchange LSAs, they build their Link-State Database (LSDB). This database stores all the information received from the network, not just direct neighbors. So even if R1 doesn’t talk to R3 directly, it will still learn about R3’s network and connections through R2’s flooded LSAs.

  2. Running the SPF Algorithm:
    Once each router has a complete LSDB, they run the Shortest Path First (SPF) algorithm. This algorithm uses the network map (LSDB) to calculate the most efficient path to reach every network. These best paths are then added to the routing table, and the router is ready to forward packets based on the shortest and lowest-cost routes.

What About Aging and Timers?

LSAs don’t live forever. To keep the network updated and avoid using old info, each LSA has an age value. Here’s how that works:

  • LSA Age Timer: Every LSA has a counter that increases over time. When it reaches MaxAge (3600 seconds or 1 hour), the LSA is considered too old and gets removed unless a refreshed version is received.

  • Refresh Timer: Even if nothing changes, routers will re-flood LSAs every 30 minutes by default to keep the LSDB fresh.

  • LSA Retransmission Timer: If a router doesn’t get an acknowledgment from its neighbor after sending an LSA, it will retransmit the LSA after a short delay (default is 5 seconds).

These timers make sure that OSPF routers are always working with accurate, up-to-date information.

So, to sum it up:

  • OSPF routers flood LSAs to share what they know.

  • The LSAs are stored in the LSDB, creating a full network map.

  • Each router runs SPF to calculate the best path, and aging timers make sure nothing goes stale.


Now that we’ve seen how OSPF routers flood LSAs and build their network map, you might be wondering what happens when the network gets bigger?

As more routers and links are added, the number of LSAs flying around increases, and the LSDBs can get pretty large. To keep things organized and avoid overwhelming the routers, OSPF divides the network into smaller sections called areas.


What Are OSPF Areas?

An OSPF area is a logical grouping of routers that helps keep the network efficient and easier to manage. Inside an area, routers exchange LSAs and build their own copy of the LSDB. But routers don’t share every single detail with routers outside their area. This helps limit the amount of information each router has to handle.

You can think of areas like neighborhoods in a city. Each one manages its own local roads, but only shares the main roads that connect it to other areas.

Why Use Areas?

Here are a few reasons OSPF uses areas, especially in large networks:

  • Reduces LSDB size: Routers only store detailed information about their own area, which saves memory and processing power.

  • Limits LSA flooding: LSAs are mostly kept within an area, so changes in one area don’t overwhelm the whole network.

  • Improves stability: Issues in one area (like flapping links) won’t affect the others.


Types of OSPF Areas

Here are the basic types of areas you'll come across:

  1. Backbone Area (Area 0):
    This is the main area in every OSPF network. All other areas must connect to Area 0, either directly or through a virtual link. It acts like a central hub that links all the other areas together.

  2. Standard Areas (non-backbone):
    These areas connect to the backbone and exchange summarized routes with it. Inside the area, routers still flood Type 1 and Type 2 LSAs, but between areas, only summarized routes are passed.

  3. Special Areas (we’ll keep it simple here):
    There are areas like Stub, Totally Stubby, and NSSA (Not-So-Stubby Area) that are used to block certain LSAs and reduce complexity even more. These are helpful in specific scenarios, especially when you don’t want a small area to deal with external route information.


Why Do We Use OSPF Areas?

When you’re working with a small network, using one area (called a single-area design) is simple and works just fine. All routers are in the same area, they all share the same LSDB, and things are easy to manage.

But as the network grows, that single area can become a problem.

Pros of a Single-Area Design:

  • Simple to set up – No need to divide routers or links into different areas.

  • All routers see the full picture – Every router knows about all networks and links.

  • Good for small networks – With just a few routers, the LSDB stays small and manageable.

Cons of a Single-Area Design in Large Networks:

  • Large LSDB – As more routers and networks are added, the LSDB grows and uses more memory and CPU.

  • More frequent SPF calculations – A change in one link (even far away) can cause all routers to recalculate their SPF tree.

  • More LSA flooding – Every LSA is shared with every router, even if it’s not relevant to them.

To solve these problems, OSPF uses a multi-area design. By dividing the network into smaller areas, routers only need to care about what's in their own area. This keeps things efficient, reduces the size of the LSDB, and limits the scope of LSA flooding.


Understanding OSPF Areas

  • An OSPF area is a group of routers and links that share the same LSDB. Inside an area, routers know everything about each other’s links and networks.

  • The backbone area, also known as Area 0, is the core of every OSPF network. All other areas must connect to Area 0 either directly or through a virtual link so OSPF can route traffic properly between areas.

    Image show the backbone area highlighted by a red square. Credits to the owner of this image : https://www.jeremysitlab.com/

  • Routers that have all their interfaces inside the same area are called internal routers.

    Image show the internal routers highlighted by a red square. Credits to the owner of this image : https://www.jeremysitlab.com/

  • Routers with interfaces in two or more areas are called Area Border Routers (ABRs).

    • ABRs maintain a separate LSDB for each area they’re connected to.

    • It’s recommended to connect an ABR to no more than two areas, since more than that can put extra load on the router and make the design harder to manage.

      Image show the ABRs highlighted by a red square. Credits to the owner of this image : https://www.jeremysitlab.com/

  • Routers that are connected to Area 0 are called backbone routers. These can be internal routers or ABRs, as long as they have an interface in the backbone.

    Image show the backbone routers highlighted by a red square. Credits to the owner of this image : https://www.jeremysitlab.com/

  • An intra-area route is a route to a destination inside the same area.

    Image show the intra-area routes highlighted by a red square. Credits to the owner of this image : https://www.jeremysitlab.com/

  • An interarea route is a route to a destination in a different area. Routers learn these routes through ABRs, which summarize and share route info between areas.

    Image show the interarea routes highlighted by a red square. Credits to the owner of this image : https://www.jeremysitlab.com/

  • OSPF areas must be contiguous, meaning the routers in an area should be connected without gaps. You shouldn’t have an area split across the network with unrelated areas in between.

    • The image below shows that areas are contiguous.

      Image show the example of contiguous. Credits to the owner of this image : https://www.jeremysitlab.com/

    • And the image below is not contiguous. It is not allowed in OSPF.

      Image show the example of a not contiguous area highlighter in red square. Credits to the owner of this image : https://www.jeremysitlab.com/

  • Every OSPF area must have at least one ABR connected to Area 0. If it doesn’t, routers in that area won’t be able to reach destinations in other areas.

    Image show the example of a router of different areas connected to area 0 highlighted in red square. Credits to the owner of this image : https://www.jeremysitlab.com/

  • If two OSPF interfaces are in the same subnet, they must also be in the same area. OSPF won’t form a neighbor relationship if the area numbers don’t match.

Image show the example of one router that is not in area 0 highlighted in green square. Credits to the owner of this image : https://www.jeremysitlab.com/


Now that we understand how OSPF areas work and why they’re important, let’s move on to the basic configuration.

In this setup, we’ll keep things simple by placing all routers in Area 0, which is the backbone area. I’ll break down the configuration for each router step by step, including the IP addresses used on each interface, so it’s easy to follow and apply if you’re working on a lab or simulation.

Image shows the network diagram that we will use to demo the OSPF Configuration. It consist of 3 routers, 2 switches, and 2 PCs.

  • PC1 → SW1 → R1

    • PC1: 192.168.1.1/24

    • R1 (to SW1): 192.168.1.254/24

  • PC2 → SW2 → R3

    • PC2: 192.168.2.1/24

    • R3 (to SW2): 192.168.2.254/24

  • R1 ↔ R2

    • R1 G0/0: 10.0.11.1/30

    • R2 G0/0: 10.0.11.2/30

  • R2 ↔ R3

    • R2 G0/1: 10.0.12.2/30

    • R3 G0/0: 10.0.12.1/30


Configuring OSPF on a router isn’t too complicated once you understand the purpose behind each command. In this part, we’ll go over the core commands used in basic OSPF setup, explain what they do, and why they matter. Since OSPF behaves differently from protocols like RIP or EIGRP, it’s important to understand how it decides which interfaces participate, how neighbors are formed, and how networks are advertised.

Let’s break down the main configuration commands:

router ospf [process-id]

This command starts the OSPF process on the router. The process-id is a number you assign. It’s locally significant, meaning it doesn’t have to match other routers in the network.

R1(config)# router ospf 1

This tells the router to start OSPF process 1. You can use any number (like 10, 100, etc.), but most people just use 1 for simplicity.

network [network-address] [wildcard-mask] area [area-id]

This command tells OSPF which interfaces should participate in the process and what area they belong to. It doesn’t advertise the network the way RIP does. Instead, it matches interface IPs, and if the IP falls within the given network + wildcard, that interface is added to OSPF.

R1(config-router)# network 10.0.11.0 0.0.0.3 area 0

Here’s what’s happening:

  • 10.0.11.0 is the subnet where R1 and R2 connect.

  • 0.0.0.3 is the wildcard mask, which is the inverse of a subnet mask (/30 = 255.255.255.252 → wildcard 0.0.0.3)

  • area 0 means the matched interface will belong to Area 0.

So this command looks at all of R1’s interfaces and checks: “Is the IP address within 10.0.11.0/30?” If yes, OSPF is enabled on that interface.

You’ll repeat this for each network or interface you want OSPF to run on.

passive-interface [interface]

By default, when OSPF is enabled on an interface, the router sends Hello packets to try and form a neighbor relationship. But not all interfaces should be forming OSPF neighbors like the one facing a PC or a switch (LAN interface).

The passive-interface command tells OSPF:
"Advertise this network, but don’t send Hello packets on this interface."

R1(config-router)# passive-interface GigabitEthernet0/1

This is useful when:

  • An interface is connected to end devices like PCs or switches.

  • You don’t want OSPF neighbor relationships forming there.

  • You still want the network advertised to the rest of the OSPF domain.

If you want to make all interfaces passive by default and just allow a few to send Hellos, you can use:

R1(config-router)# passive-interface default
R1(config-router)# no passive-interface GigabitEthernet0/0

Advertising a Default Route in OSPF

In some networks, especially smaller ones, you may want to tell all other routers to send unknown traffic (like internet-bound traffic) to one main router usually the one connected to the internet. This is done by advertising a default route through OSPF.

Let’s say R1 is connected to the internet, and we want R2 and R3 to use it as their gateway for all traffic going outside the network.

Step 1: Create a static default route on R1

R1(config)# ip route 0.0.0.0 0.0.0.0 [next-hop or exit-interface]

For example:

R1(config)# ip route 0.0.0.0 0.0.0.0 192.168.1.1

This tells R1, “Send all unknown traffic to the internet via PC1.”

Step 2: Tell OSPF to advertise that default route

R1(config)# router ospf 1
R1(config-router)# default-information originate

This tells OSPF, “Hey, I have a default route. Let me share it with everyone else.”

Now R2 and R3 will receive the default route via OSPF and know to send internet traffic through R1.


What Is an ASBR?

When a router shares routes from outside OSPF like a static route, another routing protocol, or a default route, it becomes an ASBR (Autonomous System Boundary Router).

In this case, R1 becomes an ASBR because it’s injecting a static default route into OSPF. The command default-information originate triggers that behavior.


Verifying OSPF: show ip protocols

Use this command to check:

  • OSPF process ID

  • Router ID

  • Networks being advertised

  • If default information is being originated

  • Administrative distance

  • Maximum paths allowed

R1# show ip protocols

Useful to confirm:

  • OSPF is running

  • Interfaces involved

  • Routes being shared

  • Whether a default route is advertised


Understanding the Router ID (RID)

The Router ID is a unique identifier for each OSPF router. It’s a 32-bit number that looks like an IP address but doesn’t need to be routable.

OSPF uses the router ID:

  • To identify each router in the LSDB

  • In neighbor relationships

  • In SPF calculations

Router ID Selection Order (Priority):

  1. Manually configured RID (using router-id command)

  2. Highest IP on a loopback interface

  3. Highest IP on an active physical interface

If no interfaces are up, OSPF won't start.

You can set it manually like this:

R1(config)# router ospf 1
R1(config-router)# router-id 1.1.1.1

If OSPF is already running, you'll need to reset the process for the change to take effect.


Clearing the OSPF Process

When you change something like the router ID after OSPF is already running, you need to restart the OSPF process for the change to apply:

R1# clear ip ospf process

This resets OSPF neighbors and forces the router to re-run SPF and build its LSDB again.

Use with caution in live networks, as it causes a brief loss of routing.


OSPF Maximum Paths and Distance

maximum-paths

OSPF supports equal-cost load balancing. By default, it can install up to 4 equal-cost paths to the same destination.

You can change this with:

R1(config-router)# maximum-paths 6

This tells the router, “Install up to 6 equal-cost routes in the routing table.”

distance

OSPF has a default administrative distance of 110, which defines how trusted the route is.

You can manually change this if needed:

R1(config-router)# distance 100

Lower distance values make the protocol more preferred, but changing OSPF’s distance is rarely needed unless you're doing advanced route control.

Summary of What You’ve Learned in This Section:

CommandPurpose
router ospf [id]Starts the OSPF process
network [ip] [wildcard] area [x]Enables OSPF on matching interfaces
passive-interfaceAdvertises network but disables Hello packets
default-information originateInjects a default route into OSPF
show ip protocolsVerifies OSPF status and settings
router-idSets the router’s unique OSPF identifier
clear ip ospf processRestarts the OSPF process
maximum-pathsAllows load balancing across equal-cost routes
distanceAdjusts OSPF administrative distance

Now that we’ve configured OSPF and looked at how routers share routes and build their LSDB, there’s one more important piece that influences how OSPF chooses the best path and that’s cost.

In OSPF, cost isn’t based on the number of hops like RIP or metrics like bandwidth and delay in EIGRP. Instead, OSPF uses cost values to figure out the shortest and most efficient path to a destination. Let’s take a closer look at how OSPF calculates cost, how you can influence it, and why it matters when there’s more than one possible route.


What Is OSPF Cost?

In OSPF, the cost is the metric used to determine the "shortest" or most preferred path to a destination. Unlike RIP, which simply counts hops, OSPF is more flexible and looks at link speed (bandwidth) to make routing decisions.

The lower the cost, the more preferred the path.


How OSPF Calculates Cost

OSPF calculates cost using this formula:

Cost = Reference Bandwidth / Interface Bandwidth

By default, the reference bandwidth is 100 Mbps (or 100,000,000 bits per second).

Let’s say you have a FastEthernet link (100 Mbps). The calculation would be:

Cost = 100,000,000 / 100,000,000 = 1

But if you’re using a slower link, like 10 Mbps:

Cost = 100,000,000 / 10,000,000 = 10

So a 10 Mbps link will have a cost of 10, and a 100 Mbps link will have a cost of 1. OSPF will naturally prefer the path with a lower cost.


Example:

Imagine you have two possible paths from R1 to R3:

  • Path A: Goes through two 100 Mbps links

  • Path B: Goes through one 10 Mbps link

PathCost CalculationTotal Cost
A1 (100 Mbps) + 1 (100 Mbps)2
B10 (10 Mbps)10

Even though Path B might look shorter in hops, OSPF chooses Path A because it has the lower total cost.


Why You Should Change the Reference Bandwidth

The default reference bandwidth of 100 Mbps was fine when FastEthernet was the standard. But today, many networks use Gigabit or even 10-Gigabit links. If you don’t update the reference bandwidth, OSPF will treat both 100 Mbps and 1 Gbps links with the same cost of 1, which can lead to poor path decisions.

To fix that, use the following command under OSPF config mode:

R1(config-router)# auto-cost reference-bandwidth 1000

This changes the reference bandwidth to 1000 Mbps (1 Gbps).

Now the same cost calculation looks like this:

  • For 1 Gbps (1,000,000,000 bps):
    1000000000 / 1000000000 = 1

  • For 100 Mbps:
    1000000000 / 100000000 = 10

This allows OSPF to better differentiate between fast and slow links.

Important: This command should be applied to all routers in the OSPF domain. If not, cost calculations may be inconsistent, which can lead to routing problems.


show ip ospf interface Command

The show ip ospf interface command is used to check OSPF settings and status per interface. It shows detailed information about each interface where OSPF is running.

Here’s the basic syntax:

R1# show ip ospf interface

You can also focus on a specific interface:

R1# show ip ospf interface GigabitEthernet0/0

What You’ll See and What It Means

Here are the key details you’ll get from this command:

Interface

Shows the interface name (like GigabitEthernet0/0) that is participating in OSPF.

IP Address

Displays the IP address assigned to that interface.

Area

Shows which OSPF area this interface belongs to (like Area 0).

Cost

Shows the OSPF cost of this interface. This cost is used in SPF calculations to choose the best path.

State

Displays the OSPF interface state, such as:

  • DR (Designated Router)

  • BDR (Backup Designated Router)

  • DROTHER (neither DR nor BDR)

This tells you the role of the router in the multi-access network (like Ethernet).

Hello and Dead Intervals

These are OSPF timers:

  • Hello interval – how often OSPF sends Hello packets (default: 10 seconds for broadcast links)

  • Dead interval – how long OSPF waits before declaring a neighbor down (default: 40 seconds)

These must match between neighbors or adjacency won’t form.

Neighbor Count

Shows how many OSPF neighbors are detected on that interface.

MTU (Maximum Transmission Unit)

Mismatch in MTU can also prevent OSPF neighbors from forming, so it’s helpful to verify this here.


Why This Command Is Useful

  • Confirms if OSPF is running on the interface.

  • Shows which area the interface belongs to.

  • Helps verify cost, timers, and neighbor info.

  • Useful for troubleshooting when neighbor relationships aren't forming.


Example Output (Simplified)

GigabitEthernet0/0 is up, line protocol is up
  Internet Address 10.0.11.1/30, Area 0
  Process ID 1, Router ID 1.1.1.1, Network Type BROADCAST, Cost: 1
  Transmit Delay is 1 sec, State DR, Priority 1
  Designated Router (ID) 1.1.1.1
  Backup Designated Router (ID) 2.2.2.2
  Timer intervals: Hello 10, Dead 40, Wait 40, Retransmit 5
  Neighbor Count is 1

From this, we can tell:

  • The interface is active and in Area 0.

  • The router is the DR.

  • It has one neighbor.

  • The Hello and Dead timers are set correctly.

Image show using the command show ip ospf interface g0/0 on R1.


Now that we’ve seen how OSPF calculates cost and how to check it using show ip ospf interface, let’s look at how we can actually modify the cost when needed.

Sometimes, you may want to control the path OSPF chooses. For example, to prefer one link over another. OSPF gives you three different ways to influence the cost of a path, and each method has its own use case depending on how much control you want.

Let’s break down the three methods and the commands used for each.


Change the Interface Cost Manually

This is the most direct way to influence OSPF path selection. You can manually set the cost on an interface using the ip ospf cost command.

R1(config-if)# ip ospf cost [value]

Example:

R1(config-if)# ip ospf cost 50

This overrides the automatic cost calculation based on bandwidth and sets the OSPF cost to 50 for that interface.

Use this when:

  • You want precise control over OSPF cost.

  • You're dealing with mismatched bandwidths or test environments.


Change the Bandwidth of the Interface

OSPF calculates cost based on interface bandwidth. So, by changing the bandwidth value (without affecting actual speed), you can influence the OSPF cost.

R1(config-if)# bandwidth [kbps]

Example:

R1(config-if)# bandwidth 1000

This sets the bandwidth to 1 Mbps (1000 Kbps), which OSPF uses in its cost formula:

Cost = Reference Bandwidth / Interface Bandwidth

Use this when:

  • You want to simulate slower/faster links.

  • You're in a lab and can’t change actual link speed.

Note: Changing the bandwidth affects other protocols too, like EIGRP and QoS.


Change the Reference Bandwidth

By default, OSPF uses a reference bandwidth of 100 Mbps. This was fine in older networks, but with modern Gigabit and 10-Gigabit links, everything ends up with the same cost (1). To fix this, you can raise the reference bandwidth so faster links have lower costs.

Command (under OSPF config mode):

R1(config-router)# auto-cost reference-bandwidth [Mbps]

Example:

R1(config-router)# auto-cost reference-bandwidth 1000

This sets the reference bandwidth to 1 Gbps, allowing OSPF to differentiate between FastEthernet (100 Mbps), Gigabit (1 Gbps), and higher-speed links.

Use this when:

  • Your network uses high-speed links (1 Gbps or more).

  • You want OSPF to make smarter path decisions based on modern bandwidths.

Important: This should be set consistently across all routers to avoid mismatched cost calculations.


Summary Table:

MethodCommandScopeWhen to Use
Manual Interface Costip ospf cost [value]Per interfacePrecise control over OSPF paths
Adjust Bandwidthbandwidth [kbps]Per interfaceSimulate real/virtual link speeds
Adjust Reference Bandwidthauto-cost reference-bandwidth [Mbps]OSPF processModern networks with fast links

OSPF Neighbors and OSPF States

So far, we’ve talked about OSPF areas, cost, and how to influence path selection but none of that matters if routers don’t form neighbor relationships first. OSPF is a link-state protocol, which means routers must first discover and exchange information with their neighbors before building a complete view of the network.

Let’s take a closer look at how OSPF routers become neighbors and the different states they go through during that process.


What Is an OSPF Neighbor?

An OSPF neighbor is simply another router on a directly connected network that is also running OSPF. Two routers must:

  • Be in the same subnet

  • Be in the same OSPF area

  • Have matching Hello and Dead intervals

  • Not be on passive interfaces

  • Have matching authentication (if used)

  • Have matching MTU (in some cases)

Once all of these conditions are met, the routers try to become neighbors by exchanging Hello packets.


OSPF Neighbor States (The 7-Step Process)

When two OSPF routers are trying to form a neighbor relationship, they don’t just connect instantly. They go through a series of seven states, gradually building trust and syncing their databases.

Let’s go through each one:

Down

  • No Hello packets received yet.

  • The router doesn’t know about any neighbors on the interface.

Init

  • The router received a Hello packet from a neighbor, but it doesn’t see itself in that packet yet.

  • It’s like your neighbor waved at you, but you’re still not sure they saw you.

2-Way

  • The neighbor has now replied and includes your router ID in its Hello.

  • Now both routers officially recognize each other.

  • If the link is broadcast or multi-access (like Ethernet), a DR/BDR election happens here.

  • If it’s a point-to-point link, they move forward without elections.

Routers that are neither DR nor BDR will stop here with each other (they stay at 2-Way).

ExStart

  • The routers are about to exchange databases, but first they need to agree who goes first.

  • OSPF chooses the Master and Slave roles.

    • The router with the higher router ID becomes the Master.

    • The Master controls the sequence numbers and starts the exchange.

  • The Slave waits and responds as needed.

Why this matters: It prevents confusion or duplicate information during LSDB syncing.

Exchange

  • The routers now exchange summary lists of their LSDB using DBD (Database Description) packets.

  • This doesn’t contain full details. Just a summary of what each router has.

  • Each side compares the lists to see what it’s missing.

Loading

  • If a router sees LSAs in the summary that it doesn’t have (or has outdated), it sends LSR (Link-State Request) packets.

  • The neighbor replies with LSU (Link-State Update) packets containing the full info.

Full

  • All LSAs have been exchanged.

  • Both routers now have the same link-state database.

  • The routers are now fully adjacent and can make accurate routing decisions.


show ip ospf neighbor – What It Does

This command shows the list of OSPF neighbors your router has discovered and their current state.

Syntax:

R1# show ip ospf neighbor

Sample Output:

Neighbor ID     Pri   State           Dead Time   Address         Interface
2.2.2.2         1     FULL/DR         00:00:33     10.0.11.2       GigabitEthernet0/0
3.3.3.3         1     FULL/BDR        00:00:39     10.0.12.1       GigabitEthernet0/1

Key Info You’ll See:

  • Neighbor ID – The Router ID of the neighbor.

  • Priority – Used in DR/BDR elections.

  • State – Current OSPF state (like FULL, 2-WAY, EXSTART, etc.).

  • Dead Time – Timer showing how long before the neighbor is declared dead if no Hello is received.

  • Address – The neighbor’s IP address.

  • Interface – The local interface used to reach the neighbor.


How to Activate OSPF Directly on an Interface

In older OSPF setups, you had to use the network command and wildcard masks. But starting in newer versions of Cisco IOS (and IOS-XE), you can activate OSPF directly on an interface. No need for wildcard masks.

This is a simpler and more direct way to enable OSPF per interface.


Example Configuration

Let’s say we want to enable OSPF Process ID 1 on GigabitEthernet0/0 and place it in Area 0.

Step-by-step:

R1(config)# interface GigabitEthernet0/0
R1(config-if)# ip ospf 1 area 0

This command:

  • Enables OSPF process 1 on the interface.

  • Assigns that interface to Area 0.

  • Automatically starts sending Hello packets to discover neighbors.

This method is useful when:

  • You don’t want to bother calculating wildcard masks.

  • You only want to enable OSPF on specific interfaces.

  • You prefer a cleaner and faster config.


OSPF Packet Types

TypeNamePurpose
1HelloUsed to discover and maintain neighbor relationships.
2DBD (Database Description)Summarizes LSAs during the database exchange phase.
3LSR (Link-State Request)Requests specific LSAs that are missing or outdated.
4LSU (Link-State Update)Sends the actual LSAs (full information) in response to LSRs or flooding.
5LSAck (Link-State Acknowledgment)Acknowledges receipt of LSAs to ensure reliable delivery.

These packets work together during the neighbor formation process to ensure all routers have the same link-state database, which OSPF uses to build accurate routing tables.


Common Reasons Why OSPF Neighbors Don’t Reach Full State

If two routers are stuck in Init, 2-Way, or ExStart, there’s usually a mismatch or misconfiguration. Here are the most common things to check:

1. Hello and Dead Interval Mismatch

Both routers must have the same timers. Use:

R1# show ip ospf interface

Check that Hello (default 10s) and Dead (default 40s) match on both ends.

2. Authentication Mismatch

If OSPF authentication is enabled on one router but not the other (or if passwords don’t match), neighbors won’t form.

Verify with:

R1# show ip ospf interface [interface-name]

3. MTU Mismatch

If routers have different MTU sizes, they might get stuck in ExStart. You’ll often see this if one side can't agree on DBD packet sizes.

Fix it by matching the MTU or disabling MTU checks:

R1(config-if)# ip ospf mtu-ignore

4. Passive Interfaces

If an interface is marked as passive, it won’t send or receive OSPF Hello packets so no neighbor will form.

You can disable passive mode like this:

R1(config-router)# no passive-interface GigabitEthernet0/0

5. Area or Subnet Mismatch

Both routers must be in the same area and IP subnet to become neighbors.

Use:

R1# show ip ospf neighbor
R1# show ip ospf interface

to double-check.


Where We’re Heading Next

Now that you know how OSPF routers discover each other, go through states, and what can go wrong, it’s a good time to explore what happens on broadcast networks where multiple routers are connected, like on a switch or shared segment.

That’s where Designated Routers (DR) and Backup Designated Routers (BDR) come in.


What Are DR and BDR in OSPF?

In OSPF, when multiple routers share the same network segment (like being connected to the same switch), it can get messy if all of them try to form full neighbor relationships with everyone else.

To make things more efficient, OSPF elects a DR and a BDR. These two routers act as the central points for communication on that segment.

  • DR (Designated Router): The main router responsible for collecting and distributing LSAs on the segment.

  • BDR (Backup Designated Router): Takes over if the DR goes down.

  • DROTHERs: All other routers on the segment that are neither DR nor BDR.


Why OSPF Elects a DR and BDR

Without a DR/BDR system, 5 routers on one network would each have to form full adjacencies with the other 4. That’s a lot of unnecessary LSA traffic.

With DR/BDR:

  • Each router only forms a full adjacency with the DR and BDR.

  • This reduces the number of neighbor relationships and keeps LSA flooding under control.


How Are DR and BDR Elected?

The election happens automatically when OSPF routers come up on a broadcast or non-point-to-point link.

Rules:

  1. The router with the highest OSPF priority wins.

  2. If there’s a tie, the one with the highest router ID wins.

  3. The BDR is elected first, then the DR.

If a DR/BDR is already elected, new routers won’t trigger a re-election. They’ll just join as DROTHERs unless the DR or BDR goes down.


Setting OSPF Priority

You can influence the election by changing the OSPF priority on the interface:

R1(config-if)# ip ospf priority 100
  • Default priority is 1.

  • Set it to 0 to make sure a router never becomes DR or BDR.


Verifying DR/BDR Roles

Use this command:

R1# show ip ospf neighbor

You’ll see which router is DR, BDR, or DROTHER in the output.


Example Scenario

Let’s say R1, R2, and R3 are all connected to the same switch:

  • R1 has priority 1, Router ID 1.1.1.1

  • R2 has priority 100, Router ID 2.2.2.2

  • R3 has priority 50, Router ID 3.3.3.3

🟢 R2 becomes the DR (highest priority)
🟡 R3 becomes the BDR (next highest)
⚪ R1 becomes a DROTHER


What Are LSAs in OSPF?

Once OSPF routers become neighbors and reach the Full state, they start exchanging information about the network. This information is shared in the form of LSAs, or Link-State Advertisements.

Think of LSAs as little "network update reports" that each router sends out to describe:

  • What networks it knows

  • What routers it's connected to

  • How everything is linked together

These LSAs are stored in the LSDB (Link-State Database) and used to build the OSPF routing table using the SPF (Shortest Path First) algorithm.


OSPF LSA Types – The Ones You Actually Need to Know

We’ve talked about how OSPF routers form neighbor relationships and exchange information. Now, let’s look at what they actually exchange. That’s where LSAs, or Link-State Advertisements, come in.

All the data inside the OSPF LSDB (Link-State Database) is made up of LSAs. These LSAs describe the routers, links, networks, and routes in the OSPF domain.

OSPF defines 11 types of LSAs, but for the CCNA level, you only really need to focus on the first three that appear most in basic OSPF deployments:

Type 1 – Router LSA

  • Generated by every router within an area.

  • Describes that router’s directly connected interfaces and neighbors.

  • Only stays within the area it originated.

  • Helps build the full topology of that area.

You’ll always see these in any functioning OSPF setup.

Type 2 – Network LSA

  • Generated by the Designated Router (DR) on broadcast or multi-access networks (like Ethernet).

  • Lists all routers connected to that segment.

  • Also stays within the same area.

You’ll only see this if a DR is elected on the interface.

Type 5 – External LSA

  • Generated by ASBRs (Autonomous System Boundary Routers).

  • Advertises routes that are external to OSPF (e.g., static routes or routes from another routing protocol).

  • Flooded throughout the entire OSPF domain except stub areas.

When you use default-information originate or redistribute static/default routes into OSPF, this is what gets created.


Viewing LSAs – show ip ospf database

You can see all LSAs known to the router by using:

R1# show ip ospf database

This command breaks down the LSDB into sections, showing you:

  • Router LSAs (Type 1)

  • Network LSAs (Type 2)

  • External LSAs (Type 5)

Sample output:

OSPF Router with ID (1.1.1.1) (Process ID 1)

                Router Link States (Area 0)

Link ID         ADV Router      Age     Seq#       Checksum Link count
1.1.1.1         1.1.1.1         800     0x8000003a 0x0092   3
...

                Net Link States (Area 0)

Link ID         ADV Router      Age     Seq#       Checksum
10.0.11.2       2.2.2.2         766     0x8000001d 0x0049

                Type-5 AS External Link States

Link ID         ADV Router      Age     Seq#       Checksum Tag
0.0.0.0         1.1.1.1         340     0x80000001 0x0078   0

This command is useful for verifying which routers are advertising what, and it helps in troubleshooting or just seeing how OSPF is piecing together your network.


Let’s Talk About Loopback Interfaces in OSPF

Now that we've covered how to activate OSPF on physical interfaces, let's take a quick detour into something just as important; loopback interfaces.

Loopbacks aren’t tied to physical ports. They’re virtual interfaces that are always up as long as the router is running. In OSPF, loopbacks serve a special role, especially when it comes to Router IDs and network stability.


What Is a Loopback Interface?

A loopback interface is a virtual interface on a router. Unlike physical interfaces, it doesn't go down unless you manually shut it. Because of that, it's reliable and often used for:

  • Router ID selection in OSPF

  • Stable reachability (useful in routing protocols and network monitoring)


Why Loopback Matters in OSPF

OSPF needs a Router ID (RID); a unique 32-bit identifier (looks like an IP address) used to identify the router in OSPF processes.

OSPF selects the Router ID in this order:

  1. Manually configured Router ID (router-id command)

  2. Highest IP address on any loopback interface

  3. Highest IP address on any active physical interface

So, if you don’t manually set a Router ID, it’s best practice to create a loopback interface with a high, unique IP address. This ensures consistency even if physical interfaces go down.


Loopback Interface Configuration Example

Let’s say you want to configure a loopback interface with IP 1.1.1.1/32 and use it in OSPF area 0.

Step 1: Create the loopback interface

R1(config)# interface Loopback0
R1(config-if)# ip address 1.1.1.1 255.255.255.255

Tip: Using a /32 mask (255.255.255.255) treats the loopback as a single-host route. That’s a common practice in OSPF.

Step 2: Activate OSPF on the loopback

R1(config)# router ospf 1
R1(config-router)# network 1.1.1.1 0.0.0.0 area 0

Or if you're using interface-based OSPF configuration:

R1(config)# interface Loopback0
R1(config-if)# ip ospf 1 area 0

Verifying the Router ID

After configuring the loopback and enabling OSPF, check the router ID with:

R1# show ip ospf

You should see:

Routing Process "ospf 1" with ID 1.1.1.1

If OSPF was already running before you added the loopback, you may need to reset the OSPF process for the Router ID to update:

R1# clear ip ospf process

Warning: This will temporarily bring down all OSPF adjacencies so use with caution on live networks.


OSPF Network Types – What Are They and Why Do They Matter?

Now that we’ve gone through loopback interfaces and how OSPF interacts with them, it’s time to understand how OSPF behaves on different types of networks. Not all links are the same. Some are direct point-to-point links between two routers, while others are shared by multiple devices.

OSPF adjusts its behavior based on the network type. This affects how routers discover neighbors, how often Hello packets are sent, and whether a DR (Designated Router) and BDR (Backup Designated Router) are needed.

There are three main OSPF network types you’ll commonly encounter. Let’s go through each one.

1. Broadcast Network

Example: Ethernet networks where multiple routers are connected to the same switch.

Behavior:

  • OSPF automatically discovers neighbors using multicast Hello packets.

  • A DR and BDR are elected to manage LSA flooding efficiently.

  • Each router on the network only forms a full adjacency with the DR and BDR.

  • All other routers remain in a 2-Way state with each other.

Timers:

  • Hello Interval: 10 seconds

  • Dead Interval: 40 seconds

Use Case: Suitable for LANs where multiple routers are on the same segment. It scales well and reduces overhead.

2. Point-to-Point Network

Example: Direct connection between two routers using a serial link or a dedicated Ethernet cable.

Behavior:

  • No DR/BDR election is needed.

  • The two routers form a direct full adjacency.

  • OSPF immediately assumes there’s only one neighbor on the link.

Timers:

  • Hello Interval: 10 seconds

  • Dead Interval: 40 seconds

Use Case: Simple and fast convergence. Best used when only two routers are connected.

3. Non-Broadcast Multi-Access (NBMA) Network

Example: Older WAN technologies like Frame Relay, ATM, or MPLS in certain configurations.

Behavior:

  • No automatic neighbor discovery. You must manually configure neighbors.

  • DR and BDR are still elected.

  • Hello packets are unicast rather than multicast.

Timers:

  • Hello Interval: 30 seconds

  • Dead Interval: 120 seconds

Use Case: Used in networks where multicast is not supported. Requires more manual setup.

Summary Table

Network TypeExampleAuto Neighbor DiscoveryDR/BDR ElectionHello/Dead Interval
BroadcastEthernet, LANYesYes10 / 40 seconds
Point-to-PointSerial, Direct LinkYesNo10 / 40 seconds
NBMAFrame Relay, ATMNo (manual config)Yes30 / 120 seconds

Understanding Serial Interfaces in OSPF and Lab Setups

In a lot of OSPF lab scenarios, especially when using platforms like Packet Tracer or GNS3, you’ll often connect routers using serial links. These are commonly used to simulate WAN connections.

Unlike Ethernet interfaces, serial interfaces require you to be aware of DCE and DTE roles, and sometimes you’ll need to manually set the clock rate to make the connection work.

If you’ve ever set up a serial link and noticed that nothing's happening, it’s usually because this part was missed.


What Are DCE and DTE?

When two routers are connected by a serial cable, one side acts as the DCE (Data Communications Equipment) and the other as the DTE (Data Terminal Equipment).

  • DCE: This side provides the clocking signal that controls the data transmission rate.

  • DTE: This side receives the clocking.

In real-world networks, the DCE device is usually something like a modem or service provider equipment. But in lab setups, when two routers are directly connected via serial, one router has to simulate the DCE role.


How to Know Which Side Is DCE?

You can check the cable type on each interface with this command:

R1# show controllers serial 0/0/0

If it says DCE, that router is responsible for providing the clock rate.


Configuring Clock Rate on the DCE Side

If your router interface is the DCE, you’ll need to manually configure the clock rate. Otherwise, the link won’t come up correctly.

Here’s how to do it:

R1(config)# interface serial 0/0/0
R1(config-if)# clock rate 64000
  • 64000 is a typical value in lab setups, but you can use others like 128000, 256000, etc.

  • Only set this on the DCE side.

Once set, the DTE side will follow the timing from the DCE side, and the link should come up.


Summary

TermMeaningRole
DCEData Communications EquipmentProvides clocking (requires clock rate)
DTEData Terminal EquipmentReceives clocking

HDLC and PPP – Serial Encapsulation Protocols

When two routers are connected through a serial interface, they need a data-link protocol to communicate. This protocol defines how data is framed and sent over the link. In Cisco devices, the default protocol used is HDLC, but you can also manually set it to PPP if needed.

  • This is the default encapsulation on Cisco serial interfaces.

  • It’s simple and works well for point-to-point links.

  • Cisco uses a proprietary version of HDLC, which means it only works between Cisco devices.

PPP (Point-to-Point Protocol)

  • A more flexible and open standard compared to HDLC.

  • Supports features like authentication (PAP, CHAP), compression, and error detection.

  • Works between different vendor devices, not just Cisco.

You can switch from HDLC to PPP with this command:

R1(config-if)# encapsulation ppp

DCE and DTE – What You Need to Know

In a lab setup with two routers connected via serial cables, one router acts as the DCE (Data Communications Equipment) and the other as the DTE (Data Terminal Equipment).

  • DCE provides the clocking signal that controls the speed of the link.

  • DTE receives the clocking from the DCE side.

In real-world networks, this timing is often handled by the service provider. But in lab environments, you’ll need to configure it manually on the router acting as the DCE.

To check which side is DCE or DTE, use:

R1# show controllers serial 0/0/0

Look for the word DCE in the output. If it's there, that router must provide the clock rate.


Setting the Clock Rate

If your router is the DCE, you must configure the clock rate on that interface using:

R1(config-if)# clock rate 64000

You can use other values like 128000, 256000, or more just make sure the DCE side sets it, and the DTE side will follow.


Configuring OSPF Network Types with ip ospf network

By default, OSPF automatically determines the network type based on the interface type. For example, Ethernet interfaces are treated as broadcast, while serial interfaces are usually treated as point-to-point or non-broadcast, depending on the platform.

But sometimes, you’ll want to manually change the network type to control how OSPF behaves especially if you're working in a lab or in a situation where the defaults don’t match your design.

To change the OSPF network type on an interface, use this command in interface configuration mode:

R1(config-if)# ip ospf network [type]

Available options include:

  • broadcast

  • point-to-point

  • non-broadcast

  • point-to-multipoint

In most basic setups, you'll only be working with broadcast and point-to-point, so let's focus on those.


Broadcast vs. Point-to-Point Network Types in OSPF

FeatureBroadcastPoint-to-Point
Common Interface TypeEthernetSerial, direct link
Neighbor DiscoveryAutomatic (using multicast)Automatic
DR/BDR ElectionYesNo
LSAsShared through DR/BDRShared directly between neighbors
Hello Interval (default)10 seconds10 seconds
Dead Interval (default)40 seconds40 seconds
Number of NeighborsOne or moreOne
Use CaseLAN segmentsSimple direct router-to-router links

Example: Changing Network Type on a Serial Interface

Let’s say a serial interface is defaulting to non-broadcast, but you want to treat it as a clean point-to-point connection.

R1(config)# interface serial 0/0/0
R1(config-if)# ip ospf network point-to-point

This tells OSPF to:

  • Skip DR/BDR elections

  • Form a full adjacency directly

  • Assume only one neighbor on the link


OSPF Neighbor Requirements – What Needs to Match?

For two routers to become OSPF neighbors and form an adjacency, several key settings must match. If even one of these is misconfigured, OSPF won't form the relationship, and you'll be stuck troubleshooting why they're stuck in the 2-Way or Init state.

Here are the main requirements that must match between neighbors:

  1. Area number must match
    Both interfaces must belong to the same OSPF area.

  2. Interfaces must be in the same subnet
    OSPF won’t form a neighbor relationship if the IP addresses are in different subnets.

  3. OSPF process must not be shut down
    Make sure the OSPF routing process is running and not in a shutdown state.

  4. Router IDs must be unique
    Each OSPF router in the domain must have a unique Router ID. Duplicates will cause adjacency problems.

  5. Hello and Dead timers must match
    If these timers don’t match on both sides of the link, the neighbor relationship will fail.

  6. Authentication settings must match
    If OSPF authentication is enabled, the authentication type and passwords must be the same on both routers.

  7. IP MTU settings must match
    If the MTU differs and ip ospf mtu-ignore isn’t configured, the routers might get stuck in the EXSTART state.

  8. OSPF network types must match
    Network types determine OSPF behavior (like DR/BDR elections), and mismatches can lead to incomplete adjacency.

These are the most common settings to double-check when neighbor relationships aren't forming. If you run into issues, starting here usually saves a lot of time.


Wrapping Up

That’s it for OSPF! We covered a lot. From what OSPF is, how it builds neighbor relationships, the role of LSAs, the importance of areas, how cost is calculated, and how to configure it step by step. We also touched on more detailed topics like network types, loopback interfaces, neighbor requirements, and common LSA types you’ll actually encounter in a CCNA-level setup.

If you're just starting out with networking, OSPF can feel like a lot at first but once you break it down and try it in a lab, it starts to make sense. The best way to really understand how OSPF works is to get hands-on: build small topologies, run the commands, watch how routers form relationships, and check the routing tables.

I'm not a professional instructor. Just someone learning and sharing along the way. I'm still learning too.

Thanks for reading, and I hope this helped make OSPF a little easier to understand. Stay curious, keep practicing, and let’s keep learning networking.

0
Subscribe to my newsletter

Read articles from Pits directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Pits
Pits